feat(migration): add api key migration
This commit is contained in:
parent
bda5e13ac0
commit
bfccaa1362
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
namespace Appwrite\Migration\Version;
|
namespace Appwrite\Migration\Version;
|
||||||
|
|
||||||
|
|
||||||
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Appwrite\Database\Database;
|
use Appwrite\Database\Database;
|
||||||
use Appwrite\Database\Document;
|
use Appwrite\Database\Document;
|
||||||
use Appwrite\Migration\Migration;
|
use Appwrite\Migration\Migration;
|
||||||
|
use Appwrite\OpenSSL\OpenSSL;
|
||||||
|
|
||||||
class V06 extends Migration
|
class V06 extends Migration
|
||||||
{
|
{
|
||||||
|
@ -14,7 +17,9 @@ class V06 extends Migration
|
||||||
$project = $this->project;
|
$project = $this->project;
|
||||||
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
||||||
|
|
||||||
|
$this->projectDB->disableFilters();
|
||||||
$this->forEachDocument([$this, 'fixDocument']);
|
$this->forEachDocument([$this, 'fixDocument']);
|
||||||
|
$this->projectDB->enableFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function fixDocument(Document $document)
|
protected function fixDocument(Document $document)
|
||||||
|
@ -27,6 +32,21 @@ class V06 extends Migration
|
||||||
->removeAttribute('password-update');
|
->removeAttribute('password-update');
|
||||||
}
|
}
|
||||||
break;
|
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;
|
return $document;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue