Merge pull request #12308 from appwrite/add-api-key-migration

Add API key migration support
This commit is contained in:
Jake Barnby authored and GitHub committed 2026-06-04 15:22:52 +12:00
commit 2bfcf13da9
5 files changed
+140 -22

No files matched your search

Generated
+20 -20
View File
@@ -69,16 +69,16 @@
},
{
"name": "appwrite/appwrite",
"version": "23.1.1",
"version": "24.2.0",
"source": {
"type": "git",
"url": "https://github.com/appwrite/sdk-for-php.git",
"reference": "fd7c0f0bf5ddf334533534b20ed967cfb400f6ea"
"reference": "d3217b6524b9d174ab91fb7ffc555c68bfa1da97"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/fd7c0f0bf5ddf334533534b20ed967cfb400f6ea",
"reference": "fd7c0f0bf5ddf334533534b20ed967cfb400f6ea",
"url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/d3217b6524b9d174ab91fb7ffc555c68bfa1da97",
"reference": "d3217b6524b9d174ab91fb7ffc555c68bfa1da97",
"shasum": ""
},
"require": {
@@ -104,10 +104,10 @@
"support": {
"email": "team@appwrite.io",
"issues": "https://github.com/appwrite/sdk-for-php/issues",
"source": "https://github.com/appwrite/sdk-for-php/tree/23.1.1",
"source": "https://github.com/appwrite/sdk-for-php/tree/24.2.0",
"url": "https://appwrite.io/support"
},
"time": "2026-05-12T11:03:36+00:00"
"time": "2026-05-21T18:56:51+00:00"
},
{
"name": "appwrite/php-clamav",
@@ -3359,20 +3359,20 @@
},
{
"name": "utopia-php/abuse",
"version": "1.3.0",
"version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/abuse.git",
"reference": "5d7efbe5c6b0cf7d06003114fd86e24ba785582f"
"reference": "00e59c89a1ac5f4ad771695e5dbee020b3c7ac44"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/5d7efbe5c6b0cf7d06003114fd86e24ba785582f",
"reference": "5d7efbe5c6b0cf7d06003114fd86e24ba785582f",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/00e59c89a1ac5f4ad771695e5dbee020b3c7ac44",
"reference": "00e59c89a1ac5f4ad771695e5dbee020b3c7ac44",
"shasum": ""
},
"require": {
"appwrite/appwrite": "23.*",
"appwrite/appwrite": "24.*",
"ext-curl": "*",
"ext-pdo": "*",
"ext-redis": "*",
@@ -3405,9 +3405,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/abuse/issues",
"source": "https://github.com/utopia-php/abuse/tree/1.3.0"
"source": "https://github.com/utopia-php/abuse/tree/1.3.1"
},
"time": "2026-05-11T08:07:02+00:00"
"time": "2026-06-03T07:30:05+00:00"
},
{
"name": "utopia-php/agents",
@@ -4658,20 +4658,20 @@
},
{
"name": "utopia-php/migration",
"version": "1.12.0",
"version": "1.13.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "3ee6e12af256726bddc3a0402c94535132abecc6"
"reference": "0395af61922b52fb73bd9dbfb2dd10ac7aed2b01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/3ee6e12af256726bddc3a0402c94535132abecc6",
"reference": "3ee6e12af256726bddc3a0402c94535132abecc6",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/0395af61922b52fb73bd9dbfb2dd10ac7aed2b01",
"reference": "0395af61922b52fb73bd9dbfb2dd10ac7aed2b01",
"shasum": ""
},
"require": {
"appwrite/appwrite": "23.*",
"appwrite/appwrite": "24.*",
"ext-curl": "*",
"ext-openssl": "*",
"halaxa/json-machine": "^1.2",
@@ -4707,9 +4707,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/1.12.0"
"source": "https://github.com/utopia-php/migration/tree/1.13.0"
},
"time": "2026-05-14T07:30:09+00:00"
"time": "2026-06-03T06:15:27+00:00"
},
{
"name": "utopia-php/mongo",
@@ -59,6 +59,12 @@ class MigrationReport extends Model
'default' => 0,
'example' => 5,
])
->addRule(Resource::TYPE_API_KEY, [
'type' => self::TYPE_INTEGER,
'description' => 'Number of API keys to be migrated.',
'default' => 0,
'example' => 5,
])
->addRule(Resource::TYPE_SITE, [
'type' => self::TYPE_INTEGER,
'description' => 'Number of sites to be migrated.',
@@ -43,6 +43,12 @@ class Project extends Model
'default' => '',
'example' => '1592981250',
])
->addRule('region', [
'type' => self::TYPE_STRING,
'description' => 'Project region.',
'default' => 'default',
'example' => 'fra',
])
// Resource: Dev Keys
->addRule('devKeys', [
@@ -173,6 +179,19 @@ class Project extends Model
'example' => new \stdClass(),
'array' => true,
])
->addRule('blocks', [
'type' => self::TYPE_STRING,
'description' => 'Project blocks information.',
'default' => [],
'example' => [],
'array' => true,
])
->addRule('consoleAccessedAt', [
'type' => self::TYPE_DATETIME,
'description' => 'Last time the project was accessed via console.',
'default' => '',
'example' => self::TYPE_DATETIME_EXAMPLE,
])
;
}
@@ -207,10 +226,16 @@ class Project extends Model
$this->expandServices($document);
$this->expandProtocols($document);
$this->expandAuthMethods($document);
$this->expandConsoleAccessedAt($document);
return $document;
}
private function expandConsoleAccessedAt(Document $document): void
{
$document->setAttribute('consoleAccessedAt', $document->getAttribute('accessedAt', ''));
}
private function expandSmtpFields(Document $document): void
{
if (!$document->isSet('smtp')) {
+1 -1
View File
@@ -111,7 +111,7 @@ trait ProjectCustom
'x-appwrite-project' => 'console',
], [
'keyId' => ID::unique(),
'name' => 'Demo Project Key',
'name' => 'Demo Project Key ' . $project['body']['$id'],
'scopes' => [
'users.read',
'users.write',
@@ -224,7 +224,11 @@ trait MigrationsBase
$this->assertEquals(Appwrite::getSupportedResources(), $response['resources']);
$this->assertEquals('Appwrite', $response['source']);
$this->assertEquals('Appwrite', $response['destination']);
$this->assertEmpty($response['statusCounters']);
$this->assertArrayHasKey(Resource::TYPE_API_KEY, $response['statusCounters']);
$counts = $response['statusCounters'][Resource::TYPE_API_KEY];
$this->assertEquals(0, $counts['error']);
$this->assertGreaterThan(0, $counts['success']);
}
/**
@@ -2540,6 +2544,89 @@ trait MigrationsBase
$this->client->call(Client::METHOD_DELETE, '/project/platforms/' . $platform['$id'], $sourceHeaders);
}
public function testAppwriteMigrationApiKey(): void
{
$sourceHeaders = [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
];
$destinationHeaders = [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getDestinationProject()['$id'],
'x-appwrite-key' => $this->getDestinationProject()['apiKey'],
];
// Create API key on source project
$response = $this->client->call(Client::METHOD_POST, '/project/keys', $sourceHeaders, [
'keyId' => ID::unique(),
'name' => 'Test API Key',
'scopes' => ['databases.read', 'databases.write'],
'expire' => null,
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertNotEmpty($response['body']['$id']);
$apiKey = $response['body'];
$result = $this->performMigrationSync([
'resources' => [
Resource::TYPE_API_KEY,
],
'endpoint' => $this->webEndpoint,
'projectId' => $this->getProject()['$id'],
'apiKey' => $this->getProject()['apiKey'],
]);
$this->assertEquals('completed', $result['status']);
$this->assertEquals([Resource::TYPE_API_KEY], $result['resources']);
$this->assertArrayHasKey(Resource::TYPE_API_KEY, $result['statusCounters']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_API_KEY]['error']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_API_KEY]['pending']);
$this->assertGreaterThanOrEqual(1, $result['statusCounters'][Resource::TYPE_API_KEY]['success']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_API_KEY]['processing']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_API_KEY]['warning']);
// Verify API key on destination project using the project's API key
$response = $this->client->call(Client::METHOD_GET, '/project/keys', $destinationHeaders);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']);
$this->assertGreaterThan(0, $response['body']['total']);
$foundKey = null;
foreach ($response['body']['keys'] as $k) {
if ($k['name'] === 'Test API Key') {
$foundKey = $k;
break;
}
}
$this->assertNotNull($foundKey);
$this->assertEquals('Test API Key', $foundKey['name']);
$this->assertEqualsCanonicalizing(['databases.read', 'databases.write'], $foundKey['scopes']);
$this->assertEmpty($foundKey['expire']);
$this->assertNotEquals($apiKey['secret'], $foundKey['secret']);
// Cleanup migrated keys on destination — delete anything that isn't the destination's own auth key,
// otherwise later tests inherit duplicated apiKeys and fail on conflict.
$destinationAuthSecret = $this->getDestinationProject()['apiKey'];
foreach ($response['body']['keys'] as $k) {
if ($k['secret'] === $destinationAuthSecret) {
continue;
}
$this->client->call(Client::METHOD_DELETE, '/project/keys/' . $k['$id'], $destinationHeaders);
}
// Cleanup on source
$this->client->call(Client::METHOD_DELETE, '/project/keys/' . $apiKey['$id'], $sourceHeaders);
}
/**
* Import documents from a CSV file.
*/