formatting

This commit is contained in:
Damodar Lohani
2022-07-25 08:12:14 +00:00
parent 394296f277
commit d2998963fa
3 changed files with 11 additions and 10 deletions
+5 -5
View File
@@ -381,11 +381,11 @@ Database::addFilter(
Database::addFilter(
'masterEncrypt',
function(mixed $value, Document $document, Database $database) {
function (mixed $value, Document $document, Database $database) {
$keyId = $document->getAttribute('keyId', '');
$database->setNamespace('_console');
$key = Authorization::skip(fn() => $database->getDocument('secrets', $keyId));
if($key->isEmpty()) {
if ($key->isEmpty()) {
throw new Exception("Unable to find master key with ID ($keyId} to encrypt.");
}
@@ -400,15 +400,15 @@ Database::addFilter(
'version' => $keyId,
]);
},
function(mixed $value, Document $document, Database $database) {
if(is_null($value)) {
function (mixed $value, Document $document, Database $database) {
if (is_null($value)) {
return null;
}
$value = json_decode($value, true);
$keyId = $value['version'];
$database->setNamespace('_console');
$key = Authorization::skip(fn() => $database->getDocument('secrets', $keyId));
if($key->isEmpty()) {
if ($key->isEmpty()) {
throw new Exception("Unable to find master key with ID {$keyId} to decrypt.");
}
$secret = $key->getAttribute('secret');
-1
View File
@@ -148,7 +148,6 @@ $cli
} else {
Console::info("[{$time}] No projects for key rotation.");
}
}
// # of days in seconds (1 day = 86400s)
+6 -4
View File
@@ -28,7 +28,7 @@ class EncryptionV1 extends Worker
{
$type = $this->args['type'] ?? '';
switch($type) {
switch ($type) {
case APP_ENCRYPTION_TYPE_PROJECT_MASTER_KEY:
$project = new Document($this->args['project'] ?? []);
$this->rotateMasterKeyForProject($project);
@@ -50,10 +50,12 @@ class EncryptionV1 extends Worker
'$collection' => 'secrets',
'secret' => OpenSSL::secretString(),
])));
$dbForConsole->updateDocument('projects', $projectId,
$dbForConsole->updateDocument(
'projects',
$projectId,
$project
->setAttribute('keyId', $secret->getId())
->setAttribute('keyRotationDate', time() + App::getEnv('_APP_KEY_ROTATION_INTERVAL', 60 * 60 * 24 * 90))
);
);
}
}
}