Skip to content

Commit

Permalink
feat: add skipRegionValidation configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Feb 2, 2025
1 parent ddf9b74 commit d5a5255
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], '');
Expand Down
1 change: 1 addition & 0 deletions src/Config/ConfigDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 47 additions & 0 deletions tests/phpunit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d5a5255

Please sign in to comment.