From 62a563a6d82e12bd617a540d7c7f18e9200581c2 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Fri, 16 Aug 2019 15:09:43 -0500 Subject: [PATCH] bugfix: allow authentication with automatic GCP discovery --- src/GoogleCloudStorageServiceProvider.php | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/GoogleCloudStorageServiceProvider.php b/src/GoogleCloudStorageServiceProvider.php index 22cdf3c..0c10292 100644 --- a/src/GoogleCloudStorageServiceProvider.php +++ b/src/GoogleCloudStorageServiceProvider.php @@ -84,21 +84,24 @@ public function boot() */ private function createClient($config) { - $keyFile = array_get($config, 'key_file'); - if (is_string($keyFile)) { - return new StorageClient([ - 'projectId' => $config['project_id'], - 'keyFilePath' => $keyFile, - ]); + $options = []; + if (isset($config['project_id'])) { + $options['projectId'] = $config['project_id']; } - if (! is_array($keyFile)) { - $keyFile = []; + if (isset($config['key_file'])) { + $keyFile = array_get($config, 'key_file'); + if (is_string($keyFile)) { + $options['keyFilePath'] = $keyFile; + } else { + if (! is_array($keyFile)) { + $keyFile = []; + } + $options['keyFile'] = array_merge(["project_id" => $config['project_id']], $keyFile); + } } - return new StorageClient([ - 'projectId' => $config['project_id'], - 'keyFile' => array_merge(["project_id" => $config['project_id']], $keyFile) - ]); + + return new StorageClient($options); } /**