Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/auth/envDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum GCPEnv {
CLOUD_FUNCTIONS = 'CLOUD_FUNCTIONS',
COMPUTE_ENGINE = 'COMPUTE_ENGINE',
CLOUD_RUN = 'CLOUD_RUN',
CLOUD_RUN_JOBS = 'CLOUD_RUN_JOBS',
NONE = 'NONE',
}

Expand Down Expand Up @@ -48,6 +49,8 @@ async function getEnvMemoized(): Promise<GCPEnv> {
env = GCPEnv.KUBERNETES_ENGINE;
} else if (isCloudRun()) {
env = GCPEnv.CLOUD_RUN;
} else if (isCloudRunJob()) {
env = GCPEnv.CLOUD_RUN_JOBS;
} else {
env = GCPEnv.COMPUTE_ENGINE;
}
Expand All @@ -74,6 +77,10 @@ function isCloudRun() {
return !!process.env.K_CONFIGURATION;
}

function isCloudRunJob() {
return !!process.env.CLOUD_RUN_JOB;
}

async function isKubernetesEngine() {
try {
await gcpMetadata.instance('attributes/cluster-name');
Expand Down
8 changes: 8 additions & 0 deletions test/test.googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,14 @@ describe('googleauth', () => {
assert.strictEqual(env, envDetect.GCPEnv.CLOUD_RUN);
});

it('should get the current environment if Cloud Run Jobs', async () => {
envDetect.clear();
mockEnvVar('CLOUD_RUN_JOB', 'KITTY');
const {auth} = mockGCE();
const env = await auth.getEnv();
assert.strictEqual(env, envDetect.GCPEnv.CLOUD_RUN_JOBS);
});

it('should make the request via `#fetch`', async () => {
const url = 'http://example.com';
const {auth, scopes} = mockGCE();
Expand Down
Loading