Skip to content

Commit

Permalink
support more regions
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Jan 30, 2025
1 parent ddf9b74 commit a3f4242
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ private function generateBackupPath(int $backupId, StorageApi $client): string
$region = $token['owner']['region'];
$projectId = $token['owner']['id'];

if ($region !== $imageParams['region']) {
if (!in_array($region, $imageParams['regions'], true)) {
throw new Exception(
sprintf(
'Project with ID "%s" is not located in %s region',
'Project with ID "%s" is not located in %s regions',
$projectId,
$imageParams['region'],
implode(',', $imageParams['regions']),
),
);
}
Expand Down
46 changes: 23 additions & 23 deletions tests/phpunit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ public function validConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
],
[
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
'.',
Expand All @@ -121,14 +121,14 @@ public function validConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
],
[
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'',
false,
Expand All @@ -142,21 +142,21 @@ public function validConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
],
[
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
'.',
Expand All @@ -172,13 +172,13 @@ public function validConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
],
Expand All @@ -187,7 +187,7 @@ public function validConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'testPath',
true,
Expand All @@ -201,22 +201,22 @@ public function validConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'backupPath' => 'testPath',
'#bucket' => 'testBucket',
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
],
[
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
'backupPath' => 'testPath',

Expand Down Expand Up @@ -263,7 +263,7 @@ public function invalidConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
Expand All @@ -280,7 +280,7 @@ public function invalidConfigDataProvider(): Generator
'backupPath' => 'testBackupPath',
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'#accountKey' => 'testAccountKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
Expand All @@ -296,7 +296,7 @@ public function invalidConfigDataProvider(): Generator
'backupPath' => 'testBackupPath',
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => 'testAccountName',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
Expand All @@ -311,7 +311,7 @@ public function invalidConfigDataProvider(): Generator
'parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
'image_parameters' => [
Expand All @@ -327,7 +327,7 @@ public function invalidConfigDataProvider(): Generator
'parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
'image_parameters' => [
Expand Down Expand Up @@ -360,7 +360,7 @@ public function invalidConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_S3,
Expand All @@ -377,7 +377,7 @@ public function invalidConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => 'testAccessKeyId',
'#secret_access_key' => 'testAccessKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
'#bucket' => 'testBucket',
],
],
Expand All @@ -393,7 +393,7 @@ public function invalidConfigDataProvider(): Generator
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => 'testJsonKey',
'#bucket' => 'testBucket',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
],
'The child node "backupId" at path "root.parameters" must be configured.',
Expand All @@ -406,7 +406,7 @@ public function invalidConfigDataProvider(): Generator
'backupId' => 'testBackupId',
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#bucket' => 'testBucket',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
Expand All @@ -422,7 +422,7 @@ public function invalidConfigDataProvider(): Generator
'backupId' => 'testBackupId',
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => 'testJsonKey',
'region' => 'testRegion',
'regions' => ['testRegion'],
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/FunctionalAbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testCreateCredentials(): void
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
'regions' => [getenv('TEST_AZURE_REGION')],
],
]),
);
Expand Down Expand Up @@ -114,7 +114,7 @@ public function testSuccessfulRun(): void
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
'regions' => [getenv('TEST_AZURE_REGION')],
],
]),
);
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testSuccessfulRun(): void
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
'regions' => [getenv('TEST_AZURE_REGION')],
],
]),
);
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testSuccessfulRunOnlyStructure(): void
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
'regions' => [getenv('TEST_AZURE_REGION')],
],
]),
);
Expand Down Expand Up @@ -217,7 +217,7 @@ public function testSuccessfulRunOnlyStructure(): void
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
'regions' => [getenv('TEST_AZURE_REGION')],
],
]),
);
Expand Down Expand Up @@ -251,7 +251,7 @@ public function testRegionErrorRun(): void
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => 'unknown-custom-region',
'regions' => ['unknown-custom-region'],
],
]),
);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/FunctionalAbsWrongCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testWrongAccountKey(): void
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => 'wrongsecret',
'region' => getenv('TEST_AZURE_REGION'),
'regions' => [getenv('TEST_AZURE_REGION')],
],
]),
);
Expand Down
14 changes: 7 additions & 7 deletions tests/phpunit/FunctionalGCSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testCreateCredentials(): void
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => getenv('TEST_GCP_SERVICE_ACCOUNT'),
'region' => getenv('TEST_GCP_REGION'),
'regions' => [getenv('TEST_GCP_REGION')],
'#bucket' => getenv('TEST_GCP_BUCKET'),
],
]),
Expand All @@ -97,7 +97,7 @@ public function testCreateCredentials(): void
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => getenv('TEST_GCP_SERVICE_ACCOUNT'),
'region' => getenv('TEST_GCP_REGION'),
'regions' => [getenv('TEST_GCP_REGION')],
'#bucket' => getenv('TEST_GCP_BUCKET'),
],
]),
Expand Down Expand Up @@ -192,7 +192,7 @@ public function testSuccessfulRun(): void
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => getenv('TEST_GCP_SERVICE_ACCOUNT'),
'region' => getenv('TEST_GCP_REGION'),
'regions' => [getenv('TEST_GCP_REGION')],
'#bucket' => getenv('TEST_GCP_BUCKET'),
],
]),
Expand Down Expand Up @@ -241,7 +241,7 @@ public function testSuccessfulRunOnlyStructure(): void
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => getenv('TEST_GCP_SERVICE_ACCOUNT'),
'region' => getenv('TEST_GCP_REGION'),
'regions' => [getenv('TEST_GCP_REGION')],
'#bucket' => getenv('TEST_GCP_BUCKET'),
],
]),
Expand Down Expand Up @@ -272,15 +272,15 @@ public function testCreateUnexistsBackupFolder(): void
'parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => getenv('TEST_GCP_SERVICE_ACCOUNT'),
'region' => getenv('TEST_GCP_REGION'),
'regions' => [getenv('TEST_GCP_REGION')],
'#bucket' => getenv('TEST_GCP_BUCKET'),
'backupPath' => 'unexists/backup/folder',
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'access_key_id' => '',
'#secret_access_key' => '',
'region' => '',
'regions' => [''],
'#bucket' => '',
],
]),
Expand Down Expand Up @@ -314,7 +314,7 @@ public function testRegionErrorRun(): void
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_GCS,
'#jsonKey' => getenv('TEST_GCP_SERVICE_ACCOUNT'),
'region' => 'unknown-custom-region',
'regions' => ['unknown-custom-region'],
'#bucket' => getenv('TEST_GCP_BUCKET'),
],
]),
Expand Down
Loading

0 comments on commit a3f4242

Please sign in to comment.