Members
GCE_LINUX_BIOS_PATHS
Known paths unique to Google Compute Engine Linux instances
METADATA_SERVER_DETECTION
Metadata server detection override options.
Available via process.env.METADATA_SERVER_DETECTION.
(constant) SERVERLESS_ENV_VARS
Environment variables used to detect Google Cloud Serverless environments (Cloud Run Services, Cloud Run Jobs, Cloud Run Worker Pools, and Cloud Functions).
(constant) gaxios_1
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.
gcpResidencyCache
A cache for the detected GCP Residency.
Methods
(async) bulk(properties)
Retrieve metadata items in parallel.
Parameters:
| Name | Type | Description |
|---|---|---|
properties |
The metadata properties to retrieve |
Returns:
| Type | Description |
|---|---|
|
The metadata in |
Example
```
const data = await bulk([
{
metadataKey: 'instance',
},
{
metadataKey: 'project/project-id',
},
] as const);
// data.instance;
// data['project/project-id'];
```
detectGCPResidency() → {boolean}
Determines if the process is running on Google Cloud Platform.
Returns:
| Type | Description |
|---|---|
| boolean |
|
getBaseUrl()
Returns the base URL while taking into account the GCE_METADATA_HOST environment variable if it exists.
Returns:
| Type | Description |
|---|---|
|
The base URL, e.g., http://169.254.169.254/computeMetadata/v1. |
getErrorCodes()
Recursively extracts and normalizes POSIX/network error codes from potentially
nested Error objects (AggregateError.errors from Promise.any, .cause, .error).
Guards against circular references and deep recursion.
getGCPResidency()
Detects GCP Residency. Caches results to reduce costs for subsequent calls.
- See:
-
- setGCPResidency for setting
instance()
Obtain metadata for the current GCE instance.
Example
```
const serviceAccount: {} = await instance('service-accounts/');
const serviceAccountEmail: string = await instance('service-accounts/default/email');
```
(async) isAvailable()
Determine if the metadata server is currently available.
isGoogleCloudServerless() → {boolean}
Determines if the process is running on a Google Cloud Serverless environment (Cloud Run Services/Jobs/Worker Pools or Cloud Functions).
Environment variables checked:
CLOUD_RUN_JOBis used for Cloud Run Jobs: Cloud Run environment variables.FUNCTION_NAMEis used in older Cloud Functions environments: Python 3.7 and Go 1.11.K_SERVICEis used in Cloud Run and newer Cloud Functions environments: Cloud Run environment variables, Cloud Functions newer runtimes.CLOUD_RUN_WORKER_POOLis used in Cloud Run Worker Pools: Cloud Run environment variables, Deploy Worker Pools to Cloud Run.
Returns:
| Type | Description |
|---|---|
| boolean |
|
isGoogleComputeEngine() → {boolean}
Determines if the process is running on a Google Compute Engine instance.
Returns:
| Type | Description |
|---|---|
| boolean |
|
isGoogleComputeEngineLinux() → {boolean}
Determines if the process is running on a Linux Google Compute Engine instance.
Returns:
| Type | Description |
|---|---|
| boolean |
|
isGoogleComputeEngineMACAddress() → {boolean}
Determines if the process is running on a Google Compute Engine instance with a known MAC address.
Returns:
| Type | Description |
|---|---|
| boolean |
|
project()
Obtain metadata for the current GCP project.
Example
```
const projectId: string = await project('project-id');
const numericProjectId: number = await project('numeric-project-id');
```
requestTimeout() → {number}
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:
| Type | Description |
|---|---|
| number |
a request timeout duration in milliseconds. |
resetIsAvailableCache()
reset the memoized isAvailable() lookup.
setGCPResidency()
Sets the detected GCP Residency. Useful for forcing metadata server detection behavior.
Set null to autodetect the environment (default behavior).
- See:
-
- getGCPResidency for getting
universe()
Obtain metadata for the current universe.