Skip to content

Commit

Permalink
fix: cache tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
rayriffy committed Jun 20, 2024
1 parent 84500a0 commit 2d5c88d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/backend/gardenGate/getServiceAccountIdToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export const getServiceAccountIdToken = async (
audience: string,
credentialPath: string
) => {
const cachedToken = await readFileSystem<string>(['googleIdToken', audience])
const cachedToken = await readFileSystem<string>([
'googleIdToken',
audience,
credentialPath,
])

if (cachedToken !== null) return cachedToken.data

Expand All @@ -18,7 +22,11 @@ export const getServiceAccountIdToken = async (
// each token has a lifespan of 1 hour
const token = await client.fetchIdToken(audience)

// allow caching token for 30 minutes, preventing spaming to google cloud
await writeFileSystem(['googleIdToken', audience], token, 30 * 60 * 1000)
// allow caching token for 30 minutes, preventing spamming to google cloud
await writeFileSystem(
['googleIdToken', audience, credentialPath],
token,
30 * 60 * 1000
)
return token
}

0 comments on commit 2d5c88d

Please sign in to comment.