Built motion from commit 10af8726.|2.6.34
[motion2.git] / legacy-libs / gcp-metadata / README.md
1 # gcp-metadata
2 > Get the metadata from a Google Cloud Platform environment.
3
4 [![NPM Version][npm-image]][npm-url]
5 [![codecov][codecov-image]][codecov-url]
6
7 ```sh
8 $ npm install --save gcp-metadata
9 ```
10 ```js
11 const gcpMetadata = require('gcp-metadata');
12 ```
13
14 #### Check to see if the metadata server is available
15 ```js
16 const isAvailable = await gcpMetadata.isAvailable();
17 ```
18
19 #### Access all metadata
20 ```js
21 const data = await gcpMetadata.instance();
22 console.log(data); // ... All metadata properties
23 ```
24
25 #### Access specific properties
26 ```js
27 const data = await gcpMetadata.instance('hostname');
28 console.log(data) // ...Instance hostname
29 ```
30
31 #### Access specific properties with query parameters
32 ```js
33 const data = await gcpMetadata.instance({
34   property: 'tags',
35   params: { alt: 'text' }
36 });
37 console.log(data) // ...Tags as newline-delimited list
38 ```
39
40 #### Access with custom headers
41 ```js
42 await gcpMetadata.instance({
43   headers: { 'no-trace': '1' }
44 }); // ...Request is untraced
45 ```
46
47 ### Take care with large number valued properties
48
49 In some cases number valued properties returned by the Metadata Service may be
50 too large to be representable as JavaScript numbers. In such cases we return
51 those values as `BigNumber` objects (from the [bignumber.js][] library). Numbers
52 that fit within the JavaScript number range will be returned as normal number
53 values.
54
55 ```js
56 const id = await gcpMetadata.instance('id');
57 console.log(id)  // ... BigNumber { s: 1, e: 18, c: [ 45200, 31799277581759 ] }
58 console.log(id.toString()) // ... 4520031799277581759
59 ```
60
61 [bignumber.js]: https://github.com/MikeMcl/bignumber.js
62 [codecov-image]: https://codecov.io/gh/googleapis/gcp-metadata/branch/master/graph/badge.svg
63 [codecov-url]: https://codecov.io/gh/googleapis/gcp-metadata
64 [npm-image]: https://img.shields.io/npm/v/gcp-metadata.svg
65 [npm-url]: https://www.npmjs.com/package/gcp-metadata