1 | /**
|
2 | * Copyright 2018 Google LLC
|
3 | *
|
4 | * Distributed under MIT license.
|
5 | * See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
6 | */
|
7 | /// <reference types="node" />
|
8 | import { OutgoingHttpHeaders } from 'http';
|
9 | export declare const BASE_PATH = "/computeMetadata/v1";
|
10 | export declare const HOST_ADDRESS = "http://169.254.169.254";
|
11 | export declare const SECONDARY_HOST_ADDRESS = "http://metadata.google.internal.";
|
12 | export declare const HEADER_NAME = "Metadata-Flavor";
|
13 | export declare const HEADER_VALUE = "Google";
|
14 | export declare const HEADERS: Readonly<{
|
15 | "Metadata-Flavor": "Google";
|
16 | }>;
|
17 | /**
|
18 | * Metadata server detection override options.
|
19 | *
|
20 | * Available via `process.env.METADATA_SERVER_DETECTION`.
|
21 | */
|
22 | export declare const METADATA_SERVER_DETECTION: Readonly<{
|
23 | 'assume-present': "don't try to ping the metadata server, but assume it's present";
|
24 | none: "don't try to ping the metadata server, but don't try to use it either";
|
25 | 'bios-only': "treat the result of a BIOS probe as canonical (don't fall back to pinging)";
|
26 | 'ping-only': "skip the BIOS probe, and go straight to pinging";
|
27 | }>;
|
28 | export interface Options {
|
29 | params?: {
|
30 | [index: string]: string;
|
31 | };
|
32 | property?: string;
|
33 | headers?: OutgoingHttpHeaders;
|
34 | }
|
35 | export interface MetadataAccessor {
|
36 | /**
|
37 | *
|
38 | * @example
|
39 | *
|
40 | * // equivalent to `project('project-id')`;
|
41 | * const metadataKey = 'project/project-id';
|
42 | */
|
43 | metadataKey: string;
|
44 | params?: Options['params'];
|
45 | headers?: Options['headers'];
|
46 | noResponseRetries?: number;
|
47 | fastFail?: boolean;
|
48 | }
|
49 | export type BulkResults<T extends readonly MetadataAccessor[]> = {
|
50 | [key in T[number]['metadataKey']]: ReturnType<JSON['parse']>;
|
51 | };
|
52 | /**
|
53 | * Obtain metadata for the current GCE instance.
|
54 | *
|
55 | * @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
56 | *
|
57 | * @example
|
58 | * ```
|
59 | * const serviceAccount: {} = await instance('service-accounts/');
|
60 | * const serviceAccountEmail: string = await instance('service-accounts/default/email');
|
61 | * ```
|
62 | */
|
63 | export declare function instance<T = any>(options?: string | Options): Promise<T>;
|
64 | /**
|
65 | * Obtain metadata for the current GCP project.
|
66 | *
|
67 | * @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
68 | *
|
69 | * @example
|
70 | * ```
|
71 | * const projectId: string = await project('project-id');
|
72 | * const numericProjectId: number = await project('numeric-project-id');
|
73 | * ```
|
74 | */
|
75 | export declare function project<T = any>(options?: string | Options): Promise<T>;
|
76 | /**
|
77 | * Obtain metadata for the current universe.
|
78 | *
|
79 | * @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
80 | *
|
81 | * @example
|
82 | * ```
|
83 | * const universeDomain: string = await universe('universe_domain');
|
84 | * ```
|
85 | */
|
86 | export declare function universe<T>(options?: string | Options): Promise<T>;
|
87 | /**
|
88 | * Retrieve metadata items in parallel.
|
89 | *
|
90 | * @see {@link https://cloud.google.com/compute/docs/metadata/predefined-metadata-keys}
|
91 | *
|
92 | * @example
|
93 | * ```
|
94 | * const data = await bulk([
|
95 | * {
|
96 | * metadataKey: 'instance',
|
97 | * },
|
98 | * {
|
99 | * metadataKey: 'project/project-id',
|
100 | * },
|
101 | * ] as const);
|
102 | *
|
103 | * // data.instance;
|
104 | * // data['project/project-id'];
|
105 | * ```
|
106 | *
|
107 | * @param properties The metadata properties to retrieve
|
108 | * @returns The metadata in `metadatakey:value` format
|
109 | */
|
110 | export declare function bulk<T extends readonly Readonly<MetadataAccessor>[], R extends BulkResults<T> = BulkResults<T>>(properties: T): Promise<R>;
|
111 | /**
|
112 | * Determine if the metadata server is currently available.
|
113 | */
|
114 | export declare function isAvailable(): Promise<boolean>;
|
115 | /**
|
116 | * reset the memoized isAvailable() lookup.
|
117 | */
|
118 | export declare function resetIsAvailableCache(): void;
|
119 | /**
|
120 | * A cache for the detected GCP Residency.
|
121 | */
|
122 | export declare let gcpResidencyCache: boolean | null;
|
123 | /**
|
124 | * Detects GCP Residency.
|
125 | * Caches results to reduce costs for subsequent calls.
|
126 | *
|
127 | * @see setGCPResidency for setting
|
128 | */
|
129 | export declare function getGCPResidency(): boolean;
|
130 | /**
|
131 | * Sets the detected GCP Residency.
|
132 | * Useful for forcing metadata server detection behavior.
|
133 | *
|
134 | * Set `null` to autodetect the environment (default behavior).
|
135 | * @see getGCPResidency for getting
|
136 | */
|
137 | export declare function setGCPResidency(value?: boolean | null): void;
|
138 | /**
|
139 | * Obtain the timeout for requests to the metadata server.
|
140 | *
|
141 | * In certain environments and conditions requests can take longer than
|
142 | * the default timeout to complete. This function will determine the
|
143 | * appropriate timeout based on the environment.
|
144 | *
|
145 | * @returns {number} a request timeout duration in milliseconds.
|
146 | */
|
147 | export declare function requestTimeout(): number;
|
148 | export * from './gcp-residency';
|