Proyecto audio control. inicado con panel y control.
This commit is contained in:
202
node_modules/gcp-metadata/LICENSE
generated
vendored
Normal file
202
node_modules/gcp-metadata/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
235
node_modules/gcp-metadata/README.md
generated
vendored
Normal file
235
node_modules/gcp-metadata/README.md
generated
vendored
Normal file
@@ -0,0 +1,235 @@
|
||||
[//]: # "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"/>
|
||||
|
||||
# [GCP Metadata: Node.js Client](https://github.com/googleapis/gcp-metadata)
|
||||
|
||||
[](https://cloud.google.com/terms/launch-stages)
|
||||
[](https://www.npmjs.com/package/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/main/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
|
||||
```
|
||||
|
||||
|
||||
### 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();
|
||||
|
||||
```
|
||||
|
||||
#### Check to see if the metadata server is available
|
||||
```js
|
||||
const isAvailable = await gcpMetadata.isAvailable();
|
||||
```
|
||||
|
||||
#### Access all metadata
|
||||
|
||||
```js
|
||||
const data = await gcpMetadata.instance();
|
||||
console.log(data); // ... All metadata properties
|
||||
```
|
||||
|
||||
#### Access specific properties
|
||||
```js
|
||||
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
|
||||
```js
|
||||
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
|
||||
```js
|
||||
const data = await gcpMetadata.instance({
|
||||
property: 'tags',
|
||||
params: { alt: 'text' }
|
||||
});
|
||||
console.log(data) // ...Tags as newline-delimited list
|
||||
```
|
||||
|
||||
#### Access with custom headers
|
||||
```js
|
||||
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](https://github.com/MikeMcl/bignumber.js) library). Numbers
|
||||
that fit within the JavaScript number range will be returned as normal number
|
||||
values.
|
||||
|
||||
```js
|
||||
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.
|
||||
|
||||
* `DEBUG_AUTH`: emit debugging logs
|
||||
|
||||
* `METADATA_SERVER_DETECTION`: configure desired metadata server availability check behavior.
|
||||
|
||||
* `assume-present`: don't try to ping the metadata server, but assume it's present
|
||||
* `none`: don't try to ping the metadata server, but don't try to use it either
|
||||
* `bios-only`: treat the result of a BIOS probe as canonical (don't fall back to pinging)
|
||||
* `ping-only`: skip the BIOS probe, and go straight to pinging
|
||||
|
||||
|
||||
## Samples
|
||||
|
||||
Samples 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.
|
||||
|
||||
| Sample | Source Code | Try it |
|
||||
| --------------------------- | --------------------------------- | ------ |
|
||||
| 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) |
|
||||
|
||||
|
||||
|
||||
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://github.com/nodejs/release#release-schedule).
|
||||
Libraries are compatible with all current _active_ and _maintenance_ versions of
|
||||
Node.js.
|
||||
If you are using an end-of-life version of Node.js, we recommend that you update
|
||||
as soon as possible to an actively supported LTS version.
|
||||
|
||||
Google's client libraries support legacy versions of Node.js runtimes on a
|
||||
best-efforts basis with the following warnings:
|
||||
|
||||
* Legacy versions are not tested in continuous integration.
|
||||
* Some security patches and features cannot be backported.
|
||||
* Dependencies cannot be kept up-to-date.
|
||||
|
||||
Client libraries targeting some end-of-life versions of Node.js are available, and
|
||||
can be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
|
||||
The dist-tags follow the naming convention `legacy-(version)`.
|
||||
For example, `npm install gcp-metadata@legacy-8` installs client libraries
|
||||
for versions compatible with Node.js 8.
|
||||
|
||||
## Versioning
|
||||
|
||||
This library follows [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
|
||||
This library is considered to be **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 **stable** 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/main/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 templates in
|
||||
[directory](https://github.com/googleapis/synthtool).
|
||||
|
||||
## License
|
||||
|
||||
Apache Version 2.0
|
||||
|
||||
See [LICENSE](https://github.com/googleapis/gcp-metadata/blob/main/LICENSE)
|
||||
|
||||
[client-docs]: https://cloud.google.com/nodejs/docs/reference/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/external/set-up-adc-local
|
||||
57
node_modules/gcp-metadata/build/src/gcp-residency.d.ts
generated
vendored
Normal file
57
node_modules/gcp-metadata/build/src/gcp-residency.d.ts
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Known paths unique to Google Compute Engine Linux instances
|
||||
*/
|
||||
export declare const GCE_LINUX_BIOS_PATHS: {
|
||||
BIOS_DATE: string;
|
||||
BIOS_VENDOR: string;
|
||||
};
|
||||
/**
|
||||
* Determines if the process is running on a Google Cloud Serverless environment (Cloud Run or Cloud Functions instance).
|
||||
*
|
||||
* Uses the:
|
||||
* - {@link https://cloud.google.com/run/docs/container-contract#env-vars Cloud Run environment variables}.
|
||||
* - {@link https://cloud.google.com/functions/docs/env-var Cloud Functions environment variables}.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCP serverless, `false` otherwise.
|
||||
*/
|
||||
export declare function isGoogleCloudServerless(): boolean;
|
||||
/**
|
||||
* Determines if the process is running on a Linux Google Compute Engine instance.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on Linux GCE, `false` otherwise.
|
||||
*/
|
||||
export declare function isGoogleComputeEngineLinux(): boolean;
|
||||
/**
|
||||
* Determines if the process is running on a Google Compute Engine instance with a known
|
||||
* MAC address.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCE (as determined by MAC address), `false` otherwise.
|
||||
*/
|
||||
export declare function isGoogleComputeEngineMACAddress(): boolean;
|
||||
/**
|
||||
* Determines if the process is running on a Google Compute Engine instance.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCE, `false` otherwise.
|
||||
*/
|
||||
export declare function isGoogleComputeEngine(): boolean;
|
||||
/**
|
||||
* Determines if the process is running on Google Cloud Platform.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCP, `false` otherwise.
|
||||
*/
|
||||
export declare function detectGCPResidency(): boolean;
|
||||
114
node_modules/gcp-metadata/build/src/gcp-residency.js
generated
vendored
Normal file
114
node_modules/gcp-metadata/build/src/gcp-residency.js
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GCE_LINUX_BIOS_PATHS = void 0;
|
||||
exports.isGoogleCloudServerless = isGoogleCloudServerless;
|
||||
exports.isGoogleComputeEngineLinux = isGoogleComputeEngineLinux;
|
||||
exports.isGoogleComputeEngineMACAddress = isGoogleComputeEngineMACAddress;
|
||||
exports.isGoogleComputeEngine = isGoogleComputeEngine;
|
||||
exports.detectGCPResidency = detectGCPResidency;
|
||||
const fs_1 = require("fs");
|
||||
const os_1 = require("os");
|
||||
/**
|
||||
* Known paths unique to Google Compute Engine Linux instances
|
||||
*/
|
||||
exports.GCE_LINUX_BIOS_PATHS = {
|
||||
BIOS_DATE: '/sys/class/dmi/id/bios_date',
|
||||
BIOS_VENDOR: '/sys/class/dmi/id/bios_vendor',
|
||||
};
|
||||
const GCE_MAC_ADDRESS_REGEX = /^42:01/;
|
||||
/**
|
||||
* Determines if the process is running on a Google Cloud Serverless environment (Cloud Run or Cloud Functions instance).
|
||||
*
|
||||
* Uses the:
|
||||
* - {@link https://cloud.google.com/run/docs/container-contract#env-vars Cloud Run environment variables}.
|
||||
* - {@link https://cloud.google.com/functions/docs/env-var Cloud Functions environment variables}.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCP serverless, `false` otherwise.
|
||||
*/
|
||||
function isGoogleCloudServerless() {
|
||||
/**
|
||||
* `CLOUD_RUN_JOB` is used for Cloud Run Jobs
|
||||
* - See {@link https://cloud.google.com/run/docs/container-contract#env-vars Cloud Run environment variables}.
|
||||
*
|
||||
* `FUNCTION_NAME` is used in older Cloud Functions environments:
|
||||
* - See {@link https://cloud.google.com/functions/docs/env-var Python 3.7 and Go 1.11}.
|
||||
*
|
||||
* `K_SERVICE` is used in Cloud Run and newer Cloud Functions environments:
|
||||
* - See {@link https://cloud.google.com/run/docs/container-contract#env-vars Cloud Run environment variables}.
|
||||
* - See {@link https://cloud.google.com/functions/docs/env-var Cloud Functions newer runtimes}.
|
||||
*/
|
||||
const isGFEnvironment = process.env.CLOUD_RUN_JOB ||
|
||||
process.env.FUNCTION_NAME ||
|
||||
process.env.K_SERVICE;
|
||||
return !!isGFEnvironment;
|
||||
}
|
||||
/**
|
||||
* Determines if the process is running on a Linux Google Compute Engine instance.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on Linux GCE, `false` otherwise.
|
||||
*/
|
||||
function isGoogleComputeEngineLinux() {
|
||||
if ((0, os_1.platform)() !== 'linux')
|
||||
return false;
|
||||
try {
|
||||
// ensure this file exist
|
||||
(0, fs_1.statSync)(exports.GCE_LINUX_BIOS_PATHS.BIOS_DATE);
|
||||
// ensure this file exist and matches
|
||||
const biosVendor = (0, fs_1.readFileSync)(exports.GCE_LINUX_BIOS_PATHS.BIOS_VENDOR, 'utf8');
|
||||
return /Google/.test(biosVendor);
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines if the process is running on a Google Compute Engine instance with a known
|
||||
* MAC address.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCE (as determined by MAC address), `false` otherwise.
|
||||
*/
|
||||
function isGoogleComputeEngineMACAddress() {
|
||||
const interfaces = (0, os_1.networkInterfaces)();
|
||||
for (const item of Object.values(interfaces)) {
|
||||
if (!item)
|
||||
continue;
|
||||
for (const { mac } of item) {
|
||||
if (GCE_MAC_ADDRESS_REGEX.test(mac)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Determines if the process is running on a Google Compute Engine instance.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCE, `false` otherwise.
|
||||
*/
|
||||
function isGoogleComputeEngine() {
|
||||
return isGoogleComputeEngineLinux() || isGoogleComputeEngineMACAddress();
|
||||
}
|
||||
/**
|
||||
* Determines if the process is running on Google Cloud Platform.
|
||||
*
|
||||
* @returns {boolean} `true` if the process is running on GCP, `false` otherwise.
|
||||
*/
|
||||
function detectGCPResidency() {
|
||||
return isGoogleCloudServerless() || isGoogleComputeEngine();
|
||||
}
|
||||
//# sourceMappingURL=gcp-residency.js.map
|
||||
1
node_modules/gcp-metadata/build/src/gcp-residency.js.map
generated
vendored
Normal file
1
node_modules/gcp-metadata/build/src/gcp-residency.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"gcp-residency.js","sourceRoot":"","sources":["../../src/gcp-residency.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAwBH,0DAkBC;AAOD,gEAcC;AAQD,0EAcC;AAOD,sDAEC;AAOD,gDAEC;AArGD,2BAA0C;AAC1C,2BAA+C;AAE/C;;GAEG;AACU,QAAA,oBAAoB,GAAG;IAClC,SAAS,EAAE,6BAA6B;IACxC,WAAW,EAAE,+BAA+B;CAC7C,CAAC;AAEF,MAAM,qBAAqB,GAAG,QAAQ,CAAC;AAEvC;;;;;;;;GAQG;AACH,SAAgB,uBAAuB;IACrC;;;;;;;;;;OAUG;IACH,MAAM,eAAe,GACnB,OAAO,CAAC,GAAG,CAAC,aAAa;QACzB,OAAO,CAAC,GAAG,CAAC,aAAa;QACzB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAExB,OAAO,CAAC,CAAC,eAAe,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAgB,0BAA0B;IACxC,IAAI,IAAA,aAAQ,GAAE,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAEzC,IAAI,CAAC;QACH,yBAAyB;QACzB,IAAA,aAAQ,EAAC,4BAAoB,CAAC,SAAS,CAAC,CAAC;QAEzC,qCAAqC;QACrC,MAAM,UAAU,GAAG,IAAA,iBAAY,EAAC,4BAAoB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAE1E,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,+BAA+B;IAC7C,MAAM,UAAU,GAAG,IAAA,sBAAiB,GAAE,CAAC;IAEvC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,IAAI,CAAC,IAAI;YAAE,SAAS;QAEpB,KAAK,MAAM,EAAC,GAAG,EAAC,IAAI,IAAI,EAAE,CAAC;YACzB,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB;IACnC,OAAO,0BAA0B,EAAE,IAAI,+BAA+B,EAAE,CAAC;AAC3E,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB;IAChC,OAAO,uBAAuB,EAAE,IAAI,qBAAqB,EAAE,CAAC;AAC9D,CAAC"}
|
||||
141
node_modules/gcp-metadata/build/src/index.d.ts
generated
vendored
Normal file
141
node_modules/gcp-metadata/build/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
export declare const BASE_PATH = "/computeMetadata/v1";
|
||||
export declare const HOST_ADDRESS = "http://169.254.169.254";
|
||||
export declare const SECONDARY_HOST_ADDRESS = "http://metadata.google.internal.";
|
||||
export declare const HEADER_NAME = "Metadata-Flavor";
|
||||
export declare const HEADER_VALUE = "Google";
|
||||
export declare const HEADERS: Readonly<{
|
||||
"Metadata-Flavor": "Google";
|
||||
}>;
|
||||
/**
|
||||
* Metadata server detection override options.
|
||||
*
|
||||
* Available via `process.env.METADATA_SERVER_DETECTION`.
|
||||
*/
|
||||
export declare const METADATA_SERVER_DETECTION: Readonly<{
|
||||
'assume-present': "don't try to ping the metadata server, but assume it's present";
|
||||
none: "don't try to ping the metadata server, but don't try to use it either";
|
||||
'bios-only': "treat the result of a BIOS probe as canonical (don't fall back to pinging)";
|
||||
'ping-only': "skip the BIOS probe, and go straight to pinging";
|
||||
}>;
|
||||
type HeadersInit = ConstructorParameters<typeof Headers>[0];
|
||||
export interface Options {
|
||||
params?: {
|
||||
[index: string]: string;
|
||||
};
|
||||
property?: string;
|
||||
headers?: HeadersInit;
|
||||
}
|
||||
export interface MetadataAccessor {
|
||||
/**
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // equivalent to `project('project-id')`;
|
||||
* const metadataKey = 'project/project-id';
|
||||
*/
|
||||
metadataKey: string;
|
||||
params?: Options['params'];
|
||||
headers?: Options['headers'];
|
||||
noResponseRetries?: number;
|
||||
fastFail?: boolean;
|
||||
}
|
||||
export type BulkResults<T extends readonly MetadataAccessor[]> = {
|
||||
[key in T[number]['metadataKey']]: ReturnType<JSON['parse']>;
|
||||
};
|
||||
/**
|
||||
* Obtain metadata for the current GCE instance.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const serviceAccount: {} = await instance('service-accounts/');
|
||||
* const serviceAccountEmail: string = await instance('service-accounts/default/email');
|
||||
* ```
|
||||
*/
|
||||
export declare function instance<T = any>(options?: string | Options): Promise<T>;
|
||||
/**
|
||||
* Obtain metadata for the current GCP project.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const projectId: string = await project('project-id');
|
||||
* const numericProjectId: number = await project('numeric-project-id');
|
||||
* ```
|
||||
*/
|
||||
export declare function project<T = any>(options?: string | Options): Promise<T>;
|
||||
/**
|
||||
* Obtain metadata for the current universe.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const universeDomain: string = await universe('universe-domain');
|
||||
* ```
|
||||
*/
|
||||
export declare function universe<T>(options?: string | Options): Promise<T>;
|
||||
/**
|
||||
* Retrieve metadata items in parallel.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const data = await bulk([
|
||||
* {
|
||||
* metadataKey: 'instance',
|
||||
* },
|
||||
* {
|
||||
* metadataKey: 'project/project-id',
|
||||
* },
|
||||
* ] as const);
|
||||
*
|
||||
* // data.instance;
|
||||
* // data['project/project-id'];
|
||||
* ```
|
||||
*
|
||||
* @param properties The metadata properties to retrieve
|
||||
* @returns The metadata in `metadatakey:value` format
|
||||
*/
|
||||
export declare function bulk<T extends readonly Readonly<MetadataAccessor>[], R extends BulkResults<T> = BulkResults<T>>(properties: T): Promise<R>;
|
||||
/**
|
||||
* Determine if the metadata server is currently available.
|
||||
*/
|
||||
export declare function isAvailable(): Promise<boolean>;
|
||||
/**
|
||||
* reset the memoized isAvailable() lookup.
|
||||
*/
|
||||
export declare function resetIsAvailableCache(): void;
|
||||
/**
|
||||
* A cache for the detected GCP Residency.
|
||||
*/
|
||||
export declare let gcpResidencyCache: boolean | null;
|
||||
/**
|
||||
* Detects GCP Residency.
|
||||
* Caches results to reduce costs for subsequent calls.
|
||||
*
|
||||
* @see setGCPResidency for setting
|
||||
*/
|
||||
export declare function getGCPResidency(): boolean;
|
||||
/**
|
||||
* Sets the detected GCP Residency.
|
||||
* Useful for forcing metadata server detection behavior.
|
||||
*
|
||||
* Set `null` to autodetect the environment (default behavior).
|
||||
* @see getGCPResidency for getting
|
||||
*/
|
||||
export declare function setGCPResidency(value?: boolean | null): void;
|
||||
/**
|
||||
* Obtain the timeout for requests to the metadata server.
|
||||
*
|
||||
* In certain environments and conditions requests can take longer than
|
||||
* the default timeout to complete. This function will determine the
|
||||
* appropriate timeout based on the environment.
|
||||
*
|
||||
* @returns {number} a request timeout duration in milliseconds.
|
||||
*/
|
||||
export declare function requestTimeout(): number;
|
||||
export * from './gcp-residency';
|
||||
402
node_modules/gcp-metadata/build/src/index.js
generated
vendored
Normal file
402
node_modules/gcp-metadata/build/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,402 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.gcpResidencyCache = exports.METADATA_SERVER_DETECTION = exports.HEADERS = exports.HEADER_VALUE = exports.HEADER_NAME = exports.SECONDARY_HOST_ADDRESS = exports.HOST_ADDRESS = exports.BASE_PATH = void 0;
|
||||
exports.instance = instance;
|
||||
exports.project = project;
|
||||
exports.universe = universe;
|
||||
exports.bulk = bulk;
|
||||
exports.isAvailable = isAvailable;
|
||||
exports.resetIsAvailableCache = resetIsAvailableCache;
|
||||
exports.getGCPResidency = getGCPResidency;
|
||||
exports.setGCPResidency = setGCPResidency;
|
||||
exports.requestTimeout = requestTimeout;
|
||||
/**
|
||||
* Copyright 2018 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const gaxios_1 = require("gaxios");
|
||||
const jsonBigint = require("json-bigint");
|
||||
const gcp_residency_1 = require("./gcp-residency");
|
||||
const logger = __importStar(require("google-logging-utils"));
|
||||
exports.BASE_PATH = '/computeMetadata/v1';
|
||||
exports.HOST_ADDRESS = 'http://169.254.169.254';
|
||||
exports.SECONDARY_HOST_ADDRESS = 'http://metadata.google.internal.';
|
||||
exports.HEADER_NAME = 'Metadata-Flavor';
|
||||
exports.HEADER_VALUE = 'Google';
|
||||
exports.HEADERS = Object.freeze({ [exports.HEADER_NAME]: exports.HEADER_VALUE });
|
||||
const log = logger.log('gcp-metadata');
|
||||
/**
|
||||
* Metadata server detection override options.
|
||||
*
|
||||
* Available via `process.env.METADATA_SERVER_DETECTION`.
|
||||
*/
|
||||
exports.METADATA_SERVER_DETECTION = Object.freeze({
|
||||
'assume-present': "don't try to ping the metadata server, but assume it's present",
|
||||
none: "don't try to ping the metadata server, but don't try to use it either",
|
||||
'bios-only': "treat the result of a BIOS probe as canonical (don't fall back to pinging)",
|
||||
'ping-only': 'skip the BIOS probe, and go straight to pinging',
|
||||
});
|
||||
/**
|
||||
* Returns the base URL while taking into account the GCE_METADATA_HOST
|
||||
* environment variable if it exists.
|
||||
*
|
||||
* @returns The base URL, e.g., http://169.254.169.254/computeMetadata/v1.
|
||||
*/
|
||||
function getBaseUrl(baseUrl) {
|
||||
if (!baseUrl) {
|
||||
baseUrl =
|
||||
process.env.GCE_METADATA_IP ||
|
||||
process.env.GCE_METADATA_HOST ||
|
||||
exports.HOST_ADDRESS;
|
||||
}
|
||||
// If no scheme is provided default to HTTP:
|
||||
if (!/^https?:\/\//.test(baseUrl)) {
|
||||
baseUrl = `http://${baseUrl}`;
|
||||
}
|
||||
return new URL(exports.BASE_PATH, baseUrl).href;
|
||||
}
|
||||
// Accepts an options object passed from the user to the API. In previous
|
||||
// versions of the API, it referred to a `Request` or an `Axios` request
|
||||
// options object. Now it refers to an object with very limited property
|
||||
// names. This is here to help ensure users don't pass invalid options when
|
||||
// they upgrade from 0.4 to 0.5 to 0.8.
|
||||
function validate(options) {
|
||||
Object.keys(options).forEach(key => {
|
||||
switch (key) {
|
||||
case 'params':
|
||||
case 'property':
|
||||
case 'headers':
|
||||
break;
|
||||
case 'qs':
|
||||
throw new Error("'qs' is not a valid configuration option. Please use 'params' instead.");
|
||||
default:
|
||||
throw new Error(`'${key}' is not a valid configuration option.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
async function metadataAccessor(type, options = {}, noResponseRetries = 3, fastFail = false) {
|
||||
const headers = new Headers(exports.HEADERS);
|
||||
let metadataKey = '';
|
||||
let params = {};
|
||||
if (typeof type === 'object') {
|
||||
const metadataAccessor = type;
|
||||
new Headers(metadataAccessor.headers).forEach((value, key) => headers.set(key, value));
|
||||
metadataKey = metadataAccessor.metadataKey;
|
||||
params = metadataAccessor.params || params;
|
||||
noResponseRetries = metadataAccessor.noResponseRetries || noResponseRetries;
|
||||
fastFail = metadataAccessor.fastFail || fastFail;
|
||||
}
|
||||
else {
|
||||
metadataKey = type;
|
||||
}
|
||||
if (typeof options === 'string') {
|
||||
metadataKey += `/${options}`;
|
||||
}
|
||||
else {
|
||||
validate(options);
|
||||
if (options.property) {
|
||||
metadataKey += `/${options.property}`;
|
||||
}
|
||||
new Headers(options.headers).forEach((value, key) => headers.set(key, value));
|
||||
params = options.params || params;
|
||||
}
|
||||
const requestMethod = fastFail ? fastFailMetadataRequest : gaxios_1.request;
|
||||
const req = {
|
||||
url: `${getBaseUrl()}/${metadataKey}`,
|
||||
headers,
|
||||
retryConfig: { noResponseRetries },
|
||||
params,
|
||||
responseType: 'text',
|
||||
timeout: requestTimeout(),
|
||||
};
|
||||
log.info('instance request %j', req);
|
||||
const res = await requestMethod(req);
|
||||
log.info('instance metadata is %s', res.data);
|
||||
const metadataFlavor = res.headers.get(exports.HEADER_NAME);
|
||||
if (metadataFlavor !== exports.HEADER_VALUE) {
|
||||
throw new RangeError(`Invalid response from metadata service: incorrect ${exports.HEADER_NAME} header. Expected '${exports.HEADER_VALUE}', got ${metadataFlavor ? `'${metadataFlavor}'` : 'no header'}`);
|
||||
}
|
||||
if (typeof res.data === 'string') {
|
||||
try {
|
||||
return jsonBigint.parse(res.data);
|
||||
}
|
||||
catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
async function fastFailMetadataRequest(options) {
|
||||
const secondaryOptions = {
|
||||
...options,
|
||||
url: options.url
|
||||
?.toString()
|
||||
.replace(getBaseUrl(), getBaseUrl(exports.SECONDARY_HOST_ADDRESS)),
|
||||
};
|
||||
// We race a connection between DNS/IP to metadata server. There are a couple
|
||||
// reasons for this:
|
||||
//
|
||||
// 1. the DNS is slow in some GCP environments; by checking both, we might
|
||||
// detect the runtime environment significantly faster.
|
||||
// 2. we can't just check the IP, which is tarpitted and slow to respond
|
||||
// on a user's local machine.
|
||||
//
|
||||
// Returns first resolved promise or if all promises get rejected we return an AggregateError.
|
||||
//
|
||||
// Note, however, if a failure happens prior to a success, a rejection should
|
||||
// occur, this is for folks running locally.
|
||||
//
|
||||
const r1 = (0, gaxios_1.request)(options);
|
||||
const r2 = (0, gaxios_1.request)(secondaryOptions);
|
||||
return Promise.any([r1, r2]);
|
||||
}
|
||||
/**
|
||||
* Obtain metadata for the current GCE instance.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const serviceAccount: {} = await instance('service-accounts/');
|
||||
* const serviceAccountEmail: string = await instance('service-accounts/default/email');
|
||||
* ```
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function instance(options) {
|
||||
return metadataAccessor('instance', options);
|
||||
}
|
||||
/**
|
||||
* Obtain metadata for the current GCP project.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const projectId: string = await project('project-id');
|
||||
* const numericProjectId: number = await project('numeric-project-id');
|
||||
* ```
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function project(options) {
|
||||
return metadataAccessor('project', options);
|
||||
}
|
||||
/**
|
||||
* Obtain metadata for the current universe.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const universeDomain: string = await universe('universe-domain');
|
||||
* ```
|
||||
*/
|
||||
function universe(options) {
|
||||
return metadataAccessor('universe', options);
|
||||
}
|
||||
/**
|
||||
* Retrieve metadata items in parallel.
|
||||
*
|
||||
* @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* const data = await bulk([
|
||||
* {
|
||||
* metadataKey: 'instance',
|
||||
* },
|
||||
* {
|
||||
* metadataKey: 'project/project-id',
|
||||
* },
|
||||
* ] as const);
|
||||
*
|
||||
* // data.instance;
|
||||
* // data['project/project-id'];
|
||||
* ```
|
||||
*
|
||||
* @param properties The metadata properties to retrieve
|
||||
* @returns The metadata in `metadatakey:value` format
|
||||
*/
|
||||
async function bulk(properties) {
|
||||
const r = {};
|
||||
await Promise.all(properties.map(item => {
|
||||
return (async () => {
|
||||
const res = await metadataAccessor(item);
|
||||
const key = item.metadataKey;
|
||||
r[key] = res;
|
||||
})();
|
||||
}));
|
||||
return r;
|
||||
}
|
||||
/*
|
||||
* How many times should we retry detecting GCP environment.
|
||||
*/
|
||||
function detectGCPAvailableRetries() {
|
||||
return process.env.DETECT_GCP_RETRIES
|
||||
? Number(process.env.DETECT_GCP_RETRIES)
|
||||
: 0;
|
||||
}
|
||||
let cachedIsAvailableResponse;
|
||||
/**
|
||||
* Determine if the metadata server is currently available.
|
||||
*/
|
||||
async function isAvailable() {
|
||||
if (process.env.METADATA_SERVER_DETECTION) {
|
||||
const value = process.env.METADATA_SERVER_DETECTION.trim().toLocaleLowerCase();
|
||||
if (!(value in exports.METADATA_SERVER_DETECTION)) {
|
||||
throw new RangeError(`Unknown \`METADATA_SERVER_DETECTION\` env variable. Got \`${value}\`, but it should be \`${Object.keys(exports.METADATA_SERVER_DETECTION).join('`, `')}\`, or unset`);
|
||||
}
|
||||
switch (value) {
|
||||
case 'assume-present':
|
||||
return true;
|
||||
case 'none':
|
||||
return false;
|
||||
case 'bios-only':
|
||||
return getGCPResidency();
|
||||
case 'ping-only':
|
||||
// continue, we want to ping the server
|
||||
}
|
||||
}
|
||||
try {
|
||||
// If a user is instantiating several GCP libraries at the same time,
|
||||
// this may result in multiple calls to isAvailable(), to detect the
|
||||
// runtime environment. We use the same promise for each of these calls
|
||||
// to reduce the network load.
|
||||
if (cachedIsAvailableResponse === undefined) {
|
||||
cachedIsAvailableResponse = metadataAccessor('instance', undefined, detectGCPAvailableRetries(),
|
||||
// If the default HOST_ADDRESS has been overridden, we should not
|
||||
// make an effort to try SECONDARY_HOST_ADDRESS (as we are likely in
|
||||
// a non-GCP environment):
|
||||
!(process.env.GCE_METADATA_IP || process.env.GCE_METADATA_HOST));
|
||||
}
|
||||
await cachedIsAvailableResponse;
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
const err = e;
|
||||
if (process.env.DEBUG_AUTH) {
|
||||
console.info(err);
|
||||
}
|
||||
if (err.type === 'request-timeout') {
|
||||
// If running in a GCP environment, metadata endpoint should return
|
||||
// within ms.
|
||||
return false;
|
||||
}
|
||||
if (err.response && err.response.status === 404) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (!(err.response && err.response.status === 404) &&
|
||||
// A warning is emitted if we see an unexpected err.code, or err.code
|
||||
// is not populated:
|
||||
(!err.code ||
|
||||
![
|
||||
'EHOSTDOWN',
|
||||
'EHOSTUNREACH',
|
||||
'ENETUNREACH',
|
||||
'ENOENT',
|
||||
'ENOTFOUND',
|
||||
'ECONNREFUSED',
|
||||
].includes(err.code.toString()))) {
|
||||
let code = 'UNKNOWN';
|
||||
if (err.code)
|
||||
code = err.code.toString();
|
||||
process.emitWarning(`received unexpected error = ${err.message} code = ${code}`, 'MetadataLookupWarning');
|
||||
}
|
||||
// Failure to resolve the metadata service means that it is not available.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* reset the memoized isAvailable() lookup.
|
||||
*/
|
||||
function resetIsAvailableCache() {
|
||||
cachedIsAvailableResponse = undefined;
|
||||
}
|
||||
/**
|
||||
* A cache for the detected GCP Residency.
|
||||
*/
|
||||
exports.gcpResidencyCache = null;
|
||||
/**
|
||||
* Detects GCP Residency.
|
||||
* Caches results to reduce costs for subsequent calls.
|
||||
*
|
||||
* @see setGCPResidency for setting
|
||||
*/
|
||||
function getGCPResidency() {
|
||||
if (exports.gcpResidencyCache === null) {
|
||||
setGCPResidency();
|
||||
}
|
||||
return exports.gcpResidencyCache;
|
||||
}
|
||||
/**
|
||||
* Sets the detected GCP Residency.
|
||||
* Useful for forcing metadata server detection behavior.
|
||||
*
|
||||
* Set `null` to autodetect the environment (default behavior).
|
||||
* @see getGCPResidency for getting
|
||||
*/
|
||||
function setGCPResidency(value = null) {
|
||||
exports.gcpResidencyCache = value !== null ? value : (0, gcp_residency_1.detectGCPResidency)();
|
||||
}
|
||||
/**
|
||||
* Obtain the timeout for requests to the metadata server.
|
||||
*
|
||||
* In certain environments and conditions requests can take longer than
|
||||
* the default timeout to complete. This function will determine the
|
||||
* appropriate timeout based on the environment.
|
||||
*
|
||||
* @returns {number} a request timeout duration in milliseconds.
|
||||
*/
|
||||
function requestTimeout() {
|
||||
return getGCPResidency() ? 0 : 3000;
|
||||
}
|
||||
__exportStar(require("./gcp-residency"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/gcp-metadata/build/src/index.js.map
generated
vendored
Normal file
1
node_modules/gcp-metadata/build/src/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
77
node_modules/gcp-metadata/package.json
generated
vendored
Normal file
77
node_modules/gcp-metadata/package.json
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"name": "gcp-metadata",
|
||||
"version": "8.1.2",
|
||||
"description": "Get the metadata from a Google Cloud Platform environment",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"directory": "packages/gcp-metadata",
|
||||
"url": "https://github.com/googleapis/google-cloud-node-core.git"
|
||||
},
|
||||
"main": "./build/src/index.js",
|
||||
"types": "./build/src/index.d.ts",
|
||||
"type": "commonjs",
|
||||
"files": [
|
||||
"build/src"
|
||||
],
|
||||
"scripts": {
|
||||
"compile": "cross-env NODE_OPTIONS=--max-old-space-size=8192 tsc -p .",
|
||||
"fix": "gts fix",
|
||||
"pretest": "npm run compile",
|
||||
"prepare": "npm run compile",
|
||||
"samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../",
|
||||
"presystem-test": "npm run compile",
|
||||
"system-test": "mocha build/system-test --timeout 600000",
|
||||
"test": "c8 mocha --timeout=5000 build/test",
|
||||
"docs": "jsdoc -c .jsdoc.js",
|
||||
"lint": "gts check",
|
||||
"docs-test": "linkinator docs",
|
||||
"predocs-test": "npm run docs",
|
||||
"prelint": "cd samples; npm link ../; npm install",
|
||||
"clean": "gts clean",
|
||||
"precompile": "gts clean"
|
||||
},
|
||||
"keywords": [
|
||||
"google cloud platform",
|
||||
"google cloud",
|
||||
"google",
|
||||
"app engine",
|
||||
"compute engine",
|
||||
"metadata server",
|
||||
"metadata"
|
||||
],
|
||||
"author": "Google LLC",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"gaxios": "^7.0.0",
|
||||
"google-logging-utils": "^1.0.0",
|
||||
"json-bigint": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@google-cloud/functions": "^4.0.0",
|
||||
"@types/json-bigint": "^1.0.4",
|
||||
"@types/mocha": "^10.0.9",
|
||||
"@types/ncp": "^2.0.8",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/sinon": "^17.0.3",
|
||||
"@types/tmp": "^0.2.6",
|
||||
"c8": "^10.1.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"gcbuild": "^1.3.39",
|
||||
"gcx": "^2.0.27",
|
||||
"gts": "^6.0.2",
|
||||
"jsdoc": "^4.0.4",
|
||||
"jsdoc-fresh": "^5.0.0",
|
||||
"jsdoc-region-tag": "^4.0.0",
|
||||
"linkinator": "^6.1.2",
|
||||
"mocha": "^11.1.0",
|
||||
"ncp": "^2.0.0",
|
||||
"nock": "^14.0.1",
|
||||
"sinon": "^21.0.0",
|
||||
"tmp": "^0.2.3",
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"homepage": "https://github.com/googleapis/google-cloud-node-core/tree/main/packages/gcp-metadata"
|
||||
}
|
||||
Reference in New Issue
Block a user