How to use the gcp-metadata.project 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 / system-test / fixtures / kitchen / src / index.ts View on Github external
* Distributed under MIT license.
 * See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
 */

import * as gcp from 'gcp-metadata';
// uncomment the line below during development
//import * as gcp from '../../../../build/src/index';

const header = gcp.HEADER_NAME;
const headers = gcp.HEADERS;

async function main() {
  const v = await gcp.instance('/somepath');
}

gcp.project('something').then(console.log);

main().catch(console.error);
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 / cloud-debug-nodejs / src / agent / debuglet.js View on Github external
Debuglet.prototype.getProjectId_ = function(callback) {
  var that = this;

  // We need to figure out whether we are running on GCP. We can use our ability
  // to access the metadata service as a test for that.
  // TODO: change this to getProjectId in the future.
  metadata.project(
      '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);
        }
        return callback(null, project, onGCP);
      });
};
github googleapis / cloud-debug-nodejs / src / agent / debuglet.js View on Github external
Debuglet.prototype.getMetadataValues_ = function(callback) {
  var that = this;

  // We need to figure out whether we are running on GCP. We can use our ability
  // to access the metadata service as a test for that.
  // TODO: change this to getProjectId in the future.
  metadata.project(
      '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,
github ruslang02 / atomos / node_modules / google-auth-library / build / src / auth / googleauth.js View on Github external
return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 2, , 3]);
                        return [4 /*yield*/, gcpMetadata.project('project-id')];
                    case 1:
                        r = _a.sent();
                        return [2 /*return*/, r.data];
                    case 2:
                        e_3 = _a.sent();
                        // Ignore any errors
                        return [2 /*return*/, null];
                    case 3: return [2 /*return*/];
                }
            });
        });
github census-instrumentation / opencensus-node / packages / opencensus-resource-util / src / resource-utils.ts View on Github external
async function getProjectId() {
  try {
    return await gcpMetadata.project('project-id');
  } catch {
    return '';
  }
}

gcp-metadata

Get the metadata from a Google Cloud Platform environment

Apache-2.0
Latest version published 1 year ago

Package Health Score

85 / 100
Full package analysis