Skip to content

Commit

Permalink
create missing container
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Jan 22, 2025
1 parent 29dadda commit b4d4279
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 86 deletions.
17 changes: 2 additions & 15 deletions src/Storages/AwsS3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ class AwsS3Storage implements IStorage

private LoggerInterface $logger;

private bool $userDefinedCredentials;

public const FEDERATION_TOKEN_EXPIRATION_HOURS = 36;

public function __construct(S3Config $config, bool $userDefinedCredentials, LoggerInterface $logger)
public function __construct(S3Config $config, LoggerInterface $logger)
{
$this->config = $config;
$this->logger = $logger;
$this->userDefinedCredentials = $userDefinedCredentials;
}

public function generateTempReadCredentials(string $backupId, string $path): array
Expand Down Expand Up @@ -72,17 +69,7 @@ public function getBackup(Client $sapi, string $path): Backup
]);
} catch (S3Exception $e) {
if ($e->getAwsErrorCode() === 'NoSuchKey') {
if ($this->userDefinedCredentials) {
$this->createBackupPath($path);
} else {
throw new UserException(
sprintf(
'Backup path "%s" not found in the bucket "%s".',
$path,
$this->config->getBucket(),
),
);
}
$this->createBackupPath($path);
} else {
throw new UserException($e->getAwsErrorMessage() ?? $e->getMessage());
}
Expand Down
5 changes: 1 addition & 4 deletions src/Storages/AzureBlobStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public function getBackup(Client $sapi, string $path): Backup
throw $e;
}
if (!in_array($path, $listContainers)) {
throw new UserException(sprintf(
'The specified container "%s" does not exist.',
$path,
));
$client->createContainer($path);
}

return new AbsBackup($sapi, $client, $path, $this->logger);
Expand Down
32 changes: 0 additions & 32 deletions tests/phpunit/FunctionalAbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,38 +237,6 @@ public function testSuccessfulRunOnlyStructure(): void
self::assertGreaterThan(0, count($events));
}

public function testBadBackupIdRun(): void
{
$fileSystem = new Filesystem();
$fileSystem->dumpFile(
$this->temp->getTmpFolder() . '/config.json',
(string) json_encode([
'action' => 'run',
'parameters' => [
'backupId' => $this->sapiClient->generateId(),
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_ABS,
'accountName' => getenv('TEST_AZURE_ACCOUNT_NAME'),
'#accountKey' => getenv('TEST_AZURE_ACCOUNT_KEY'),
'region' => getenv('TEST_AZURE_REGION'),
],
]),
);

$runProcess = $this->createTestProcess();
$runProcess->run();

$this->assertEquals(1, $runProcess->getExitCode());

$output = $runProcess->getOutput();
$errorOutput = $runProcess->getErrorOutput();

$this->assertEmpty($output);
$this->assertStringContainsString('The specified container', $errorOutput);
$this->assertStringContainsString('does not exist.', $errorOutput);
}

public function testRegionErrorRun(): void
{
$fileSystem = new Filesystem();
Expand Down
35 changes: 0 additions & 35 deletions tests/phpunit/FunctionalS3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,41 +274,6 @@ public function testSuccessfulRunOnlyStructure(): void
self::assertGreaterThan(0, count($events));
}

public function testBadBackupIdRun(): void
{
$fileSystem = new Filesystem();
$fileSystem->dumpFile(
$this->temp->getTmpFolder() . '/config.json',
(string) json_encode([
'action' => 'run',
'parameters' => [
'backupId' => $this->sapiClient->generateId(),
],
'image_parameters' => [
'storageBackendType' => Config::STORAGE_BACKEND_S3,
'access_key_id' => getenv('TEST_AWS_ACCESS_KEY_ID'),
'#secret_access_key' => getenv('TEST_AWS_SECRET_ACCESS_KEY'),
'region' => getenv('TEST_AWS_REGION'),
'#bucket' => getenv('TEST_AWS_S3_BUCKET'),
],
]),
);

$runProcess = $this->createTestProcess();
$runProcess->run();

$this->assertEquals(1, $runProcess->getExitCode());

$output = $runProcess->getOutput();
$errorOutput = $runProcess->getErrorOutput();

$this->assertEmpty($output);
$this->assertStringMatchesFormat(
'Backup path "%s" not found in the bucket "%s".',
trim($errorOutput),
);
}

public function testCreateUnexistsBackupFolderS3(): void
{
$fileSystem = new Filesystem();
Expand Down

0 comments on commit b4d4279

Please sign in to comment.