From ab11f045e368121f760bde3d18b1d47ea7ac00bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Fri, 8 Feb 2019 12:15:38 +0100 Subject: [PATCH] Add support for google cloud storage --- DependencyInjection/BMBackupManagerExtension.php | 3 +++ DependencyInjection/Configuration.php | 5 ++++- Resources/config/services.yml | 4 ++++ Tests/Unit/DependencyInjection/ConfigurationTest.php | 2 +- composer.json | 2 ++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/BMBackupManagerExtension.php b/DependencyInjection/BMBackupManagerExtension.php index 6ff5c4c..b976c13 100644 --- a/DependencyInjection/BMBackupManagerExtension.php +++ b/DependencyInjection/BMBackupManagerExtension.php @@ -10,6 +10,7 @@ use Srmklive\Dropbox\Adapter\DropboxAdapter as Dropbox2Adapter; use League\Flysystem\Rackspace\RackspaceAdapter; use League\Flysystem\Sftp\SftpAdapter; +use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Reference; @@ -41,6 +42,7 @@ public function load(array $configs, ContainerBuilder $container) 'DropboxV2' => 'backup_manager.filesystems.dropbox_v2_filesystem', 'Ftp' => 'backup_manager.filesystems.ftp_filesystem', 'Sftp' => 'backup_manager.filesystems.sftp_filesystem', + 'Gcs' => 'backup_manager.filesystems.gcs_filesystem', ]; $filesystemDef = $container->getDefinition('backup_manager.filesystems'); @@ -75,6 +77,7 @@ private function validateStorage(array $config) 'DropboxV2' => ['package'=>'srmklive/flysystem-dropbox-v2:^1.0', 'test'=>Dropbox2Adapter::class], 'Ftp' => ['package'=>'league/flysystem:^1.0', 'test'=>Ftp::class], 'Sftp' => ['package'=>'league/flysystem-sftp:^1.0', 'test'=>SftpAdapter::class], + 'Gcs' => ['package' => 'superbalist/flysystem-google-storage:^6.0', 'test' => GoogleStorageAdapter::class], ]; foreach ($config as $key => $storageConfig) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0d9dad5..9b73076 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -57,8 +57,11 @@ public function getConfigTreeBuilder() case 'Sftp': $this->validateAuthenticationType(['host', 'username', 'password', 'root', 'port', 'timeout', 'privateKey'], $config, 'Sftp'); break; + case 'Gcs': + $this->validateAuthenticationType(['project', 'keyFilePath', 'bucket', 'prefix'], $config, 'Gcs'); + break; default: - $validTypes = ['Local', 'AwsS3', 'B2', 'Rackspace', 'Dropbox', 'DropboxV2', 'Ftp', 'Sftp']; + $validTypes = ['Local', 'AwsS3', 'B2', 'Rackspace', 'Dropbox', 'DropboxV2', 'Ftp', 'Sftp', 'Gcs']; throw new InvalidConfigurationException(sprintf('Type must be one of "%s", got "%s"', implode(', ', $validTypes), $config['type'])); } } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index a8bd6f8..1c869cf 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -50,6 +50,10 @@ services: class: BackupManager\Filesystems\SftpFilesystem public: false + backup_manager.filesystems.gcs_filesystem: + class: BackupManager\Filesystems\GcsFilesystem + public: false + backup_manager.filesystems: class: BackupManager\Filesystems\FilesystemProvider public: false diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 8954a21..661d083 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -176,7 +176,7 @@ public function testStorageTypes($type) public function validStorageTypes() { return [ - ['Local'],['AwsS3'], ['B2'], ['Rackspace'], ['Dropbox'], ['DropboxV2'], ['Ftp'], ['Sftp'], + ['Local'],['AwsS3'], ['B2'], ['Rackspace'], ['Dropbox'], ['DropboxV2'], ['Ftp'], ['Sftp'], ['Gcs'], ]; } } diff --git a/composer.json b/composer.json index fe3764a..20ae03b 100644 --- a/composer.json +++ b/composer.json @@ -26,12 +26,14 @@ "matthiasnoback/symfony-dependency-injection-test": "^1.2 || ^2.3", "matthiasnoback/symfony-config-test": "^2.2 || ^3.1", "nyholm/symfony-bundle-test": "^1.3.1", + "superbalist/flysystem-google-storage": "^6.0 || ^ 7.0", "symfony/phpunit-bridge": "^3.4 || ^4.0" }, "suggest": { "league/flysystem-aws-s3-v3": "To use AWS S3, version 3", "mhetreramesh/flysystem-backblaze": "To use B2", "srmklive/flysystem-dropbox-v2": "To use Dropbox", + "superbalist/flysystem-google-storage": "Google Cloud Storage adapter support.", "league/flysystem-rackspace": "To use Rackspace", "league/flysystem-sftp": "To use sftp" },