diff --git a/src/Application.php b/src/Application.php index 9af0ae1..d9f0116 100644 --- a/src/Application.php +++ b/src/Application.php @@ -104,7 +104,7 @@ private function generateBackupPath(int $backupId, StorageApi $client): string $region = $token['owner']['region']; $projectId = $token['owner']['id']; - if ($region !== $imageParams['region']) { + if (!$this->config->skipRegionValidation() && $region !== $imageParams['region']) { throw new Exception( sprintf( 'Project with ID "%s" is not located in %s region', diff --git a/src/Config/Config.php b/src/Config/Config.php index 17b180d..ead4404 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -44,6 +44,13 @@ public function includeVersions(): bool return $val; } + public function skipRegionValidation(): bool + { + /** @var bool $val */ + $val = $this->getValue(['parameters', 'skipRegionValidation'], false); + return $val; + } + public function isUserDefinedCredentials(): bool { $storageBackendType = $this->getValue(['parameters', 'storageBackendType'], ''); diff --git a/src/Config/ConfigDefinition.php b/src/Config/ConfigDefinition.php index 10618e8..45d13dc 100644 --- a/src/Config/ConfigDefinition.php +++ b/src/Config/ConfigDefinition.php @@ -97,6 +97,7 @@ protected function getParametersDefinition(): ArrayNodeDefinition ->scalarNode('backupPath')->end() ->booleanNode('exportStructureOnly')->end() ->booleanNode('includeVersions')->end() + ->booleanNode('skipRegionValidation')->defaultFalse()->end() ->scalarNode('storageBackendType')->end() ->scalarNode('accountName')->end() ->scalarNode('#accountKey')->end() diff --git a/tests/phpunit/ConfigTest.php b/tests/phpunit/ConfigTest.php index 98ebee4..9db0ee5 100644 --- a/tests/phpunit/ConfigTest.php +++ b/tests/phpunit/ConfigTest.php @@ -57,6 +57,34 @@ public function testBackupId(): void Assert::assertEquals('', $config->getBackupId()); } + public function testSkipRegionValidation(): void + { + $config = new Config([ + 'action' => 'run', + 'parameters' => [ + 'backupId' => '123456', + 'skipRegionValidation' => true, + ], + 'image_parameters' => [ + 'storageBackendType' => Config::STORAGE_BACKEND_S3, + ], + ], new ConfigDefinition()); + + Assert::assertTrue($config->skipRegionValidation()); + + $config = new Config([ + 'action' => 'run', + 'parameters' => [ + 'backupId' => '123456', + ], + 'image_parameters' => [ + 'storageBackendType' => Config::STORAGE_BACKEND_S3, + ], + ], new ConfigDefinition()); + + Assert::assertFalse($config->skipRegionValidation()); + } + /** @dataProvider invalidConfigDataProvider */ public function testInvalidConfig(array $configArray, string $expectedExceptionMessage): void { @@ -252,6 +280,25 @@ public function validConfigDataProvider(): Generator true, Config::STORAGE_BACKEND_ABS, ]; + + yield 'config-with-skip-region-validation' => [ + [ + 'action' => 'run', + 'parameters' => [ + 'backupId' => 123456, + 'skipRegionValidation' => true, + ], + 'image_parameters' => [ + 'storageBackendType' => Config::STORAGE_BACKEND_S3, + ], + ], + [ + 'storageBackendType' => Config::STORAGE_BACKEND_S3, + ], + '.', + false, + Config::STORAGE_BACKEND_S3, + ]; } public function invalidConfigDataProvider(): Generator