From 1f7995cb6de7c6434894c7c3b3b505c545d5c4bf Mon Sep 17 00:00:00 2001 From: Luka Fontanilla Date: Wed, 6 Oct 2021 20:00:35 -0700 Subject: [PATCH] GC Storage updates. The GC storage node client has change it's import, additionally creating the client can be simplified by just passing the keyFilename. Updated the README.md as well as .env sample for GC storage setup. --- .env-sample | 3 +++ README.md | 2 ++ src/stores/google_cloud_store.ts | 10 ++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.env-sample b/.env-sample index c55fd29b..0d1eaa31 100644 --- a/.env-sample +++ b/.env-sample @@ -9,3 +9,6 @@ SLACKBOT_S3_BUCKET=my-bucket SLACKBOT_S3_BUCKET_REGION=us-east-1 AWS_ACCESS_KEY_ID=ABCDEFGHJKL AWS_SECRET_ACCESS_KEY=abcdefghjkl +GOOGLE_CLOUD_BUCKET=my-bucket-name +GOOGLE_CLOUD_PROJECT=my-project-id +GOOGLE_CLOUD_CREDENTIALS_JSON= diff --git a/README.md b/README.md index 5b30f851..0364f185 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,8 @@ There are a couple environment variables that can be used to tweak behavior: ###### Google Cloud Storage +Requires that the Cloud Storage Bucket isn't preventing public access and that `Access Control` is set to `Fine-Grained` and `Object-level ACLs enabled` is set. + - `GOOGLE_CLOUD_BUCKET` (optional) - If you want to use Google Cloud to store visualization images posted by Lookerbot, provide the name of your bucket. If Lookerbot is running on Google Compute Engine, [no further information should be needed if the approprate API scopes are set up](https://github.com/GoogleCloudPlatform/google-cloud-node#on-google-cloud-platform). diff --git a/src/stores/google_cloud_store.ts b/src/stores/google_cloud_store.ts index 8628c636..5a6e2599 100644 --- a/src/stores/google_cloud_store.ts +++ b/src/stores/google_cloud_store.ts @@ -2,7 +2,8 @@ import * as fs from "fs" import { ReadableStreamBuffer } from "stream-buffers" import { Store } from "./store" -const gcs = require("@google-cloud/storage") +// post v2.* nodejs cloud storage client requires the below import +const {Storage} = require("@google-cloud/storage") export class GoogleCloudStore extends Store { @@ -16,9 +17,10 @@ export class GoogleCloudStore extends Store { blobStream.put(buffer) blobStream.stop() - const storage = gcs({ - credentials: process.env.GOOGLE_CLOUD_CREDENTIALS_JSON ? JSON.parse(process.env.GOOGLE_CLOUD_CREDENTIALS_JSON) : undefined, - projectId: process.env.GOOGLE_CLOUD_PROJECT, + // updating due to v2.* nodejs client changes + const storage = new Storage({ + // if keyFilename is supplied, projectID is no longer required + keyFilename: process.env.GOOGLE_CLOUD_CREDENTIALS_JSON }) const bucketName = process.env.GOOGLE_CLOUD_BUCKET