How to use the gcp-metadata.instance 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 / nodejs-logging / src / metadata.ts View on Github external
export async function getGCEDescriptor() {
  const idResponse = await gcpMetadata.instance('id');
  const zoneResponse = await gcpMetadata.instance('zone');
  // Some parsing is necessary. Metadata service returns a fully
  // qualified zone name: 'projects/{projectId}/zones/{zone}'. Logging
  // wants just the zone part.
  //
  const zone = zoneFromQualifiedZone(zoneResponse);
  return {
    type: 'gce_instance',
    labels: {
      // idResponse can be BigNumber when the id too large for JavaScript
      // numbers. Use a toString() to uniformly convert to a string.
      instance_id: idResponse.toString(),
      zone,
    },
  };
}
github googleapis / nodejs-logging / src / metadata.ts View on Github external
export async function getGCEDescriptor() {
  const idResponse = await gcpMetadata.instance('id');
  const zoneResponse = await gcpMetadata.instance('zone');
  // Some parsing is necessary. Metadata service returns a fully
  // qualified zone name: 'projects/{projectId}/zones/{zone}'. Logging
  // wants just the zone part.
  //
  const zone = zoneFromQualifiedZone(zoneResponse);
  return {
    type: 'gce_instance',
    labels: {
      // idResponse can be BigNumber when the id too large for JavaScript
      // numbers. Use a toString() to uniformly convert to a string.
      instance_id: idResponse.toString(),
      zone,
    },
  };
}
github googleapis / cloud-debug-nodejs / src / agent / debuglet.js View on Github external
'project-id', function(err, response, metadataProject) {
        // We should get an error if we are not on GCP.
        var onGCP = !err;

        // We perfer to use the locally available projectId as that is least
        // surprising to users.
        var project = that.debug_.options.projectId ||
                      process.env.GCLOUD_PROJECT || metadataProject;

        // We if don't have a projectId by now, we fail with an error.
        if (!project) {
          return callback(err);
        }
        metadata.instance(
          'attributes/cluster-name', function(err, response, metadataCluster) {
            return callback(null,
              { project: project, clusterName: metadataCluster, onGCP: onGCP});
        });
      });
};
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-profiler-nodejs / ts / src / index.ts View on Github external
async function getMetadataInstanceField(field: string): Promise {
  return gcpMetadata.instance(field);
}
github census-instrumentation / opencensus-node / packages / opencensus-resource-util / src / resource-utils.ts View on Github external
async function getInstanceId() {
  try {
    const id = await gcpMetadata.instance('id');
    return id.toString();
  } catch {
    return '';
  }
}
github stephenplusplus / google-auto-auth / index.js View on Github external
isContainerEngine (callback) {
    var env = this.environment;

    if (typeof env.IS_CONTAINER_ENGINE !== 'undefined') {
      setImmediate(() => {
        callback(null, env.IS_CONTAINER_ENGINE);
      });
      return;
    }

    gcpMetadata.instance('/attributes/cluster-name')
      .then(() => {
        env.IS_CONTAINER_ENGINE = true;
        callback(null, env.IS_CONTAINER_ENGINE);
      })
      .catch(() => {
        env.IS_CONTAINER_ENGINE = false
        callback(null, env.IS_CONTAINER_ENGINE);
      });
  }
github census-instrumentation / opencensus-node / packages / opencensus-resource-util / src / resource-utils.ts View on Github external
async function getClusterName() {
  try {
    return await gcpMetadata.instance('attributes/cluster-name');
  } catch {
    return '';
  }
}

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