gcp-metadata

  • Version 6.1.0
  • Published
  • 81.3 kB
  • 2 dependencies
  • Apache-2.0 license

Install

npm i gcp-metadata
yarn add gcp-metadata
pnpm add gcp-metadata

Overview

Get the metadata from a Google Cloud Platform environment

Index

Variables

variable BASE_PATH

const BASE_PATH: string;

    variable GCE_LINUX_BIOS_PATHS

    const GCE_LINUX_BIOS_PATHS: { BIOS_DATE: string; BIOS_VENDOR: string };
    • Known paths unique to Google Compute Engine Linux instances

    variable gcpResidencyCache

    let gcpResidencyCache: boolean;
    • A cache for the detected GCP Residency.

    variable HEADER_NAME

    const HEADER_NAME: string;

      variable HEADER_VALUE

      const HEADER_VALUE: string;

        variable HEADERS

        const HEADERS: Readonly<{ 'Metadata-Flavor': 'Google' }>;

          variable HOST_ADDRESS

          const HOST_ADDRESS: string;

            variable METADATA_SERVER_DETECTION

            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';
            }>;
            • Metadata server detection override options.

              Available via process.env.METADATA_SERVER_DETECTION.

            variable SECONDARY_HOST_ADDRESS

            const SECONDARY_HOST_ADDRESS: string;

              Functions

              function bulk

              bulk: <
              T extends readonly Readonly<MetadataAccessor>[],
              R extends BulkResults<T> = BulkResults<T>
              >(
              properties: T
              ) => Promise<R>;
              • Retrieve metadata items in parallel.

                Parameter properties

                The metadata properties to retrieve

                Returns

                The metadata in metadatakey:value format

                Example 1

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

                See Also

              function detectGCPResidency

              detectGCPResidency: () => boolean;
              • Determines if the process is running on Google Cloud Platform.

                Returns

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

              function getGCPResidency

              getGCPResidency: () => boolean;
              • Detects GCP Residency. Caches results to reduce costs for subsequent calls.

                See Also

                • setGCPResidency for setting

              function instance

              instance: <T = any>(options?: string | Options) => Promise<T>;

              function isAvailable

              isAvailable: () => Promise<boolean>;
              • Determine if the metadata server is currently available.

              function isGoogleCloudServerless

              isGoogleCloudServerless: () => boolean;
              • Determines if the process is running on a Google Cloud Serverless environment (Cloud Run or Cloud Functions instance).

                Uses the: - . - .

                Returns

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

              function isGoogleComputeEngine

              isGoogleComputeEngine: () => 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.

              function isGoogleComputeEngineLinux

              isGoogleComputeEngineLinux: () => 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.

              function isGoogleComputeEngineMACAddress

              isGoogleComputeEngineMACAddress: () => 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.

              function project

              project: <T = any>(options?: string | Options) => Promise<T>;

              function requestTimeout

              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

                {number} a request timeout duration in milliseconds.

              function resetIsAvailableCache

              resetIsAvailableCache: () => void;
              • reset the memoized isAvailable() lookup.

              function setGCPResidency

              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).

                See Also

                • getGCPResidency for getting

              function universe

              universe: <T>(options?: string | Options) => Promise<T>;

              Interfaces

              interface MetadataAccessor

              interface MetadataAccessor {}

                property fastFail

                fastFail?: boolean;

                  property headers

                  headers?: Options['headers'];

                    property metadataKey

                    metadataKey: string;
                    • Example 1

                      // equivalent to project('project-id'); const metadataKey = 'project/project-id';

                    property noResponseRetries

                    noResponseRetries?: number;

                      property params

                      params?: Options['params'];

                        interface Options

                        interface Options {}

                          property headers

                          headers?: OutgoingHttpHeaders;

                            property params

                            params?: {
                            [index: string]: string;
                            };

                              property property

                              property?: string;

                                Type Aliases

                                type BulkResults

                                type BulkResults<T extends readonly MetadataAccessor[]> = {
                                [key in T[number]['metadataKey']]: ReturnType<JSON['parse']>;
                                };

                                  Package Files (2)

                                  Dependencies (2)

                                  Dev Dependencies (22)

                                  Peer Dependencies (0)

                                  No peer dependencies.

                                  Badge

                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/gcp-metadata.

                                  • Markdown
                                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/gcp-metadata)
                                  • HTML
                                    <a href="https://www.jsdocs.io/package/gcp-metadata"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>