gcp-metadata
Advanced tools
Comparing version 4.2.1 to 4.3.0
@@ -24,4 +24,13 @@ /** | ||
} | ||
/** | ||
* Obtain metadata for the current GCE instance | ||
*/ | ||
export declare function instance<T = any>(options?: string | Options): Promise<T>; | ||
/** | ||
* Obtain metadata for the current GCP Project. | ||
*/ | ||
export declare function project<T = any>(options?: string | Options): Promise<T>; | ||
/** | ||
* Determine if the metadata server is currently available. | ||
*/ | ||
export declare function isAvailable(): Promise<boolean>; | ||
@@ -32,2 +41,5 @@ /** | ||
export declare function resetIsAvailableCache(): void; | ||
/** | ||
* Obtain the timeout for requests to the metadata server. | ||
*/ | ||
export declare function requestTimeout(): number; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const gaxios_1 = require("gaxios"); | ||
const jsonBigint = require('json-bigint'); // eslint-disable-line | ||
const jsonBigint = require("json-bigint"); | ||
exports.BASE_PATH = '/computeMetadata/v1'; | ||
@@ -152,2 +152,5 @@ exports.HOST_ADDRESS = 'http://169.254.169.254'; | ||
} | ||
/** | ||
* Obtain metadata for the current GCE instance | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -158,2 +161,5 @@ function instance(options) { | ||
exports.instance = instance; | ||
/** | ||
* Obtain metadata for the current GCP Project. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -172,6 +178,6 @@ function project(options) { | ||
} | ||
let cachedIsAvailableResponse; | ||
/** | ||
* Determine if the metadata server is currently available. | ||
*/ | ||
let cachedIsAvailableResponse; | ||
async function isAvailable() { | ||
@@ -236,2 +242,5 @@ try { | ||
exports.resetIsAvailableCache = resetIsAvailableCache; | ||
/** | ||
* Obtain the timeout for requests to the metadata server. | ||
*/ | ||
function requestTimeout() { | ||
@@ -238,0 +247,0 @@ // In testing, we were able to reproduce behavior similar to |
@@ -7,2 +7,9 @@ # Changelog | ||
## [4.3.0](https://www.github.com/googleapis/gcp-metadata/compare/v4.2.1...v4.3.0) (2021-06-10) | ||
### Features | ||
* add `gcf-owl-bot[bot]` to `ignoreAuthors` ([#450](https://www.github.com/googleapis/gcp-metadata/issues/450)) ([6a0f9ad](https://www.github.com/googleapis/gcp-metadata/commit/6a0f9ad09b6d16370d08c5d60541ce3ef64a9f97)) | ||
### [4.2.1](https://www.github.com/googleapis/gcp-metadata/compare/v4.2.0...v4.2.1) (2020-10-29) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "gcp-metadata", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "Get the metadata from a Google Cloud Platform environment", | ||
@@ -12,3 +12,3 @@ "repository": "googleapis/gcp-metadata", | ||
"scripts": { | ||
"compile": "tsc -p .", | ||
"compile": "cross-env NODE_OPTIONS=--max-old-space-size=8192 tsc -p .", | ||
"fix": "gts fix", | ||
@@ -48,13 +48,15 @@ "pretest": "npm run compile", | ||
"@compodoc/compodoc": "^1.1.10", | ||
"@google-cloud/functions": "^1.1.4", | ||
"@microsoft/api-documenter": "^7.8.10", | ||
"@microsoft/api-extractor": "^7.8.10", | ||
"@types/json-bigint": "^1.0.0", | ||
"@types/mocha": "^8.0.0", | ||
"@types/ncp": "^2.0.1", | ||
"@types/nock": "^10.0.3", | ||
"@types/node": "^12.7.2", | ||
"@types/node": "^14.0.0", | ||
"@types/tmp": "0.2.0", | ||
"@types/uuid": "^8.0.0", | ||
"c8": "^7.0.0", | ||
"codecov": "^3.5.0", | ||
"cross-env": "^7.0.3", | ||
"gcbuild": "^1.3.4", | ||
"gcx": "^1.0.0", | ||
"googleapis": "^61.0.0", | ||
"gts": "^3.0.0", | ||
@@ -67,5 +69,3 @@ "linkinator": "^2.0.0", | ||
"typescript": "^3.8.3", | ||
"uuid": "^8.0.0", | ||
"@microsoft/api-documenter": "^7.8.10", | ||
"@microsoft/api-extractor": "^7.8.10" | ||
"uuid": "^8.0.0" | ||
}, | ||
@@ -72,0 +72,0 @@ "engines": { |
172
README.md
@@ -1,12 +0,81 @@ | ||
# gcp-metadata | ||
> Get the metadata from a Google Cloud Platform environment. | ||
[//]: # "This README.md file is auto-generated, all changes to this file will be lost." | ||
[//]: # "To regenerate it, use `python -m synthtool`." | ||
<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"/> | ||
[![NPM Version][npm-image]][npm-url] | ||
[![codecov][codecov-image]][codecov-url] | ||
# [GCP Metadata: Node.js Client](https://github.com/googleapis/gcp-metadata) | ||
```sh | ||
$ npm install --save gcp-metadata | ||
[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages) | ||
[![npm version](https://img.shields.io/npm/v/gcp-metadata.svg)](https://www.npmjs.org/package/gcp-metadata) | ||
[![codecov](https://img.shields.io/codecov/c/github/googleapis/gcp-metadata/master.svg?style=flat)](https://codecov.io/gh/googleapis/gcp-metadata) | ||
Get the metadata from a Google Cloud Platform environment | ||
A comprehensive list of changes in each version may be found in | ||
[the CHANGELOG](https://github.com/googleapis/gcp-metadata/blob/master/CHANGELOG.md). | ||
* [GCP Metadata Node.js Client API Reference][client-docs] | ||
* [GCP Metadata Documentation][product-docs] | ||
* [github.com/googleapis/gcp-metadata](https://github.com/googleapis/gcp-metadata) | ||
Read more about the client libraries for Cloud APIs, including the older | ||
Google APIs Client Libraries, in [Client Libraries Explained][explained]. | ||
[explained]: https://cloud.google.com/apis/docs/client-libraries-explained | ||
**Table of contents:** | ||
* [Quickstart](#quickstart) | ||
* [Installing the client library](#installing-the-client-library) | ||
* [Using the client library](#using-the-client-library) | ||
* [Samples](#samples) | ||
* [Versioning](#versioning) | ||
* [Contributing](#contributing) | ||
* [License](#license) | ||
## Quickstart | ||
### Installing the client library | ||
```bash | ||
npm install gcp-metadata | ||
``` | ||
```js | ||
### Using the client library | ||
```javascript | ||
const gcpMetadata = require('gcp-metadata'); | ||
async function quickstart() { | ||
// check to see if this code can access a metadata server | ||
const isAvailable = await gcpMetadata.isAvailable(); | ||
console.log(`Is available: ${isAvailable}`); | ||
// Instance and Project level metadata will only be available if | ||
// running inside of a Google Cloud compute environment such as | ||
// Cloud Functions, App Engine, Kubernetes Engine, or Compute Engine. | ||
// To learn more about the differences between instance and project | ||
// level metadata, see: | ||
// https://cloud.google.com/compute/docs/storing-retrieving-metadata#project-instance-metadata | ||
if (isAvailable) { | ||
// grab all top level metadata from the service | ||
const instanceMetadata = await gcpMetadata.instance(); | ||
console.log('Instance metadata:'); | ||
console.log(instanceMetadata); | ||
// get all project level metadata | ||
const projectMetadata = await gcpMetadata.project(); | ||
console.log('Project metadata:'); | ||
console.log(projectMetadata); | ||
} | ||
} | ||
quickstart(); | ||
``` | ||
@@ -20,2 +89,3 @@ | ||
#### Access all metadata | ||
```js | ||
@@ -60,3 +130,3 @@ const data = await gcpMetadata.instance(); | ||
too large to be representable as JavaScript numbers. In such cases we return | ||
those values as `BigNumber` objects (from the [bignumber.js][] library). Numbers | ||
those values as `BigNumber` objects (from the [bignumber.js](https://github.com/MikeMcl/bignumber.js) library). Numbers | ||
that fit within the JavaScript number range will be returned as normal number | ||
@@ -71,8 +141,2 @@ values. | ||
[bignumber.js]: https://github.com/MikeMcl/bignumber.js | ||
[codecov-image]: https://codecov.io/gh/googleapis/gcp-metadata/branch/master/graph/badge.svg | ||
[codecov-url]: https://codecov.io/gh/googleapis/gcp-metadata | ||
[npm-image]: https://img.shields.io/npm/v/gcp-metadata.svg | ||
[npm-url]: https://www.npmjs.com/package/gcp-metadata | ||
### Environment variables | ||
@@ -87,2 +151,80 @@ | ||
* DETECT_GCP_RETRIES: number representing number of retries that should be attempted on metadata lookup. | ||
* DETECT_GCP_RETRIES: number representing number of retries that should be attempted on metadata lookup. | ||
## Samples | ||
Samples are in the [`samples/`](https://github.com/googleapis/gcp-metadata/tree/master/samples) directory. Each sample's `README.md` has instructions for running its sample. | ||
| Sample | Source Code | Try it | | ||
| --------------------------- | --------------------------------- | ------ | | ||
| Quickstart | [source code](https://github.com/googleapis/gcp-metadata/blob/master/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) | | ||
The [GCP Metadata Node.js Client API Reference][client-docs] documentation | ||
also contains samples. | ||
## Supported Node.js Versions | ||
Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/). | ||
Libraries are compatible with all current _active_ and _maintenance_ versions of | ||
Node.js. | ||
Client libraries targeting some end-of-life versions of Node.js are available, and | ||
can be installed via npm [dist-tags](https://docs.npmjs.com/cli/dist-tag). | ||
The dist-tags follow the naming convention `legacy-(version)`. | ||
_Legacy Node.js versions are supported as a best effort:_ | ||
* Legacy versions will not be tested in continuous integration. | ||
* Some security patches may not be able to be backported. | ||
* Dependencies will not be kept up-to-date, and features will not be backported. | ||
#### Legacy tags available | ||
* `legacy-8`: install client libraries from this dist-tag for versions | ||
compatible with Node.js 8. | ||
## Versioning | ||
This library follows [Semantic Versioning](http://semver.org/). | ||
This library is considered to be **General Availability (GA)**. This means it | ||
is stable; the code surface will not change in backwards-incompatible ways | ||
unless absolutely necessary (e.g. because of critical security issues) or with | ||
an extensive deprecation period. Issues and requests against **GA** libraries | ||
are addressed with the highest priority. | ||
More Information: [Google Cloud Platform Launch Stages][launch_stages] | ||
[launch_stages]: https://cloud.google.com/terms/launch-stages | ||
## Contributing | ||
Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/gcp-metadata/blob/master/CONTRIBUTING.md). | ||
Please note that this `README.md`, the `samples/README.md`, | ||
and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`) | ||
are generated from a central template. To edit one of these files, make an edit | ||
to its template in this | ||
[directory](https://github.com/googleapis/synthtool/tree/master/synthtool/gcp/templates/node_library). | ||
## License | ||
Apache Version 2.0 | ||
See [LICENSE](https://github.com/googleapis/gcp-metadata/blob/master/LICENSE) | ||
[client-docs]: https://googleapis.dev/nodejs/gcp-metadata/latest | ||
[product-docs]: https://cloud.google.com/compute/docs/storing-retrieving-metadata | ||
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png | ||
[projects]: https://console.cloud.google.com/project | ||
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing | ||
[auth]: https://cloud.google.com/docs/authentication/getting-started |
Sorry, the diff of this file is not supported yet
59580
297
227