How to use the gcp-metadata.isAvailable function in gcp-metadata

To help you get started, we’ve selected a few gcp-metadata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / gcp-metadata / samples / quickstart.js View on Github external
async function quickstart() {
    // check to see if this code can access a metadata server
    const isAvailable = await gcpMetadata.isAvailable();
    console.log(`Is available: ${isAvailable}`);

    // Instance and Project level metadata will only be available if
    // running inside of a Google Cloud compute environment such as
    // Cloud Functions, App Engine, Kubernetes Engine, or Compute Engine.
    if (isAvailable) {
      // grab all top level metadata from the service
      const instanceMetadata = await gcpMetadata.instance();
      console.log('Instance metadata:');
      console.log(instanceMetadata);

      // get all project level metadata
      const projectMetadata = await gcpMetadata.project();
      console.log('Project metadata:');
      console.log(projectMetadata);
    }
github googleapis / gcp-metadata / system-test / fixtures / cloudbuild / index.js View on Github external
async function main() {
  const isAvailable = await gcpMetadata.isAvailable();
  console.log(`isAvailable: ${isAvailable}`);
  await gcpMetadata.instance(`service-accounts/default/token`);
  const svc = await gcpMetadata.instance({
    property: 'service-accounts/',
    params: {recursive: 'true'},
  });
  console.log('serviceAccounts:');
  console.log(
    JSON.stringify(svc)
      .split('\n')
      .join()
  );
}
github googleapis / cloud-debug-nodejs / src / agent / debuglet.ts View on Github external
static runningOnGCP(): Promise {
    return metadata.isAvailable();
  }
github googleapis / google-auth-library-nodejs / src / auth / envDetect.ts View on Github external
async function isComputeEngine() {
  return gcpMetadata.isAvailable();
}

gcp-metadata

Get the metadata from a Google Cloud Platform environment

Apache-2.0
Latest version published 6 months ago

Package Health Score

87 / 100
Full package analysis