Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Copyright 2018 Google LLC
*
* Distributed under MIT license.
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
import * as gcp from 'gcp-metadata';
// uncomment the line below during development
//import * as gcp from '../../../../build/src/index';
const header = gcp.HEADER_NAME;
const headers = gcp.HEADERS;
async function main() {
const v = await gcp.instance('/somepath');
}
gcp.project('something').then(console.log);
main().catch(console.error);
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
url = this.tokenUrl ||
"" + gcpMetadata.HOST_ADDRESS + Compute._GOOGLE_OAUTH2_TOKEN_URL;
res = null;
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, ax.request({
url: url,
headers: (_a = {}, _a[gcpMetadata.HEADER_NAME] = 'Google', _a),
raxConfig: { noResponseRetries: 3, retry: 3, instance: ax }
})];
case 2:
// TODO: In 2.0, we should remove the ability to configure the tokenUrl,
// and switch this over to use the gcp-metadata package instead.
res = _b.sent();
return [3 /*break*/, 4];
case 3:
e_1 = _b.sent();
e_1.message = 'Could not refresh access token.';
throw e_1;
case 4:
tokens = res.data;
if (res.data && res.data.expires_in) {
tokens.expiry_date =
((new Date()).getTime() + (res.data.expires_in * 1000));