mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix:remove redundant checks
This commit is contained in:
+1
-1
@@ -1033,7 +1033,7 @@ services:
|
||||
volumes:
|
||||
- appwrite-mariadb:/var/lib/mysql:rw
|
||||
ports:
|
||||
- "3306:3306"
|
||||
- "3307:3306"
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=${_APP_DB_ROOT_PASS}
|
||||
- MYSQL_DATABASE=${_APP_DB_SCHEMA}
|
||||
|
||||
@@ -71,16 +71,11 @@ class Create extends Action
|
||||
|
||||
public function action(string $domain, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform)
|
||||
{
|
||||
// 1. Domain format validations
|
||||
try {
|
||||
$domain = new Domain($domain);
|
||||
} catch (\Throwable $e) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
|
||||
}
|
||||
|
||||
// 2. Denied domains check
|
||||
$domainString = strtolower($domain);
|
||||
|
||||
|
||||
$deniedDomains = [
|
||||
'localhost',
|
||||
APP_HOSTNAME_INTERNAL
|
||||
];
|
||||
|
||||
@@ -106,15 +101,15 @@ class Create extends Action
|
||||
$deniedDomains[] = $denyListDomain;
|
||||
}
|
||||
|
||||
if (\in_array($domain->get(), $deniedDomains)) {
|
||||
if (\in_array($domainString, $deniedDomains)) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.');
|
||||
}
|
||||
|
||||
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique();
|
||||
|
||||
$status = 'created';
|
||||
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
|
||||
if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) {
|
||||
$status = 'verified';
|
||||
}
|
||||
if ($status === 'created') {
|
||||
@@ -135,15 +130,15 @@ class Create extends Action
|
||||
}
|
||||
|
||||
$validator = new AnyOf($validators, AnyOf::TYPE_STRING);
|
||||
if ($validator->isValid($domain->get())) {
|
||||
if ($validator->isValid($domainString)) {
|
||||
$status = 'verifying';
|
||||
}
|
||||
}
|
||||
|
||||
$owner = '';
|
||||
if (
|
||||
($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain))
|
||||
($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain))
|
||||
) {
|
||||
$owner = 'Appwrite';
|
||||
}
|
||||
@@ -152,12 +147,12 @@ class Create extends Action
|
||||
'$id' => $ruleId,
|
||||
'projectId' => $project->getId(),
|
||||
'projectInternalId' => $project->getSequence(),
|
||||
'domain' => $domain->get(),
|
||||
'domain' => $domainString,
|
||||
'status' => $status,
|
||||
'type' => 'api',
|
||||
'trigger' => 'manual',
|
||||
'certificateId' => '',
|
||||
'search' => implode(' ', [$ruleId, $domain->get()]),
|
||||
'search' => implode(' ', [$ruleId, $domainString]),
|
||||
'owner' => $owner,
|
||||
'region' => $project->getAttribute('region')
|
||||
]);
|
||||
|
||||
@@ -76,16 +76,10 @@ class Create extends Action
|
||||
|
||||
public function action(string $domain, string $functionId, string $branch, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject)
|
||||
{
|
||||
// 1. Domain format validations
|
||||
try {
|
||||
$domain = new Domain($domain);
|
||||
} catch (\Throwable $e) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
|
||||
}
|
||||
|
||||
// 2. Denied domains check
|
||||
$domainString = strtolower($domain);
|
||||
|
||||
$deniedDomains = [
|
||||
'localhost',
|
||||
APP_HOSTNAME_INTERNAL
|
||||
];
|
||||
|
||||
@@ -111,7 +105,7 @@ class Create extends Action
|
||||
$deniedDomains[] = $denyListDomain;
|
||||
}
|
||||
|
||||
if (\in_array($domain->get(), $deniedDomains)) {
|
||||
if (\in_array($domainString, $deniedDomains)) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.');
|
||||
}
|
||||
|
||||
@@ -123,10 +117,10 @@ class Create extends Action
|
||||
$deployment = $dbForProject->getDocument('deployments', $function->getAttribute('deploymentId', ''));
|
||||
|
||||
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique();
|
||||
|
||||
$status = 'created';
|
||||
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
|
||||
if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) {
|
||||
$status = 'verified';
|
||||
}
|
||||
if ($status === 'created') {
|
||||
@@ -147,15 +141,15 @@ class Create extends Action
|
||||
}
|
||||
|
||||
$validator = new AnyOf($validators, AnyOf::TYPE_STRING);
|
||||
if ($validator->isValid($domain->get())) {
|
||||
if ($validator->isValid($domainString)) {
|
||||
$status = 'verifying';
|
||||
}
|
||||
}
|
||||
|
||||
$owner = '';
|
||||
if (
|
||||
($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain))
|
||||
($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain))
|
||||
) {
|
||||
$owner = 'Appwrite';
|
||||
}
|
||||
@@ -164,7 +158,7 @@ class Create extends Action
|
||||
'$id' => $ruleId,
|
||||
'projectId' => $project->getId(),
|
||||
'projectInternalId' => $project->getSequence(),
|
||||
'domain' => $domain->get(),
|
||||
'domain' => $domainString,
|
||||
'status' => $status,
|
||||
'type' => 'deployment',
|
||||
'trigger' => 'manual',
|
||||
@@ -175,7 +169,7 @@ class Create extends Action
|
||||
'deploymentResourceInternalId' => $function->getSequence(),
|
||||
'deploymentVcsProviderBranch' => $branch,
|
||||
'certificateId' => '',
|
||||
'search' => implode(' ', [$ruleId, $domain->get(), $branch]),
|
||||
'search' => implode(' ', [$ruleId, $domainString, $branch]),
|
||||
'owner' => $owner,
|
||||
'region' => $project->getAttribute('region')
|
||||
]);
|
||||
|
||||
@@ -79,16 +79,11 @@ class Create extends Action
|
||||
|
||||
public function action(string $domain, string $url, int $statusCode, string $resourceId, string $resourceType, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject)
|
||||
{
|
||||
// 1. Domain format validations
|
||||
try {
|
||||
$domain = new Domain($domain);
|
||||
} catch (\Throwable $e) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
|
||||
}
|
||||
// Domain is already validated by AppwriteDomain validator
|
||||
$domainString = strtolower($domain);
|
||||
|
||||
|
||||
// 2. Denied domains check
|
||||
$deniedDomains = [
|
||||
'localhost',
|
||||
APP_HOSTNAME_INTERNAL
|
||||
];
|
||||
|
||||
@@ -114,7 +109,7 @@ class Create extends Action
|
||||
$deniedDomains[] = $denyListDomain;
|
||||
}
|
||||
|
||||
if (\in_array($domain->get(), $deniedDomains)) {
|
||||
if (\in_array($domainString, $deniedDomains)) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.');
|
||||
}
|
||||
|
||||
@@ -128,10 +123,10 @@ class Create extends Action
|
||||
}
|
||||
|
||||
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique();
|
||||
|
||||
$status = 'created';
|
||||
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
|
||||
if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) {
|
||||
$status = 'verified';
|
||||
}
|
||||
if ($status === 'created') {
|
||||
@@ -152,15 +147,15 @@ class Create extends Action
|
||||
}
|
||||
|
||||
$validator = new AnyOf($validators, AnyOf::TYPE_STRING);
|
||||
if ($validator->isValid($domain->get())) {
|
||||
if ($validator->isValid($domainString)) {
|
||||
$status = 'verifying';
|
||||
}
|
||||
}
|
||||
|
||||
$owner = '';
|
||||
if (
|
||||
($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain))
|
||||
($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain))
|
||||
) {
|
||||
$owner = 'Appwrite';
|
||||
}
|
||||
@@ -169,7 +164,7 @@ class Create extends Action
|
||||
'$id' => $ruleId,
|
||||
'projectId' => $project->getId(),
|
||||
'projectInternalId' => $project->getSequence(),
|
||||
'domain' => $domain->get(),
|
||||
'domain' => $domainString,
|
||||
'status' => $status,
|
||||
'type' => 'redirect',
|
||||
'trigger' => 'manual',
|
||||
@@ -179,7 +174,7 @@ class Create extends Action
|
||||
'deploymentResourceId' => $resource->getId(),
|
||||
'deploymentResourceInternalId' => $resource->getSequence(),
|
||||
'certificateId' => '',
|
||||
'search' => implode(' ', [$ruleId, $domain->get()]),
|
||||
'search' => implode(' ', [$ruleId, $domainString]),
|
||||
'owner' => $owner,
|
||||
'region' => $project->getAttribute('region')
|
||||
]);
|
||||
|
||||
@@ -76,16 +76,11 @@ class Create extends Action
|
||||
|
||||
public function action(string $domain, string $siteId, string $branch, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject)
|
||||
{
|
||||
// 1. Domain format validations
|
||||
try {
|
||||
$domain = new Domain($domain);
|
||||
} catch (\Throwable $e) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
|
||||
}
|
||||
|
||||
// 2. Denied domains check
|
||||
$domainString = strtolower($domain);
|
||||
|
||||
|
||||
$deniedDomains = [
|
||||
'localhost',
|
||||
APP_HOSTNAME_INTERNAL
|
||||
];
|
||||
|
||||
@@ -111,7 +106,7 @@ class Create extends Action
|
||||
$deniedDomains[] = $denyListDomain;
|
||||
}
|
||||
|
||||
if (\in_array($domain->get(), $deniedDomains)) {
|
||||
if (\in_array($domainString, $deniedDomains)) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.');
|
||||
}
|
||||
|
||||
@@ -123,10 +118,10 @@ class Create extends Action
|
||||
$deployment = $dbForProject->getDocument('deployments', $site->getAttribute('deploymentId', ''));
|
||||
|
||||
// TODO: @christyjacob remove once we migrate the rules in 1.7.x
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique();
|
||||
$ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique();
|
||||
|
||||
$status = 'created';
|
||||
if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) {
|
||||
if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) {
|
||||
$status = 'verified';
|
||||
}
|
||||
if ($status === 'created') {
|
||||
@@ -147,15 +142,15 @@ class Create extends Action
|
||||
}
|
||||
|
||||
$validator = new AnyOf($validators, AnyOf::TYPE_STRING);
|
||||
if ($validator->isValid($domain->get())) {
|
||||
if ($validator->isValid($domainString)) {
|
||||
$status = 'verifying';
|
||||
}
|
||||
}
|
||||
|
||||
$owner = '';
|
||||
if (
|
||||
($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain))
|
||||
($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) ||
|
||||
($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain))
|
||||
) {
|
||||
$owner = 'Appwrite';
|
||||
}
|
||||
@@ -164,7 +159,7 @@ class Create extends Action
|
||||
'$id' => $ruleId,
|
||||
'projectId' => $project->getId(),
|
||||
'projectInternalId' => $project->getSequence(),
|
||||
'domain' => $domain->get(),
|
||||
'domain' => $domainString,
|
||||
'status' => $status,
|
||||
'type' => 'deployment',
|
||||
'trigger' => 'manual',
|
||||
@@ -175,7 +170,7 @@ class Create extends Action
|
||||
'deploymentResourceInternalId' => $site->getSequence(),
|
||||
'deploymentVcsProviderBranch' => $branch,
|
||||
'certificateId' => '',
|
||||
'search' => implode(' ', [$ruleId, $domain->get(), $branch]),
|
||||
'search' => implode(' ', [$ruleId, $domainString, $branch]),
|
||||
'owner' => $owner,
|
||||
'region' => $project->getAttribute('region')
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user