8000 Add support for AsyncAws by Nyholm · Pull Request #168 · backup-manager/backup-manager · GitHub
[go: up one dir, main page]

Skip to content

Add support for AsyncAws #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 10
matrix:
php: [ '7.4', '8.0', '8.1']
php: ['8.0', '8.1']

steps:
- name: Set up PHP
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ This package provides a framework-agnostic database backup manager for dumping t
'root' => '/path/to/working/directory',
],
's3' => [
'type' => 'AwsS3',
'type' => 'AwsS3', // AsyncAws is also supported with type 'AsyncAwsS3'
'key' => '',
'secret' => '',
'region' => 'us-east-1',
Expand Down Expand Up @@ -207,11 +207,14 @@ Then, you'll need to select the appropriate packages for the adapters that you w
# to support s3
composer require league/flysystem-aws-s3-v3

# to support AsyncAwsS3
composer require async-aws/flysystem-s3

# to support b2
composer require mhetreramesh/flysystem-backblaze

# to support google cs
composer require league/flysystem-aws-s3-v2
composer require superbalist/flysystem-google-storage

# to install the preferred dropbox v2 driver
composer required spatie/flysystem-dropbox
Expand Down
15 changes: 6 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.0",
"league/flysystem": "^1.1.4 || ^2.1.1 || ^3.0",
"symfony/process": "^5.4 || ^6.0"
},
"require-dev": {
"aws/aws-sdk-php": "^3.133.20",
"league/flysystem-aws-s3-v3": "^1.0.24",
"league/flysystem-rackspace": "^1.0",
"league/flysystem-sftp": "^1.0",
"league/flysystem-webdav": "^1.0",
"league/flysystem-async-aws-s3": "^2.0.6 || ^3.0",
"league/flysystem-aws-s3-v3": "^1.0.24 || ^2.0 || ^3.0",
"league/flysystem-sftp": "^1.1 || ^2.0 || ^3.0",
"league/flysystem-webdav": "^1.0.10 || ^3.0",
"phpspec/phpspec": "^7.2",
"spatie/flysystem-dropbox": "^1.2",
"srmklive/flysystem-dropbox-v2": "^1.0",
"superbalist/flysystem-google-storage": "^7.2"
"spatie/flysystem-dropbox": "^2.0"
},
"suggest": {
"league/flysystem-aws-s3-v3": "AWS S3 adapter support.",
Expand Down
36 changes: 36 additions & 0 deletions spec/Filesystems/AsyncAwsS3FilesystemSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace spec\BackupManager\Filesystems;

use PhpSpec\ObjectBehavior;

class AsyncAwsS3FilesystemSpec extends ObjectBehavior {

function it_is_initializable() {
$this->shouldHaveType('BackupManager\Filesystems\AsyncAwsS3Filesystem');
}

function it_should_recognize_its_type_with_case_insensitivity() {
foreach (['asyncawss3', 'AsyncAWSS3', 'AsyncAwsS3', 'async-awss3', 'async-aws-s3'] as $type) {
$this->handles($type)->shouldBe(true);
}

foreach ([null, 'foo'] as $type) {
$this->handles($type)->shouldBe(false);
}
}

function it_should_provide_an_instance_of_an_s3_filesystem() {
$this->get($this->getConfig())->getAdapter()->shouldHaveType('League\Flysystem\AsyncAwsS3\AsyncAwsS3Adapter');
}

function getConfig() {
return [
'key' => 'key',
'secret' => 'secret',
'region' => 'us-east-1',
'bucket' => 'bucket',
'root' => 'prefix',
];
}
}
10 changes: 5 additions & 5 deletions spec/Filesystems/FlysystemFilesystemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace spec\BackupManager\Filesystems;

use BackupManager\Filesystems\FlysystemFilesystem;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\FilesystemAdapter;
use League\Flysystem\MountManager;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
Expand All @@ -26,18 +26,18 @@ public function it_should_recognize_its_type_with_case_insensitivity()
}
}

public function it_should_provide_an_instance_of_an_flysystem_filesystem(FilesystemInterface $filesystem)
public function it_should_provide_an_instance_of_an_flysystem_filesystem(FilesystemAdapter $filesystem)
{
$name = 's3_backup';
$this->beConstructedWith([$name => $filesystem]);
$this->get(['name' => $name])->shouldHaveType(FilesystemInterface::class);
$this->get(['name' => $name])->shouldHaveType(FilesystemAdapter::class);
}

public function it_should_provide_an_instance_of_an_flysystem_filesystem_in_mount_manager(MountManager $manager, FilesystemInterface $filesystem)
public function it_should_provide_an_instance_of_an_flysystem_filesystem_in_mount_manager(MountManager $manager, FilesystemAdapter $filesystem)
{
$prefix = 'upload';
$manager->getFilesystem(Argument::exact($prefix))->willReturn($filesystem);
$this->beConstructedWith([], $manager);
$this->get(['prefix' => $prefix])->shouldHaveType(FilesystemInterface::class);
$this->get(['prefix' => $prefix])->shouldHaveType(FilesystemAdapter::class);
}
}
51 changes: 51 additions & 0 deletions src/Filesystems/AsyncAwsS3Filesystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php namespace BackupManager\Filesystems;

use AsyncAws\S3\S3Client;
use League\Flysystem\AsyncAwsS3\AsyncAwsS3Adapter;
use League\Flysystem\Filesystem as Flysystem;

/**
* @package BackupManager\Filesystems
*/
class AsyncAwsS3Filesystem implements Filesystem
{
/**
* @param $type
* @return bool
*/
public function handles($type)
{
$type = strtolower($type);

return $type == 'asyncawss3' || $type == 'async-awss3' || $type == 'async-aws-s3';
}

/**
* @param array $config
* @return Flysystem
*/
public function get(array $config)
{
$clientConfig = [
'pathStyleEndpoint' => isset($config['use_path_style_endpoint']) ? $config['use_path_style_endpoint'] : false
];

if (null !== $config['key']) {
$clientConfig['accessKeyId'] = $config['key'];
}

if (null !== $config['secret']) {
$clientConfig['accessKeySecret'] = $config['secret'];
}

if (null !== $config['region']) {
$clientConfig['region'] = $config['region'];
}

if (null !== $config['endpoint']) {
4462 $clientConfig['endpoint'] = $config['endpoint'];
}

return new Flysystem(new AsyncAwsS3Adapter(new S3Client($clientConfig), $config['bucket'], $config['root']));
}
}
0