From dc67a7911a9c51f7f73eda4b5f5424073fa8b034 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 2 Jun 2025 13:55:44 +0200 Subject: [PATCH] wip #7567 @2 --- src/Transfer/GCS.php | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/Transfer/GCS.php b/src/Transfer/GCS.php index 35fca78..d4399c0 100644 --- a/src/Transfer/GCS.php +++ b/src/Transfer/GCS.php @@ -16,33 +16,32 @@ class GCS extends Driver */ protected function createClient(&$data) { - dddd($data); - return new StorageClient(); + return new StorageClient(['keyFile' => json_decode($this->getServer()->gcs_service_account_key, true)]); } public function checkConnexion($data = []) { - if(!$this->checkConnection){ + if (!$this->checkConnection) { return true; } + $data = [ + 'base_path' => $this->getServer()->getBasePath() ?? '/', + 'bucket' => $this->getServer()->getBucket(), + ]; $client = $this->createClient($data); $test = 'test' . time() . '-' . rand(1, 1000000); - $testFile = trim($data['base_path'], '/') . '/' . $test . '.txt'; + $dir = trim($data['base_path'], '/') . '/'; + $testFile = $dir . $test . '.txt'; - $oc = ['Bucket' => $data['bucket'], 'Key' => $testFile]; + $bucket = $client->bucket($data['bucket']); - try { - $client->putObject(array_merge($oc, ['Body' => $test])); - } catch (\Exception $e) { - return ['error' => true, 'message' => $e->getMessage()]; - } + $bucket->upload($test, ['name' => $testFile]); - $o = $client->getObject($oc); - $ocontent = $o->get('Body'); + $ocontent = $bucket->object($testFile)->downloadAsString(); - $client->deleteObject($oc); + $bucket->object($testFile)->delete(); if ($ocontent == $test) { return true; @@ -50,25 +49,6 @@ class GCS extends Driver return self::ERROR_SEND_FILE; } - protected function _getClientConfig(&$data) - { - $data = [ - 'access_key' => $data['access_key'] ?? $this->getServer()->getAccessKey(), - 'secret' => $data['secret'] ?? $this->getServer()->getSecret(), - 'region' => ($data['region'] ?? $this->getServer()->getRegion()) ?: 'eu-west-3', - 'bucket' => $data['bucket'] ?? $this->getServer()->getBucket(), - 'endpoint' => $data['endpoint'] ?? $this->getServer()->getEndpoint(), - 'base_path' => trim($data['base_path'] ?? $this->getServer()->getBasePath(), "/"), - 'provider' => $data['s3_provider'] ?? $this->getServer()->getS3Provider(), - ]; - - return ['region' => $data['region'], - 'version' => '2006-03-01', - 'endpoint' => $data['endpoint'], - 'use_path_style_endpoint' => static::usePathStyleEndpoint($data['provider']), - 'credentials' => ['key' => $data['access_key'], 'secret' => $data['secret']] - ]; - } protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) { $rclone = new LocalToGCSRclone(); -- 2.39.5