*/
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;
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();