in cloudrun-malware-scanner/gcs-proxy-server.ts [37:67]
async function accessTokenRefresh() {
if (accessTokenRefreshTimeout) {
clearTimeout(accessTokenRefreshTimeout);
accessTokenRefreshTimeout = null;
}
const client = await googleAuth.getClient();
if (
!client.credentials?.expiry_date ||
client.credentials.expiry_date <=
new Date().getTime() + TOKEN_REFRESH_THRESHOLD_MILLIS
) {
accessToken = await googleAuth.getAccessToken();
logger.info(
`Refreshed Access token; expires at ${new Date(
client.credentials.expiry_date!, // Non-null assertion is safe here due to the check above
).toISOString()}`,
);
}
const nextCheckDate = new Date(
client.credentials.expiry_date! - TOKEN_REFRESH_THRESHOLD_MILLIS, // Non-null assertion is safe here due to the check above
);
logger.debug(
`Next access token refresh check at ${nextCheckDate.toISOString()}`,
);
accessTokenRefreshTimeout = setTimeout(
// eslint-disable-next-line @typescript-eslint/no-misused-promises
accessTokenRefresh,
nextCheckDate.getTime() - new Date().getTime(),
);
}