mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
3158c15111
# Conflicts: # app/controllers/api/functions.php # app/controllers/api/project.php # app/controllers/api/proxy.php # app/controllers/api/storage.php # app/controllers/api/vcs.php # app/controllers/general.php # app/controllers/shared/api.php # app/init/database/filters.php # composer.json # composer.lock # src/Appwrite/Migration/Migration.php # src/Appwrite/Migration/Version/V15.php # src/Appwrite/Migration/Version/V16.php # src/Appwrite/Migration/Version/V17.php # src/Appwrite/Migration/Version/V18.php # src/Appwrite/Migration/Version/V19.php # src/Appwrite/Migration/Version/V20.php # src/Appwrite/Migration/Version/V21.php # src/Appwrite/Platform/Tasks/Migrate.php # src/Appwrite/Platform/Workers/Builds.php # src/Appwrite/Platform/Workers/Deletes.php # src/Appwrite/Platform/Workers/Functions.php # src/Appwrite/Platform/Workers/StatsResources.php # src/Appwrite/Platform/Workers/StatsUsage.php
77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Appwrite\Platform\Modules\Projects\Http\DevKeys;
|
|
|
|
use Appwrite\Extend\Exception;
|
|
use Appwrite\SDK\AuthType;
|
|
use Appwrite\SDK\ContentType;
|
|
use Appwrite\SDK\Method;
|
|
use Appwrite\SDK\Response as SDKResponse;
|
|
use Appwrite\Utopia\Response;
|
|
use Utopia\Database\Database;
|
|
use Utopia\Database\Validator\UID;
|
|
use Utopia\Platform\Action;
|
|
use Utopia\Platform\Scope\HTTP;
|
|
|
|
class Delete extends Action
|
|
{
|
|
use HTTP;
|
|
public static function getName()
|
|
{
|
|
return 'deleteDevKey';
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
$this
|
|
->setHttpMethod(Action::HTTP_REQUEST_METHOD_DELETE)
|
|
->setHttpPath('/v1/projects/:projectId/dev-keys/:keyId')
|
|
->desc('Delete dev key')
|
|
->groups(['api', 'projects'])
|
|
->label('scope', 'projects.write')
|
|
->label('sdk', new Method(
|
|
namespace: 'projects',
|
|
group: 'devKeys',
|
|
name: 'deleteDevKey',
|
|
description: <<<EOT
|
|
Delete a project\'s dev key by its unique ID. Once deleted, the key will no longer allow bypassing of rate limits and better logging of errors.
|
|
EOT,
|
|
auth: [AuthType::ADMIN],
|
|
responses: [
|
|
new SDKResponse(
|
|
code: Response::STATUS_CODE_NOCONTENT,
|
|
model: Response::MODEL_NONE
|
|
)
|
|
],
|
|
contentType: ContentType::NONE
|
|
))
|
|
->param('projectId', '', new UID(), 'Project unique ID.')
|
|
->param('keyId', '', new UID(), 'Key unique ID.')
|
|
->inject('response')
|
|
->inject('dbForPlatform')
|
|
->callback([$this, 'action']);
|
|
}
|
|
|
|
public function action(string $projectId, string $keyId, Response $response, Database $dbForPlatform)
|
|
{
|
|
|
|
$project = $dbForPlatform->getDocument('projects', $projectId);
|
|
|
|
if ($project->isEmpty()) {
|
|
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
|
}
|
|
|
|
$key = $dbForPlatform->getDocument('devKeys', $keyId);
|
|
|
|
if ($key === false || $key->isEmpty() || $key->getAttribute('projectInternalId') !== $project->getSequence()) {
|
|
throw new Exception(Exception::KEY_NOT_FOUND);
|
|
}
|
|
|
|
$dbForPlatform->deleteDocument('devKeys', $key->getId());
|
|
|
|
$dbForPlatform->purgeCachedDocument('projects', $project->getId());
|
|
|
|
$response->noContent();
|
|
}
|
|
}
|