feat: added notifiers for delete abuse and audit logs
This commit is contained in:
parent
8f9089accc
commit
f395c2e92c
|
@ -13,6 +13,8 @@ use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Config\Config;
|
use Utopia\Config\Config;
|
||||||
|
|
||||||
|
define("DELETE_QUEUE_NAME", "v1-deletes");
|
||||||
|
define("DELETE_CLASS_NAME", "DeletesV1");
|
||||||
|
|
||||||
function getConsoleDB() {
|
function getConsoleDB() {
|
||||||
global $register;
|
global $register;
|
||||||
|
@ -23,6 +25,26 @@ function getConsoleDB() {
|
||||||
return $consoleDB;
|
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
|
$cli
|
||||||
->task('maintenance')
|
->task('maintenance')
|
||||||
->desc('Schedules maintenance tasks and publishes them to resque')
|
->desc('Schedules maintenance tasks and publishes them to resque')
|
||||||
|
@ -48,12 +70,10 @@ $cli
|
||||||
return $project->getId();
|
return $project->getId();
|
||||||
}, $projects);
|
}, $projects);
|
||||||
|
|
||||||
Resque::enqueue('v1-deletes', 'DeletesV1', [
|
notifyDeleteExecutionLogs($projectIds);
|
||||||
'document' => new Document([
|
notifyDeleteAbuseLogs($projectIds);
|
||||||
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
|
notifyDeleteAuditLogs($projectIds);
|
||||||
'projectIds' => $projectIds
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
}, $interval);
|
}, $interval);
|
||||||
|
|
||||||
});
|
});
|
|
@ -14,6 +14,8 @@ use Appwrite\Database\Validator\Authorization;
|
||||||
use Appwrite\Storage\Device\Local;
|
use Appwrite\Storage\Device\Local;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Utopia\Config\Config;
|
use Utopia\Config\Config;
|
||||||
|
use Utopia\Audit\Audit;
|
||||||
|
use Utopia\Audit\Adapters\MySQL as AuditAdapter;
|
||||||
|
|
||||||
class DeletesV1
|
class DeletesV1
|
||||||
{
|
{
|
||||||
|
@ -100,7 +102,6 @@ class DeletesV1
|
||||||
|
|
||||||
protected function deleteExecutionLogs(Document $document)
|
protected function deleteExecutionLogs(Document $document)
|
||||||
{
|
{
|
||||||
|
|
||||||
$projectIds = $document->getAttribute('projectIds', []);
|
$projectIds = $document->getAttribute('projectIds', []);
|
||||||
foreach ($projectIds as $projectId) {
|
foreach ($projectIds as $projectId) {
|
||||||
if (!($projectDB = $this->getProjectDB($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)
|
protected function deleteFunction(Document $document, $projectId)
|
||||||
{
|
{
|
||||||
$projectDB = $this->getProjectDB($projectId);
|
$projectDB = $this->getProjectDB($projectId);
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
"appwrite/php-clamav": "1.0.*",
|
"appwrite/php-clamav": "1.0.*",
|
||||||
|
|
||||||
"utopia-php/framework": "0.9.8",
|
"utopia-php/framework": "0.9.8",
|
||||||
"utopia-php/abuse": "0.2.*",
|
"utopia-php/abuse": "0.3.*",
|
||||||
"utopia-php/audit": "0.3.*",
|
"utopia-php/audit": "0.4.*",
|
||||||
"utopia-php/cache": "0.2.*",
|
"utopia-php/cache": "0.2.*",
|
||||||
"utopia-php/cli": "0.8.0",
|
"utopia-php/cli": "0.8.0",
|
||||||
"utopia-php/config": "0.2.*",
|
"utopia-php/config": "0.2.*",
|
||||||
|
|
Loading…
Reference in a new issue