diff --git a/src/index.ts b/src/index.ts index ec54ffd..55940d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -184,6 +184,14 @@ async function fastFailMetadataRequest( /** * 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 export function instance(options?: string | Options) { @@ -191,13 +199,35 @@ export function instance(options?: string | Options) { } /** - * Obtain metadata for the current GCP Project. + * 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 export function project(options?: string | 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'); + * ``` + */ +export function universe(options?: string | Options) { + return metadataAccessor('universe', options); +} + /* * How many times should we retry detecting GCP environment. */ diff --git a/test/index.test.ts b/test/index.test.ts index 938d639..0ca4169 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -150,6 +150,19 @@ describe('unit test', () => { scope.done(); }); + it('should query the `universe` type', async () => { + const PROPERTY = 'universe_domain'; + const VALUE = 'my-domain.com'; + + const scope = nock(HOST) + .get(`${PATH}/universe/${PROPERTY}`) + .reply(200, VALUE, HEADERS); + + assert(await gcp.universe(PROPERTY), VALUE); + + scope.done(); + }); + it('should return the request error', async () => { const scope = nock(HOST) .get(`${PATH}/${TYPE}`)