Package gcp-metadata (7.0.0)

Interfaces

MetadataAccessor

Options

Variables

  BASE_PATH 
  
 = 
  
 "/computeMetadata/v1" 
 

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.

  GCE_LINUX_BIOS_PATHS 
 : 
  
 { 
  
 BIOS_DATE 
 : 
  
 string 
 ; 
  
 BIOS_VENDOR 
 : 
  
 string 
 ; 
 } 
 

Known paths unique to Google Compute Engine Linux instances

  gcpResidencyCache 
 : 
  
 boolean 
  
 | 
  
 null 
 

A cache for the detected GCP Residency.

  HEADER_NAME 
  
 = 
  
 "Metadata-Flavor" 
 
  HEADER_VALUE 
  
 = 
  
 "Google" 
 
  HEADERS 
 : 
  
 Readonly 
< { 
  
 "metadata-flavor" 
 := 
 "" 
  
 "google" 
 ; 
 = 
 "" 
  
 } 
 = 
 "" 
> 
  HOST_ADDRESS 
  
 = 
  
 "http://169.254.169.254" 
 
  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" 
 ; 
 = 
 "" 
  
 } 
 = 
 "" 
> 

Metadata server detection override options.

Available via process.env.METADATA_SERVER_DETECTION .

  SECONDARY_HOST_ADDRESS 
  
 = 
  
 "http://metadata.google.internal." 
 

Functions

  export 
  
 declare 
  
 function 
  
 bulk 
 

Retrieve metadata items in parallel.

Parameter
Name
Description
properties
T

The metadata properties to retrieve

Returns
Type
Description
Promise <R>

The metadata in metadatakey:value format

Type Parameters
Type
Description
T
R

Example

  const 
  
 data 
  
 = 
  
 await 
  
 bulk 
 ([ 
  
 { 
  
 metadataKey 
 : 
  
 'instance' 
 , 
  
 }, 
  
 { 
  
 metadataKey 
 : 
  
 'project/project-id' 
 , 
  
 }, 
 ] 
  
 as 
  
 const 
 ); 
 // data.instance; 
 // data['project/project-id']; 
 
  export 
  
 declare 
  
 function 
  
 detectGCPResidency 
 () 
 : 
  
 boolean 
 ; 
 

Determines if the process is running on Google Cloud Platform.

Returns
Type
Description
boolean

{boolean} true if the process is running on GCP, false otherwise.

  export 
  
 declare 
  
 function 
  
 getGCPResidency 
 () 
 : 
  
 boolean 
 ; 
 

Detects GCP Residency. Caches results to reduce costs for subsequent calls.

Returns
Type
Description
boolean
  export 
  
 declare 
  
 function 
  
 instance 
 

Obtain metadata for the current GCE instance.

Parameter
Name
Description
options
string | Options
Returns
Type
Description
Promise <T>
Type Parameter
Type
Description
T

Example

  const 
  
 serviceAccount 
 : 
  
 {} 
  
 = 
  
 await 
  
 instance 
 ( 
 'service-accounts/' 
 ); 
 const 
  
 serviceAccountEmail 
 : 
  
 string 
  
 = 
  
 await 
  
 instance 
 ( 
 'service-accounts/default/email' 
 ); 
 
  export 
  
 declare 
  
 function 
  
 isAvailable 
 () 
 : 
  
 Promise 
 

Determine if the metadata server is currently available.

Returns
Type
Description
Promise <boolean>
  export 
  
 declare 
  
 function 
  
 isGoogleCloudServerless 
 () 
 : 
  
 boolean 
 ; 
 

Determines if the process is running on a Google Cloud Serverless environment (Cloud Run or Cloud Functions instance).

Uses the: - . - .

Returns
Type
Description
boolean

{boolean} true if the process is running on GCP serverless, false otherwise.

  export 
  
 declare 
  
 function 
  
 isGoogleComputeEngine 
 () 
 : 
  
 boolean 
 ; 
 

Determines if the process is running on a Google Compute Engine instance.

Returns
Type
Description
boolean

{boolean} true if the process is running on GCE, false otherwise.

  export 
  
 declare 
  
 function 
  
 isGoogleComputeEngineLinux 
 () 
 : 
  
 boolean 
 ; 
 

Determines if the process is running on a Linux Google Compute Engine instance.

Returns
Type
Description
boolean

{boolean} true if the process is running on Linux GCE, false otherwise.

  export 
  
 declare 
  
 function 
  
 isGoogleComputeEngineMACAddress 
 () 
 : 
  
 boolean 
 ; 
 

Determines if the process is running on a Google Compute Engine instance with a known MAC address.

Returns
Type
Description
boolean

{boolean} true if the process is running on GCE (as determined by MAC address), false otherwise.

  export 
  
 declare 
  
 function 
  
 project 
 

Obtain metadata for the current GCP project.

Parameter
Name
Description
options
string | Options
Returns
Type
Description
Promise <T>
Type Parameter
Type
Description
T

Example

  const 
  
 projectId 
 : 
  
 string 
  
 = 
  
 await 
  
 project 
 ( 
 'project-id' 
 ); 
 const 
  
 numericProjectId 
 : 
  
 number 
  
 = 
  
 await 
  
 project 
 ( 
 'numeric-project-id' 
 ); 
 
  export 
  
 declare 
  
 function 
  
 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

{number} a request timeout duration in milliseconds.

  export 
  
 declare 
  
 function 
  
 resetIsAvailableCache 
 () 
 : 
  
 void 
 ; 
 

reset the memoized isAvailable() lookup.

Returns
Type
Description
void
  export 
  
 declare 
  
 function 
  
 setGCPResidency 
 ( 
 value 
 ?: 
  
 boolean 
  
 | 
  
 null 
 ) 
 : 
  
 void 
 ; 
 

Sets the detected GCP Residency. Useful for forcing metadata server detection behavior.

Set null to autodetect the environment (default behavior).

Parameter
Name
Description
value
boolean | null
Returns
Type
Description
void
  export 
  
 declare 
  
 function 
  
 universe 
 

Obtain metadata for the current universe.

Parameter
Name
Description
options
string | Options
Returns
Type
Description
Promise <T>
Type Parameter
Type
Description
T

Example

  const 
  
 universeDomain 
 : 
  
 string 
  
 = 
  
 await 
  
 universe 
 ( 
 'universe-domain' 
 ); 
 

Type Aliases

  export 
  
 type 
  
 BulkResults 
 
Type Parameter
Type
Description
T
Design a Mobile Site
View Site in Mobile | Classic
Share by: