Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gcp-metadata

Package Overview
Dependencies
Maintainers
13
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gcp-metadata - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

index.d.ts

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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc