CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
README.md236 linesDownload Raw Back to gcp-metadata
1[//]: # "This README.md file is auto-generated, all changes to this file will be lost."2[//]: # "To regenerate it, use `python -m synthtool`."3<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>4 5# [GCP Metadata: Node.js Client](https://github.com/googleapis/gcp-metadata)6 7[![release level](https://img.shields.io/badge/release%20level-stable-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages)8[![npm version](https://img.shields.io/npm/v/gcp-metadata.svg)](https://www.npmjs.com/package/gcp-metadata)9 10 11 12 13Get the metadata from a Google Cloud Platform environment14 15 16A comprehensive list of changes in each version may be found in17[the CHANGELOG](https://github.com/googleapis/gcp-metadata/blob/main/CHANGELOG.md).18 19* [GCP Metadata Node.js Client API Reference][client-docs]20* [GCP Metadata Documentation][product-docs]21* [github.com/googleapis/gcp-metadata](https://github.com/googleapis/gcp-metadata)22 23Read more about the client libraries for Cloud APIs, including the older24Google APIs Client Libraries, in [Client Libraries Explained][explained].25 26[explained]: https://cloud.google.com/apis/docs/client-libraries-explained27 28**Table of contents:**29 30 31* [Quickstart](#quickstart)32 33  * [Installing the client library](#installing-the-client-library)34  * [Using the client library](#using-the-client-library)35* [Samples](#samples)36* [Versioning](#versioning)37* [Contributing](#contributing)38* [License](#license)39 40## Quickstart41 42### Installing the client library43 44```bash45npm install gcp-metadata46```47 48 49### Using the client library50 51```javascript52const gcpMetadata = require('gcp-metadata');53 54async function quickstart() {55  // check to see if this code can access a metadata server56  const isAvailable = await gcpMetadata.isAvailable();57  console.log(`Is available: ${isAvailable}`);58 59  // Instance and Project level metadata will only be available if60  // running inside of a Google Cloud compute environment such as61  // Cloud Functions, App Engine, Kubernetes Engine, or Compute Engine.62  // To learn more about the differences between instance and project63  // level metadata, see:64  // https://cloud.google.com/compute/docs/storing-retrieving-metadata#project-instance-metadata65  if (isAvailable) {66    // grab all top level metadata from the service67    const instanceMetadata = await gcpMetadata.instance();68    console.log('Instance metadata:');69    console.log(instanceMetadata);70 71    // get all project level metadata72    const projectMetadata = await gcpMetadata.project();73    console.log('Project metadata:');74    console.log(projectMetadata);75  }76}77 78quickstart();79 80```81 82#### Check to see if the metadata server is available83```js84const isAvailable = await gcpMetadata.isAvailable();85```86 87#### Access all metadata88 89```js90const data = await gcpMetadata.instance();91console.log(data); // ... All metadata properties92```93 94#### Access specific properties95```js96const data = await gcpMetadata.instance('hostname');97console.log(data); // ...Instance hostname98const projectId = await gcpMetadata.project('project-id');99console.log(projectId); // ...Project ID of the running instance100```101 102#### Access nested properties with the relative path103```js104const data = await gcpMetadata.instance('service-accounts/default/email');105console.log(data); // ...Email address of the Compute identity service account106```107 108#### Access specific properties with query parameters109```js110const data = await gcpMetadata.instance({111  property: 'tags',112  params: { alt: 'text' }113});114console.log(data) // ...Tags as newline-delimited list115```116 117#### Access with custom headers118```js119await gcpMetadata.instance({120  headers: { 'no-trace': '1' }121}); // ...Request is untraced122```123 124### Take care with large number valued properties125 126In some cases number valued properties returned by the Metadata Service may be127too large to be representable as JavaScript numbers. In such cases we return128those values as `BigNumber` objects (from the [bignumber.js](https://github.com/MikeMcl/bignumber.js) library). Numbers129that fit within the JavaScript number range will be returned as normal number130values.131 132```js133const id = await gcpMetadata.instance('id');134console.log(id)  // ... BigNumber { s: 1, e: 18, c: [ 45200, 31799277581759 ] }135console.log(id.toString()) // ... 4520031799277581759136```137 138### Environment variables139 140* `GCE_METADATA_HOST`: provide an alternate host or IP to perform lookup against (useful, for example, you're connecting through a custom proxy server).141 142  For example:143  ```144  export GCE_METADATA_HOST='169.254.169.254'145  ```146 147* `DETECT_GCP_RETRIES`: number representing number of retries that should be attempted on metadata lookup.148 149* `DEBUG_AUTH`: emit debugging logs150 151* `METADATA_SERVER_DETECTION`: configure desired metadata server availability check behavior.152 153  * `assume-present`: don't try to ping the metadata server, but assume it's present154  * `none`: don't try to ping the metadata server, but don't try to use it either155  * `bios-only`: treat the result of a BIOS probe as canonical (don't fall back to pinging)156  * `ping-only`: skip the BIOS probe, and go straight to pinging157 158 159## Samples160 161Samples are in the [`samples/`](https://github.com/googleapis/gcp-metadata/tree/main/samples) directory. Each sample's `README.md` has instructions for running its sample.162 163| Sample                      | Source Code                       | Try it |164| --------------------------- | --------------------------------- | ------ |165| Quickstart | [source code](https://github.com/googleapis/gcp-metadata/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/gcp-metadata&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |166 167 168 169The [GCP Metadata Node.js Client API Reference][client-docs] documentation170also contains samples.171 172## Supported Node.js Versions173 174Our client libraries follow the [Node.js release schedule](https://github.com/nodejs/release#release-schedule).175Libraries are compatible with all current _active_ and _maintenance_ versions of176Node.js.177If you are using an end-of-life version of Node.js, we recommend that you update178as soon as possible to an actively supported LTS version.179 180Google's client libraries support legacy versions of Node.js runtimes on a181best-efforts basis with the following warnings:182 183* Legacy versions are not tested in continuous integration.184* Some security patches and features cannot be backported.185* Dependencies cannot be kept up-to-date.186 187Client libraries targeting some end-of-life versions of Node.js are available, and188can be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).189The dist-tags follow the naming convention `legacy-(version)`.190For example, `npm install gcp-metadata@legacy-8` installs client libraries191for versions compatible with Node.js 8.192 193## Versioning194 195This library follows [Semantic Versioning](http://semver.org/).196 197 198 199This library is considered to be **stable**. The code surface will not change in backwards-incompatible ways200unless absolutely necessary (e.g. because of critical security issues) or with201an extensive deprecation period. Issues and requests against **stable** libraries202are addressed with the highest priority.203 204 205 206 207 208 209More Information: [Google Cloud Platform Launch Stages][launch_stages]210 211[launch_stages]: https://cloud.google.com/terms/launch-stages212 213## Contributing214 215Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/gcp-metadata/blob/main/CONTRIBUTING.md).216 217Please note that this `README.md`, the `samples/README.md`,218and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`)219are generated from a central template. To edit one of these files, make an edit220to its templates in221[directory](https://github.com/googleapis/synthtool).222 223## License224 225Apache Version 2.0226 227See [LICENSE](https://github.com/googleapis/gcp-metadata/blob/main/LICENSE)228 229[client-docs]: https://cloud.google.com/nodejs/docs/reference/gcp-metadata/latest230[product-docs]: https://cloud.google.com/compute/docs/storing-retrieving-metadata231[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png232[projects]: https://console.cloud.google.com/project233[billing]: https://support.google.com/cloud/answer/6293499#enable-billing234 235[auth]: https://cloud.google.com/docs/authentication/external/set-up-adc-local236 
basant307/AI_Governance_Project · CoolFace