GithubHelp home page GithubHelp logo

isabella232 / gcp-metadata Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googleapis/gcp-metadata

0.0 0.0 0.0 486 KB

Get the metadata from a Google Cloud Platform environment

License: Apache License 2.0

TypeScript 87.75% Python 0.92% JavaScript 11.33%

gcp-metadata's Introduction

gcp-metadata

Get the metadata from a Google Cloud Platform environment.

NPM Version codecov

$ npm install --save gcp-metadata
const gcpMetadata = require('gcp-metadata');

Check to see if the metadata server is available

const isAvailable = await gcpMetadata.isAvailable();

Access all metadata

const data = await gcpMetadata.instance();
console.log(data); // ... All metadata properties

Access specific properties

const data = await gcpMetadata.instance('hostname');
console.log(data); // ...Instance hostname
const projectId = await gcpMetadata.project('project-id');
console.log(projectId); // ...Project ID of the running instance

Access nested properties with the relative path

const data = await gcpMetadata.instance('service-accounts/default/email');
console.log(data); // ...Email address of the Compute identity service account

Access specific properties with query parameters

const data = await gcpMetadata.instance({
  property: 'tags',
  params: { alt: 'text' }
});
console.log(data) // ...Tags as newline-delimited list

Access with custom headers

await gcpMetadata.instance({
  headers: { 'no-trace': '1' }
}); // ...Request is untraced

Take care with large number valued properties

In some cases number valued properties returned by the Metadata Service may be too large to be representable as JavaScript numbers. In such cases we return those values as BigNumber objects (from the bignumber.js library). Numbers that fit within the JavaScript number range will be returned as normal number values.

const id = await gcpMetadata.instance('id');
console.log(id)  // ... BigNumber { s: 1, e: 18, c: [ 45200, 31799277581759 ] }
console.log(id.toString()) // ... 4520031799277581759

Environment variables

  • GCE_METADATA_HOST: provide an alternate host or IP to perform lookup against (useful, for example, you're connecting through a custom proxy server).

For example:

export GCE_METADATA_HOST = '169.254.169.254'
  • DETECT_GCP_RETRIES: number representing number of retries that should be attempted on metadata lookup.

gcp-metadata's People

Contributors

alexander-fenster avatar bcoe avatar bojeil-google avatar callmehiphop avatar crwilcox avatar dpebot avatar fhinkel avatar gcf-merge-on-green[bot] avatar grayside avatar jkwlui avatar justinbeckwith avatar kjin avatar loganhasson avatar nolanmar511 avatar ofrobots avatar palmchou avatar release-please[bot] avatar renovate-bot avatar renovate[bot] avatar simenb avatar sofisl avatar stephenplusplus avatar summer-ji-eng avatar wascloud avatar yoshi-automation avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.