1
0
Fork 0
mirror of synced 2024-06-26 10:10:57 +12:00

feat(migration): add api key migration

This commit is contained in:
Torsten Dittmann 2021-01-15 12:57:32 +01:00
parent bda5e13ac0
commit bfccaa1362

View file

@ -2,10 +2,13 @@
namespace Appwrite\Migration\Version;
use Utopia\App;
use Utopia\CLI\Console;
use Appwrite\Database\Database;
use Appwrite\Database\Document;
use Appwrite\Migration\Migration;
use Appwrite\OpenSSL\OpenSSL;
class V06 extends Migration
{
@ -14,7 +17,9 @@ class V06 extends Migration
$project = $this->project;
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
$this->projectDB->disableFilters();
$this->forEachDocument([$this, 'fixDocument']);
$this->projectDB->enableFilters();
}
protected function fixDocument(Document $document)
@ -27,6 +32,21 @@ class V06 extends Migration
->removeAttribute('password-update');
}
break;
case Database::SYSTEM_COLLECTION_KEYS:
if ($document->getAttribute('secret', null)) {
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
$tag = null;
$document->setAttribute('secret', json_encode([
'data' => OpenSSL::encrypt($document->getAttribute('secret'), OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
'method' => OpenSSL::CIPHER_AES_128_GCM,
'iv' => bin2hex($iv),
'tag' => bin2hex($tag),
'version' => '1',
]));
}
break;
}
return $document;
}