Merge pull request #5530 from appwrite/fix-certificates
feat: add checks for domain
This commit is contained in:
commit
56efd5e11a
3 changed files with 16 additions and 3 deletions
|
@ -541,9 +541,14 @@ return [
|
||||||
],
|
],
|
||||||
Exception::DOMAIN_ALREADY_EXISTS => [
|
Exception::DOMAIN_ALREADY_EXISTS => [
|
||||||
'name' => Exception::DOMAIN_ALREADY_EXISTS,
|
'name' => Exception::DOMAIN_ALREADY_EXISTS,
|
||||||
'description' => 'A Domain with the requested ID already exists.',
|
'description' => 'The requested domain is currently in use by a project.',
|
||||||
'code' => 409,
|
'code' => 409,
|
||||||
],
|
],
|
||||||
|
Exception::DOMAIN_FORBIDDEN => [
|
||||||
|
'name' => Exception::DOMAIN_FORBIDDEN,
|
||||||
|
'description' => 'The requested domain cannot be used as a custom domain.',
|
||||||
|
'code' => 403,
|
||||||
|
],
|
||||||
Exception::VARIABLE_NOT_FOUND => [
|
Exception::VARIABLE_NOT_FOUND => [
|
||||||
'name' => Exception::VARIABLE_NOT_FOUND,
|
'name' => Exception::VARIABLE_NOT_FOUND,
|
||||||
'description' => 'Variable with the requested ID could not be found.',
|
'description' => 'Variable with the requested ID could not be found.',
|
||||||
|
|
|
@ -1191,9 +1191,12 @@ App::post('/v1/projects/:projectId/domains')
|
||||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($domain === App::getEnv('_APP_DOMAIN', '') || $domain === App::getEnv('_APP_DOMAIN_TARGET', '')) {
|
||||||
|
throw new Exception(Exception::DOMAIN_FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
$document = $dbForConsole->findOne('domains', [
|
$document = $dbForConsole->findOne('domains', [
|
||||||
Query::equal('domain', [$domain]),
|
Query::equal('domain', [$domain])
|
||||||
Query::equal('projectInternalId', [$project->getInternalId()]),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($document && !$document->isEmpty()) {
|
if ($document && !$document->isEmpty()) {
|
||||||
|
@ -1391,6 +1394,10 @@ App::delete('/v1/projects/:projectId/domains/:domainId')
|
||||||
throw new Exception(Exception::DOMAIN_NOT_FOUND);
|
throw new Exception(Exception::DOMAIN_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($domain->getAttribute('domain') === App::getEnv('_APP_DOMAIN', '') || $domain->getAttribute('domain') === App::getEnv('_APP_DOMAIN_TARGET', '')) {
|
||||||
|
throw new Exception(Exception::DOMAIN_FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
$dbForConsole->deleteDocument('domains', $domain->getId());
|
$dbForConsole->deleteDocument('domains', $domain->getId());
|
||||||
|
|
||||||
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
||||||
|
|
|
@ -177,6 +177,7 @@ class Exception extends \Exception
|
||||||
/** Domain */
|
/** Domain */
|
||||||
public const DOMAIN_NOT_FOUND = 'domain_not_found';
|
public const DOMAIN_NOT_FOUND = 'domain_not_found';
|
||||||
public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists';
|
public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists';
|
||||||
|
public const DOMAIN_FORBIDDEN = 'domain_forbidden';
|
||||||
public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed';
|
public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed';
|
||||||
|
|
||||||
protected $type = '';
|
protected $type = '';
|
||||||
|
|
Loading…
Reference in a new issue