gcp-metadata
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -8,10 +8,2 @@ "use strict"; | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -45,45 +37,43 @@ const gaxios_1 = require("gaxios"); | ||
} | ||
function metadataAccessor(type, options, noResponseRetries = 3) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
options = options || {}; | ||
if (typeof options === 'string') { | ||
options = { property: options }; | ||
async function metadataAccessor(type, options, noResponseRetries = 3) { | ||
options = options || {}; | ||
if (typeof options === 'string') { | ||
options = { property: options }; | ||
} | ||
let property = ''; | ||
if (typeof options === 'object' && options.property) { | ||
property = '/' + options.property; | ||
} | ||
validate(options); | ||
try { | ||
const res = await gaxios_1.request({ | ||
url: `${exports.BASE_URL}/${type}${property}`, | ||
headers: Object.assign({}, exports.HEADERS, options.headers), | ||
retryConfig: { noResponseRetries }, | ||
params: options.params, | ||
responseType: 'text', | ||
}); | ||
// NOTE: node.js converts all incoming headers to lower case. | ||
if (res.headers[exports.HEADER_NAME.toLowerCase()] !== exports.HEADER_VALUE) { | ||
throw new Error(`Invalid response from metadata service: incorrect ${exports.HEADER_NAME} header.`); | ||
} | ||
let property = ''; | ||
if (typeof options === 'object' && options.property) { | ||
property = '/' + options.property; | ||
else if (!res.data) { | ||
throw new Error('Invalid response from the metadata service'); | ||
} | ||
validate(options); | ||
try { | ||
const res = yield gaxios_1.request({ | ||
url: `${exports.BASE_URL}/${type}${property}`, | ||
headers: Object.assign({}, exports.HEADERS, options.headers), | ||
retryConfig: { noResponseRetries }, | ||
params: options.params, | ||
responseType: 'text' | ||
}); | ||
// NOTE: node.js converts all incoming headers to lower case. | ||
if (res.headers[exports.HEADER_NAME.toLowerCase()] !== exports.HEADER_VALUE) { | ||
throw new Error(`Invalid response from metadata service: incorrect ${exports.HEADER_NAME} header.`); | ||
if (typeof res.data === 'string') { | ||
try { | ||
return jsonBigint.parse(res.data); | ||
} | ||
else if (!res.data) { | ||
throw new Error('Invalid response from the metadata service'); | ||
catch (_a) { | ||
/* ignore */ | ||
} | ||
if (typeof res.data === 'string') { | ||
try { | ||
return jsonBigint.parse(res.data); | ||
} | ||
catch (_a) { | ||
/* ignore */ | ||
} | ||
} | ||
return res.data; | ||
} | ||
catch (e) { | ||
if (e.response && e.response.status !== 200) { | ||
e.message = `Unsuccessful response status code. ${e.message}`; | ||
} | ||
throw e; | ||
return res.data; | ||
} | ||
catch (e) { | ||
if (e.response && e.response.status !== 200) { | ||
e.message = `Unsuccessful response status code. ${e.message}`; | ||
} | ||
}); | ||
throw e; | ||
} | ||
} | ||
@@ -103,22 +93,20 @@ // tslint:disable-next-line no-any | ||
*/ | ||
function isAvailable() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
// Attempt to read instance metadata. As configured, this will | ||
// retry 3 times if there is a valid response, and fail fast | ||
// if there is an ETIMEDOUT or ENOTFOUND error. | ||
yield metadataAccessor('instance', undefined, 0); | ||
return true; | ||
async function isAvailable() { | ||
try { | ||
// Attempt to read instance metadata. As configured, this will | ||
// retry 3 times if there is a valid response, and fail fast | ||
// if there is an ETIMEDOUT or ENOTFOUND error. | ||
await metadataAccessor('instance', undefined, 0); | ||
return true; | ||
} | ||
catch (err) { | ||
// Failure to resolve the metadata service means that it is not available. | ||
if (err.code && (err.code === 'ENOTFOUND' || err.code === 'ENOENT')) { | ||
return false; | ||
} | ||
catch (err) { | ||
// Failure to resolve the metadata service means that it is not available. | ||
if (err.code && (err.code === 'ENOTFOUND' || err.code === 'ENOENT')) { | ||
return false; | ||
} | ||
// Throw unexpected errors. | ||
throw err; | ||
} | ||
}); | ||
// Throw unexpected errors. | ||
throw err; | ||
} | ||
} | ||
exports.isAvailable = isAvailable; | ||
//# sourceMappingURL=index.js.map |
@@ -7,2 +7,19 @@ # Changelog | ||
## [2.0.0](https://www.github.com/googleapis/gcp-metadata/compare/v1.0.0...v2.0.0) (2019-05-07) | ||
### Bug Fixes | ||
* **deps:** update dependency gaxios to v2 ([#191](https://www.github.com/googleapis/gcp-metadata/issues/191)) ([ac8c1ef](https://www.github.com/googleapis/gcp-metadata/commit/ac8c1ef)) | ||
### Build System | ||
* upgrade engines field to >=8.10.0 ([#194](https://www.github.com/googleapis/gcp-metadata/issues/194)) ([97c23c8](https://www.github.com/googleapis/gcp-metadata/commit/97c23c8)) | ||
### BREAKING CHANGES | ||
* upgrade engines field to >=8.10.0 (#194) | ||
## v1.0.0 | ||
@@ -174,2 +191,1 @@ | ||
- chore(deps): update dependency gts to ^0.8.0 ([#65](https://github.com/googleapis/gcp-metadata/pull/65)) | ||
{ | ||
"name": "gcp-metadata", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Get the metadata from a Google Cloud Platform environment", | ||
@@ -13,16 +13,12 @@ "repository": "googleapis/gcp-metadata", | ||
"compile": "tsc -p .", | ||
"check": "gts check", | ||
"fix": "gts fix", | ||
"fix": "gts fix && eslint --fix '**/*.js'", | ||
"clean": "gts clean", | ||
"pretest-only": "npm run compile", | ||
"posttest": "npm run check", | ||
"pretest": "npm run compile", | ||
"prepare": "npm run compile", | ||
"test": "npm run test-only", | ||
"samples-test": "mocha samples/system-test", | ||
"samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../", | ||
"presystem-test": "npm run compile", | ||
"system-test": "mocha build/system-test --timeout 600000", | ||
"test-only": "nyc mocha build/test", | ||
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json", | ||
"test": "nyc mocha build/test", | ||
"docs": "compodoc src/", | ||
"lint": "npm run check", | ||
"lint": "gts check && eslint '**/*.js'", | ||
"docs-test": "linkinator docs -r --skip www.googleapis.com", | ||
@@ -43,3 +39,3 @@ "predocs-test": "npm run docs" | ||
"dependencies": { | ||
"gaxios": "^1.0.2", | ||
"gaxios": "^2.0.0", | ||
"json-bigint": "^0.3.0" | ||
@@ -52,27 +48,31 @@ }, | ||
"@types/ncp": "^2.0.1", | ||
"@types/nock": "^9.1.3", | ||
"@types/nock": "^10.0.0", | ||
"@types/node": "^10.1.0", | ||
"@types/node-fetch": "^2.1.4", | ||
"@types/tmp": "0.0.34", | ||
"@types/tmp": "0.1.0", | ||
"@types/uuid": "^3.4.4", | ||
"assert-rejects": "^1.0.0", | ||
"codecov": "^3.0.2", | ||
"execa": "^1.0.0", | ||
"gcx": "^0.1.1", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.1.0", | ||
"eslint-plugin-node": "^9.0.0", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"gcbuild": "^1.1.1", | ||
"googleapis": "^37.0.0", | ||
"gts": "^0.9.0", | ||
"mocha": "^5.2.0", | ||
"gcx": "^0.2.0", | ||
"googleapis": "^39.0.0", | ||
"gts": "^1.0.0", | ||
"linkinator": "^1.1.2", | ||
"mocha": "^6.0.0", | ||
"ncp": "^2.0.0", | ||
"nock": "^10.0.0", | ||
"node-fetch": "^2.3.0", | ||
"nyc": "^13.0.0", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.16.4", | ||
"source-map-support": "^0.5.6", | ||
"typescript": "^3.0.0", | ||
"uuid": "^3.3.2", | ||
"linkinator": "^1.1.2" | ||
"uuid": "^3.3.2" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8.10.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34883
29
137
1
+ Addedagent-base@6.0.2(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedgaxios@2.3.4(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedis-stream@2.0.1(transitive)
- Removedagent-base@4.3.0(transitive)
- Removeddebug@3.2.7(transitive)
- Removedes6-promise@4.2.8(transitive)
- Removedes6-promisify@5.0.0(transitive)
- Removedgaxios@1.8.4(transitive)
- Removedhttps-proxy-agent@2.2.4(transitive)
Updatedgaxios@^2.0.0