Merge pull request #881 from TorstenDittmann/feat-delete-certificates
Delete certificate files with worker
This commit is contained in:
commit
133235d4a6
|
@ -477,10 +477,17 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -70,6 +70,11 @@ class DeletesV1
|
|||
$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);
|
||||
break;
|
||||
|
@ -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;
|
||||
*/
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue