Skip to content

Commit

Permalink
gce driver: fix running with default credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Jul 25, 2023
1 parent 2e2aaaa commit 0d3cf1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/npm-publish-canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ on:
jobs:
publish-packages:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.owner.name == 'livecycle'
# if: github.event.pull_request.head.repo.owner.name == 'livecycle'

steps:
- uses: actions/checkout@v3

- uses: crazy-max/ghaction-dump-context@v2

- uses: actions/setup-node@v3
with:
node-version: '18.x'
Expand Down
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 0d3cf1d

Please sign in to comment.