gcp-metadata
Advanced tools
Comparing version 0.3.1 to 0.4.0
88
index.js
@@ -1,49 +0,45 @@ | ||
'use strict' | ||
var extend = require('extend') | ||
var request = require('retry-request') | ||
var BASE_URL = 'http://metadata.google.internal/computeMetadata/v1' | ||
var gcpMetadata = { | ||
_buildMetadataAccessor: function (type) { | ||
return function (options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options | ||
options = {} | ||
} | ||
if (typeof options === 'string') { | ||
options = { | ||
property: options | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var extend = require("extend"); | ||
var request = require("retry-request"); | ||
var BASE_URL = 'http://metadata.google.internal/computeMetadata/v1'; | ||
function _buildMetadataAccessor(type) { | ||
return function metadataAccessor(options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
} | ||
var property = options.property ? '/' + options.property : '' | ||
var reqOpts = extend(true, { | ||
uri: BASE_URL + '/' + type + property, | ||
headers: { 'Metadata-Flavor': 'Google' } | ||
}, options) | ||
delete reqOpts.property | ||
return request(reqOpts, function (err, res, body) { | ||
if (err) { | ||
callback(err) | ||
} else if (!res) { | ||
callback(new Error('Invalid response from metadata service')) | ||
} else if (res.statusCode !== 200) { | ||
callback(new Error('Unsuccessful response status code'), res) | ||
} else { | ||
callback(null, res, body) | ||
if (typeof options === 'string') { | ||
options = { property: options }; | ||
} | ||
}) | ||
} | ||
} | ||
var property = ''; | ||
if (typeof options === 'object' && options.property) { | ||
property = '/' + options.property; | ||
} | ||
var reqOpts = extend(true, { | ||
uri: BASE_URL + '/' + type + property, | ||
headers: { 'Metadata-Flavor': 'Google' } | ||
}, options); | ||
delete reqOpts.property; | ||
var retryRequestOpts = { noResponseRetries: 0 }; | ||
return request(reqOpts, retryRequestOpts, function (err, res, body) { | ||
if (callback) { | ||
if (err) { | ||
callback(err); | ||
} | ||
else if (!res) { | ||
callback(new Error('Invalid response from metadata service')); | ||
} | ||
else if (res.statusCode !== 200) { | ||
callback(new Error('Unsuccessful response status code'), res); | ||
} | ||
else { | ||
callback(null, res, body); | ||
} | ||
} | ||
}); | ||
}; | ||
} | ||
gcpMetadata.instance = gcpMetadata._buildMetadataAccessor('instance') | ||
gcpMetadata.project = gcpMetadata._buildMetadataAccessor('project') | ||
module.exports = gcpMetadata | ||
exports._buildMetadataAccessor = _buildMetadataAccessor; | ||
exports.instance = _buildMetadataAccessor('instance'); | ||
exports.project = _buildMetadataAccessor('project'); |
{ | ||
"name": "gcp-metadata", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Get the metadata from a Google Cloud Platform environment", | ||
@@ -8,6 +8,13 @@ "repository": "stephenplusplus/gcp-metadata", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"test": "standard && mocha *.test.js" | ||
"compile": "tsc -p .", | ||
"check": "gts check", | ||
"fix": "gts fix", | ||
"clean": "rm index.js index.d.ts", | ||
"prepare": "npm run compile", | ||
"test": "npm run check && npm run compile && mocha *.test.js" | ||
}, | ||
@@ -27,8 +34,15 @@ "keywords": [ | ||
"extend": "^3.0.0", | ||
"retry-request": "^3.0.0" | ||
"retry-request": "^3.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/extend": "^3.0.0", | ||
"@types/mocha": "^2.2.43", | ||
"@types/node": "^8.0.31", | ||
"@types/proxyquire": "^1.3.28", | ||
"@types/request": "^2.0.3", | ||
"clang-format": "^1.1.0", | ||
"gts": "^0.3.1", | ||
"mocha": "^3.2.0", | ||
"proxyquire": "^1.7.10", | ||
"standard": "^8.6.0" | ||
"typescript": "^2.5.3" | ||
}, | ||
@@ -35,0 +49,0 @@ "engines": { |
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
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
5502
5
61
10
Updatedretry-request@^3.1.0