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

Commit e5d9eb9

Browse files
authored
start using gcp-metadata for metadata queries (#210)
1 parent 5e3a0ef commit e5d9eb9

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"async": "^2.1.2",
3939
"coffee-script": "^1.9.3",
4040
"findit2": "^2.2.3",
41+
"gcp-metadata": "^0.1.0",
4142
"google-auth-library": "^0.9.5",
4243
"lodash": "^4.12.0",
4344
"request": "^2.61.0",

src/agent/debuglet.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var extend = require('extend');
2424
var util = require('util');
2525
var semver = require('semver');
2626
var _ = require('lodash');
27+
var metadata = require('gcp-metadata');
2728

2829
var v8debugapi = require('./v8debugapi.js');
2930
var Debuggee = require('../debuggee.js');
@@ -263,30 +264,31 @@ Debuglet.createDebuggee =
263264
return new Debuggee(properties);
264265
};
265266

266-
/**
267-
* @private
268-
*/
269-
Debuglet.prototype.getProjectId_ = function(callback) {
267+
/**
268+
* @private
269+
*/
270+
Debuglet.prototype.getProjectId_ = function(callback) {
270271
var that = this;
271272

272273
// We need to figure out whether we are running on GCP. We can use our ability
273274
// to access the metadata service as a test for that.
274275
// TODO: change this to getProjectId in the future.
275-
common.utils.getProjectNumber(function(err, metadataProject) {
276-
// We should get an error if we are not on GCP.
277-
var onGCP = !err;
278-
279-
// We perfer to use the locally available projectId as that is least
280-
// surprising to users.
281-
var project = that.debug_.options.projectId || process.env.GCLOUD_PROJECT ||
282-
metadataProject;
283-
284-
// We if don't have a projectId by now, we fail with an error.
285-
if (!project) {
286-
return callback(err);
287-
}
288-
return callback(null, project, onGCP);
289-
});
276+
metadata.project(
277+
'numeric-project-id', function(err, response, metadataProject) {
278+
// We should get an error if we are not on GCP.
279+
var onGCP = !err;
280+
281+
// We perfer to use the locally available projectId as that is least
282+
// surprising to users.
283+
var project = that.debug_.options.projectId ||
284+
process.env.GCLOUD_PROJECT || metadataProject;
285+
286+
// We if don't have a projectId by now, we fail with an error.
287+
if (!project) {
288+
return callback(err);
289+
}
290+
return callback(null, project, onGCP);
291+
});
290292
};
291293

292294
Debuglet.prototype.getSourceContext_ =

test/standalone/test-debuglet.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe(__filename, function() {
4848
});
4949

5050
it('should not start when projectId is not available', function(done) {
51+
this.timeout(8000);
5152
var debug = require('../..')();
5253
var debuglet = new Debuglet(debug, defaultConfig);
5354

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

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

0 commit comments

Comments
 (0)