Skip to content

Commit

Permalink
Merge pull request #142 from livecycle/gce-fix-default-credentials
Browse files Browse the repository at this point in the history
gce driver: fix running with default credentials
  • Loading branch information
Roy Razon authored Jul 25, 2023
2 parents da43437 + f0489c6 commit d0d9ec2
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/driver-gce/src/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'path'
import { IdempotencyStrategy, Storage } from '@google-cloud/storage'
import { VirtualFS } from '@preevy/core'
import stream from 'node:stream'
import { GoogleAuth } from 'google-gax'
import { DefaultTransporter } from 'google-auth-library'

export const defaultBucketName = (
Expand Down Expand Up @@ -33,25 +32,21 @@ export const parseUrl = (url: string) => {

const hasErrorCode = (e: unknown, code: unknown) => e && (e as { code: unknown }).code === code

const authClientWithRetry = () => {
const transporter = new DefaultTransporter()
transporter.configure({ retryConfig: { noResponseRetries: 3 } })
const authClient = new GoogleAuth()
authClient.transporter = transporter
return authClient
}

export const googleCloudStorageFs = async (url: string): Promise<VirtualFS> => {
const { bucket: bucketName, path: prefix, project } = parseUrl(url)

const storage = new Storage({
projectId: project,
authClient: authClientWithRetry(),
retryOptions: {
autoRetry: true,
idempotencyStrategy: IdempotencyStrategy.RetryAlways,
},
})

const transporter = new DefaultTransporter()
transporter.configure({ retryConfig: { noResponseRetries: 3 } })
storage.authClient.transporter = transporter

const bucket = await ensureBucketExists(storage, bucketName)

return {
Expand Down

0 comments on commit d0d9ec2

Please sign in to comment.