1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

feat: added notifiers for delete abuse and audit logs

This commit is contained in:
Christy Jacob 2020-12-17 20:45:47 +05:30
parent 8f9089accc
commit f395c2e92c
3 changed files with 62 additions and 9 deletions

View file

@ -13,6 +13,8 @@ use Utopia\App;
use Utopia\CLI\Console;
use Utopia\Config\Config;
define("DELETE_QUEUE_NAME", "v1-deletes");
define("DELETE_CLASS_NAME", "DeletesV1");
function getConsoleDB() {
global $register;
@ -23,6 +25,26 @@ function getConsoleDB() {
return $consoleDB;
}
function notifyDeleteExecutionLogs(array $projectIds)
{
Resque::enqueue(DELETE_QUEUE_NAME, DELETE_CLASS_NAME, [
'document' => new Document([
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
'projectIds' => $projectIds
]),
]);
}
function notifyDeleteAbuseLogs(array $projectIds)
{
}
function notifyDeleteAuditLogs(array $projectIds)
{
}
$cli
->task('maintenance')
->desc('Schedules maintenance tasks and publishes them to resque')
@ -48,12 +70,10 @@ $cli
return $project->getId();
}, $projects);
Resque::enqueue('v1-deletes', 'DeletesV1', [
'document' => new Document([
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
'projectIds' => $projectIds
]),
]);
notifyDeleteExecutionLogs($projectIds);
notifyDeleteAbuseLogs($projectIds);
notifyDeleteAuditLogs($projectIds);
}, $interval);
});

View file

@ -14,6 +14,8 @@ use Appwrite\Database\Validator\Authorization;
use Appwrite\Storage\Device\Local;
use Utopia\CLI\Console;
use Utopia\Config\Config;
use Utopia\Audit\Audit;
use Utopia\Audit\Adapters\MySQL as AuditAdapter;
class DeletesV1
{
@ -100,7 +102,6 @@ class DeletesV1
protected function deleteExecutionLogs(Document $document)
{
$projectIds = $document->getAttribute('projectIds', []);
foreach ($projectIds as $projectId) {
if (!($projectDB = $this->getProjectDB($projectId))) {
@ -115,6 +116,38 @@ class DeletesV1
}
}
protected function deleteAbuseLogs($document)
{
global $register;
$projectIds = $document->getAttribute('projectIds', []);
foreach ($projectIds as $projectId) {
$adapter = new AuditAdapter($register->get('db'));
$adapter->setNamespace('app_'.$projectId);
$audit = new Audit($adapter);
$status = $audit->deleteLogsOlderThan();
if (!$status) {
throw new Exception('Failed to delete Audit logs for project'.$projectId, 500);
}
}
}
protected function deleteAuditLogs($document)
{
global $register;
$projectIds = $document->getAttribute('projectIds', []);
foreach ($projectIds as $projectId) {
$adapter = new AuditAdapter($register->get('db'));
$adapter->setNamespace('app_'.$projectId);
$audit = new Audit($adapter);
$status = $audit->deleteLogsOlderThan();
if (!$status) {
throw new Exception('Failed to delete Audit logs for project'.$projectId, 500);
}
}
}
protected function deleteFunction(Document $document, $projectId)
{
$projectDB = $this->getProjectDB($projectId);

View file

@ -35,8 +35,8 @@
"appwrite/php-clamav": "1.0.*",
"utopia-php/framework": "0.9.8",
"utopia-php/abuse": "0.2.*",
"utopia-php/audit": "0.3.*",
"utopia-php/abuse": "0.3.*",
"utopia-php/audit": "0.4.*",
"utopia-php/cache": "0.2.*",
"utopia-php/cli": "0.8.0",
"utopia-php/config": "0.2.*",