]> _ Git - cubist_net.git/commitdiff
wip #7567 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 2 Jun 2025 11:55:44 +0000 (13:55 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 2 Jun 2025 11:55:44 +0000 (13:55 +0200)
src/Transfer/GCS.php

index 35fca78192b113761f395372b476898f89effbc1..d4399c01e300aae830bba5fb95026f3df1b908a9 100644 (file)
@@ -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();