Skip to content

Commit

Permalink
fix(deps): update to gcp-metadata and address envDetect performance i…
Browse files Browse the repository at this point in the history
…ssues (#787)

* fix(deps): update to gcp-metadata that does not throw locally

* chore: fix up tests

* chore: fix linting
  • Loading branch information
bcoe authored and JustinBeckwith committed Sep 17, 2019
1 parent e1d6718 commit 651b5d4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"base64-js": "^1.3.0",
"fast-text-encoding": "^1.0.0",
"gaxios": "^2.0.0",
"gcp-metadata": "^2.0.0",
"gcp-metadata": "^3.0.0",
"gtoken": "^4.0.0",
"jws": "^3.1.5",
"lru-cache": "^5.0.0"
Expand Down
8 changes: 5 additions & 3 deletions src/auth/envDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ export async function getEnv() {
env = GCPEnv.APP_ENGINE;
} else if (isCloudFunction()) {
env = GCPEnv.CLOUD_FUNCTIONS;
} else if (await isKubernetesEngine()) {
env = GCPEnv.KUBERNETES_ENGINE;
} else if (await isComputeEngine()) {
env = GCPEnv.COMPUTE_ENGINE;
if (await isKubernetesEngine()) {
env = GCPEnv.KUBERNETES_ENGINE;
} else {
env = GCPEnv.COMPUTE_ENGINE;
}
} else {
env = GCPEnv.NONE;
}
Expand Down
44 changes: 39 additions & 5 deletions test/test.googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const assertRejects = require('assert-rejects');
import * as child_process from 'child_process';
import * as crypto from 'crypto';
import * as fs from 'fs';
import {BASE_PATH, HEADERS, HOST_ADDRESS} from 'gcp-metadata';
import {
BASE_PATH,
HEADERS,
HOST_ADDRESS,
SECONDARY_HOST_ADDRESS,
} from 'gcp-metadata';
import * as nock from 'nock';
import * as os from 'os';
import * as path from 'path';
Expand Down Expand Up @@ -158,21 +163,50 @@ describe('googleauth', () => {
}

function nockIsGCE() {
return nock(host)
const primary = nock(host)
.get(instancePath)
.reply(200, {}, HEADERS);
const secondary = nock(SECONDARY_HOST_ADDRESS)
.get(instancePath)
.reply(200, {}, HEADERS);

return {
done: () => {
primary.done();
secondary.done();
},
};
}

function nockNotGCE() {
return nock(host)
const primary = nock(host)
.get(instancePath)
.replyWithError({code: 'ENOTFOUND'});
const secondary = nock(SECONDARY_HOST_ADDRESS)
.get(instancePath)
.replyWithError({code: 'ENOTFOUND'});
return {
done: () => {
primary.done();
secondary.done();
},
};
}

function nock500GCE() {
return nock(host)
const primary = nock(host)
.get(instancePath)
.reply(500, {}, HEADERS);
const secondary = nock(SECONDARY_HOST_ADDRESS)
.get(instancePath)
.reply(500);
.reply(500, {}, HEADERS);

return {
done: () => {
primary.done();
secondary.done();
},
};
}

function nock404GCE() {
Expand Down

0 comments on commit 651b5d4

Please sign in to comment.