Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

start using gcp-metadata for metadata queries #210

Merged
merged 1 commit into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"async": "^2.1.2",
"coffee-script": "^1.9.3",
"findit2": "^2.2.3",
"gcp-metadata": "^0.1.0",
"google-auth-library": "^0.9.5",
"lodash": "^4.12.0",
"request": "^2.61.0",
Expand Down
40 changes: 21 additions & 19 deletions src/agent/debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var extend = require('extend');
var util = require('util');
var semver = require('semver');
var _ = require('lodash');
var metadata = require('gcp-metadata');

var v8debugapi = require('./v8debugapi.js');
var Debuggee = require('../debuggee.js');
Expand Down Expand Up @@ -263,30 +264,31 @@ Debuglet.createDebuggee =
return new Debuggee(properties);
};

/**
* @private
*/
Debuglet.prototype.getProjectId_ = function(callback) {
/**
* @private
*/
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.

This comment was marked as spam.

This comment was marked as spam.

common.utils.getProjectNumber(function(err, 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);
});
metadata.project(

This comment was marked as spam.

This comment was marked as spam.

'numeric-project-id', function(err, response, metadataProject) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

// 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);
});
};

Debuglet.prototype.getSourceContext_ =
Expand Down
2 changes: 2 additions & 0 deletions test/standalone/test-debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe(__filename, function() {
});

it('should not start when projectId is not available', function(done) {
this.timeout(8000);

This comment was marked as spam.

This comment was marked as spam.

var debug = require('../..')();
var debuglet = new Debuglet(debug, defaultConfig);

Expand All @@ -70,6 +71,7 @@ describe(__filename, function() {
});

it('should not crash without project num', function(done) {
this.timeout(8000);
var debug = require('../..')();
var debuglet = new Debuglet(debug, defaultConfig);

Expand Down