Skip to content

Commit 956e438

Browse files
committed
Update To Use JSON as an ENV variable
Updated module so ENV variable will house the JSON file so the JSON service credentials do not need to be uploaded to your repository.
1 parent d244d47 commit 956e438

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ This was initially based off of https://github.com/silverstripe/silverstripe-s3
1111

1212
The module requires a few environment variables to be set. These are mandatory.
1313

14-
* `GC_PROJECT_ID`: Your google project id
14+
* `GC_KEY_FILE`: JSON of your google service account json file
1515
* `GC_BUCKET_NAME`: The name of the cloud storage bucket bucket to store assets in.
1616

17-
If running outside of google app engine or cloud compute, you need to setup your user credentials by placing a service account key json file in the root of your site. This service account key will need access to Google Cloud Storage JSON API. Once the service account key is in the root of your site, simply add an environment variable of GOOGLE_APPLICATION_CREDENTIALS, example -
1817

19-
* `GOOGLE_APPLICATION_CREDENTIALS`: 'service-account.json'
18+
For the GC_KEY_FILE environment variable, simply copy all contents into one line and place in your .env file like -
2019

20+
GOOGLE_KEY_FILE={"type": "service_account","project_id": ...
2121

2222
## Installation
2323

_config/assets.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
22
Name: silverstripegooglecloudstorage-flysystem
33
Only:
4-
envvarset: GC_BUCKET_NAME
4+
envvarset:
5+
- GC_BUCKET_NAME
6+
- GC_KEY_FILE
57
After:
68
- '#assetsflysystem'
79
---
810
SilverStripe\Core\Injector\Injector:
911
SilverStripe\GoogleCloudStorage\Adapter\BucketAdapter:
1012
constructor:
1113
bucket: '`GC_BUCKET_NAME`'
12-
projectId: '`GC_PROJECT_ID`'
13-
keyFilePath: '`GOOGLE_APPLICATION_CREDENTIALS`'
14+
keyFile: '`GC_KEY_FILE`'
1415

1516
League\Flysystem\Adapter\Local:
1617
class: League\Flysystem\Adapter\Local

src/Adapter/BucketAdapter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
class BucketAdapter {
88
protected $bucket;
99
protected $client;
10-
public function __construct($bucketname, $projectId, $keyFilePath){
10+
public function __construct($bucketname, $keyFile){
1111
$this->client = new StorageClient([
12-
'projectId'=>$projectId,
13-
'keyFilePath' => BASE_PATH.'/'.$keyFilePath
12+
'keyFile'=> json_decode($keyFile, true)
1413
]);
14+
15+
1516
$this->bucket = $this->client->bucket($bucketname);
1617
}
1718

0 commit comments

Comments
 (0)