1
0
Fork 0
mirror of synced 2024-05-17 03:02:35 +12:00

Merge pull request #881 from TorstenDittmann/feat-delete-certificates

Delete certificate files with worker
This commit is contained in:
Eldad A. Fux 2021-02-08 14:33:18 +02:00 committed by GitHub
commit 133235d4a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 8 deletions

View file

@ -477,15 +477,22 @@ App::delete('/v1/projects/:projectId')
;
foreach (['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms)
$list = $project->getAttribute('webhooks', []);
foreach ($list as $document) { /* @var $document Document */
if (!$consoleDB->deleteDocument($projectId)) {
$list = $project->getAttribute($key, []);
foreach ($list as $document) {
/** @var Document $document */
if ($consoleDB->deleteDocument($document->getId())) {
if ($document->getCollection() == Database::SYSTEM_COLLECTION_DOMAINS) {
$deletes
->setParam('type', DELETE_TYPE_CERTIFICATES)
->setParam('document', $document)
;
}
} else {
throw new Exception('Failed to remove project document ('.$key.')] from DB', 500);
}
}
}
if (!$consoleDB->deleteDocument($project->getAttribute('teamId', null))) {
throw new Exception('Failed to remove project team from DB', 500);
}
@ -1566,7 +1573,8 @@ App::delete('/v1/projects/:projectId/domains/:domainId')
->param('domainId', null, new UID(), 'Domain unique ID.')
->inject('response')
->inject('consoleDB')
->action(function ($projectId, $domainId, $response, $consoleDB) {
->inject('deletes')
->action(function ($projectId, $domainId, $response, $consoleDB, $deletes) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
@ -1582,7 +1590,12 @@ App::delete('/v1/projects/:projectId/domains/:domainId')
throw new Exception('Domain not found', 404);
}
if (!$consoleDB->deleteDocument($domain->getId())) {
if ($consoleDB->deleteDocument($domain->getId())) {
$deletes
->setParam('type', DELETE_TYPE_CERTIFICATES)
->setParam('document', $domain)
;
} else {
throw new Exception('Failed to remove domains from DB', 500);
}

View file

@ -60,6 +60,7 @@ const DELETE_TYPE_DOCUMENT = 'document';
const DELETE_TYPE_EXECUTIONS = 'executions';
const DELETE_TYPE_AUDIT = 'audit';
const DELETE_TYPE_ABUSE = 'abuse';
const DELETE_TYPE_CERTIFICATES = 'certificates';
$register = new Registry();

View file

@ -179,6 +179,7 @@ services:
volumes:
- appwrite-uploads:/storage/uploads:rw
- appwrite-cache:/storage/cache:rw
- appwrite-certificates:/storage/certificates:rw
environment:
- _APP_ENV
- _APP_REDIS_HOST
@ -207,6 +208,7 @@ services:
- _APP_SYSTEM_SECURITY_EMAIL_ADDRESS
- _APP_REDIS_HOST
- _APP_REDIS_PORT
- _APP_DOMAIN_TARGET
- _APP_DB_HOST
- _APP_DB_PORT
- _APP_DB_SCHEMA

View file

@ -38,7 +38,7 @@ class DeletesV1
switch (strval($type)) {
case DELETE_TYPE_DOCUMENT:
$document = $this->args['document'];
$document = new Document($document);
$document = new Document($document);
switch (strval($document->getCollection())) {
case Database::SYSTEM_COLLECTION_PROJECTS:
$this->deleteProject($document);
@ -69,6 +69,11 @@ class DeletesV1
case DELETE_TYPE_ABUSE:
$this->deleteAbuseLogs($this->args['timestamp']);
break;
case DELETE_TYPE_CERTIFICATES:
$document = new Document($this->args['document']);
$this->deleteCertificates($document);
break;
default:
Console::error('No delete operation for type: '.$type);
@ -305,6 +310,21 @@ class DeletesV1
Console::info("Deleted {$count} document by group in " . ($executionEnd - $executionStart) . " seconds");
}
protected function deleteCertificates(Document $document)
{
$domain = $document->getAttribute('domain');
$directory = APP_STORAGE_CERTIFICATES . '/' . $domain;
$checkTraversal = realpath($directory) === $directory;
if($domain && $checkTraversal && is_dir($directory)) {
array_map('unlink', glob($directory.'/*.*'));
rmdir($directory);
Console::info("Deleted certificate files for {$domain}");
} else {
Console::info("No certificate files found for {$domain}");
}
}
/**
* @return Database;
*/

View file

@ -213,6 +213,7 @@ services:
- appwrite-uploads:/storage/uploads:rw
- appwrite-cache:/storage/cache:rw
- appwrite-functions:/storage/functions:rw
- appwrite-certificates:/storage/certificates:rw
- ./app:/usr/src/code/app
- ./src:/usr/src/code/src
depends_on: