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

Commit 2bc75d8

Browse files
author
Matt Loring
committed
GCLOUD_PROJECT instead of GCLOUD_PROJECT_NUM
Fixes #90
1 parent fd1f643 commit 2bc75d8

File tree

7 files changed

+38
-55
lines changed

7 files changed

+38
-55
lines changed

README.md

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,19 @@ This module provides Cloud Debug support for Node.js applications. [Google Cloud
1313
[![Cloud Debugger Intro](http://img.youtube.com/vi/tyHcK_kAOpw/0.jpg)](https://www.youtube.com/watch?v=tyHcK_kAOpw)
1414

1515
## Prerequisites
16-
* Your application will need to be using Node.js version 0.12 or greater. Node.js v5+ is recommended. (Node.js v5.2.0 is not supported on account of [this bug](https://github.com/nodejs/node/issues/4297))
16+
* Your application will need to be using Node.js version 0.12 or greater. Node.js v5+ is recommended.
1717
* The source of your application is uploaded to a [cloud source repository](https://cloud.google.com/tools/cloud-repositories/docs/). The Debugger UI needs the source to be available in order to set breakpoints.
1818

1919
## Quick Start (Node.js v4.x+)
2020
```shell
2121
# Install with `npm` or add to your `package.json`.
2222
npm install --save @google/cloud-debug
2323

24-
# Change the start command of your application in package.json
25-
...
26-
"scripts" {
27-
"start": "node --require @google/cloud-debug server.js"
28-
...
24+
# Require the agent at the top of your main script.
25+
require('@google/cloud-debug');
2926
```
3027
Deploy your application, and navigate to the [Debug tab][debug-tab] within the [Google Developers Console][dev-console] to set breakpoints and start debugging.
3128

32-
## Installation
33-
34-
1. Install the debug agent module via `npm` or add it to your `package.json`.
35-
36-
```shell
37-
npm install --save @google/cloud-debug
38-
```
39-
1. Ensure that the module gets loaded during your application's startup. The best way to do this is via the `--require` command line option available in Node.js v4. You should add this option to the startup script section in your `package.json`.
40-
41-
```
42-
"scripts": {
43-
"start": "node --require @google/cloud-debug server.js",
44-
```
45-
If you are using Node.js v0.12.x, you will not be able to use the `--require` command line option. Instead you will have to manually load the debug agent module in the startup script of your application. For example, you may want to add the following
46-
to your `server.js`:
47-
```javascript
48-
require('@google/cloud-debug');
49-
```
50-
5129
## Running on Google Cloud Platform
5230

5331
There are three different services that can host Node.js application to Google Cloud Platform.
@@ -72,13 +50,13 @@ Container Engine nodes need to also be created with the `cloud-platform` scope,
7250

7351
If your application is running outside of Google Cloud Platform, such as locally, on-premise, or on another cloud provider, you can still use Cloud Debug.
7452

75-
1. You will need to specify the numeric project ID of your project. Your numeric project ID, or project number, is visible the Project information section on your project's [dashboard][dashboard].
53+
1. You will need to specify your project name. Your project name is visible in the [Google Cloud Console][cloud-console-projects], it may be something like `particular-future-12345`. If your application is [running on Google Cloud Platform](running-on-google-cloud-platform), you don't need to specify the project name.
7654

77-
export GCLOUD_PROJECT_NUM=<your numeric project id>
55+
export GCLOUD_PROJECT=<project name>
7856

79-
2. You need to provide service account credentials to your application. The recommended way is via [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).
57+
2. You need to provide service account credentials to your application. The recommended way is via [Application Default Credentials][app-default-credentials].
8058

81-
1. [Create a new JSON service account key](https://console.developers.google.com/apis/credentials/serviceaccountkey).
59+
1. [Create a new JSON service account key][service-account].
8260
2. Copy the key somewhere your application can access it. Be sure not to expose the key publicly.
8361
3. Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the full path to the key. The debug agent will automatically look for this environment variable.
8462

@@ -110,10 +88,12 @@ As soon as that line of code is reached in any of the running instances of your
11088

11189

11290
[cloud-debugger]: https://cloud.google.com/tools/cloud-debugger/
113-
[dev-console]: https://console.developers.google.com/
114-
[dashboard]: https://console.developers.google.com/dashboard
91+
[dev-console]: https://console.cloud.google.com/
11592
[debug-tab]: https://console.developers.google.com/debug
11693
[gcloud-sdk]: https://cloud.google.com/sdk/gcloud/
94+
[cloud-console-projects]: https://console.cloud.google.com/iam-admin/projects
95+
[app-default-credentials]: https://developers.google.com/identity/protocols/application-default-credentials
96+
[service-account]: https://console.developers.google.com/apis/credentials/serviceaccountkey
11797
[npm-image]: https://img.shields.io/npm/v/@google/cloud-debug.svg
11898
[npm-url]: https://npmjs.org/package/@google/cloud-debug
11999
[travis-image]: https://travis-ci.org/GoogleCloudPlatform/cloud-debug-nodejs.svg?branch=master

lib/debugletapi.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function DebugletApi() {
4646
this.request_ = utils.authorizedRequestFactory(SCOPES);
4747

4848
/** @private {string} numeric project id */
49-
this.projectNumber_ = null;
49+
this.project_ = null;
5050

5151
/** @private {string} debuggee id provided by the server once registered */
5252
this.debuggeeId_ = null;
@@ -66,12 +66,12 @@ DebugletApi.prototype.init = function(uid, logger, callback) {
6666
that.uid_ = uid;
6767
that.nextWaitToken_ = null;
6868

69-
function complete(err, projectNumber) {
69+
function complete(err, project) {
7070
if (err) {
7171
callback(err);
7272
return;
7373
}
74-
that.projectNumber_ = projectNumber;
74+
that.project_ = project;
7575

7676
fs.readFile('source-contexts.json', 'utf8', function(err, data) {
7777
try {
@@ -84,14 +84,11 @@ DebugletApi.prototype.init = function(uid, logger, callback) {
8484
});
8585
}
8686

87-
if (process.env.GCLOUD_PROJECT_NUM) {
88-
var projectNumber = process.env.GCLOUD_PROJECT_NUM;
89-
var err = /^\d+$/.test(projectNumber) ?
90-
null :
91-
new Error('GCLOUD_PROJECT_NUM should be numeric');
87+
if (process.env.GCLOUD_PROJECT) {
88+
var project = process.env.GCLOUD_PROJECT;
9289

9390
setImmediate(function() {
94-
complete(err, projectNumber);
91+
complete(null, project);
9592
});
9693
} else {
9794
utils.getProjectNumber(complete);
@@ -159,7 +156,7 @@ DebugletApi.prototype.register_ = function(errorMessage, callback) {
159156
uniquifier = crypto.createHash('sha1').update(uniquifier).digest('hex');
160157

161158
var debuggee = {
162-
project: that.projectNumber_,
159+
project: that.project_,
163160
uniquifier: uniquifier,
164161
description: desc,
165162
agentVersion: version,

test/e2e/test-capture-time.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var debuglet;
3434

3535
describe(__filename, function(){
3636
beforeEach(function() {
37-
process.env.GCLOUD_PROJECT_NUM = 0;
37+
process.env.GCLOUD_PROJECT = 0;
3838
debuglet = new Debuglet(
3939
config, logger.create(config.logLevel, '@google/cloud-debug'));
4040
debuglet.once('started', function() {

test/e2e/test-error-message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe(__filename, function() {
3131
var debuglet = new Debuglet(
3232
config, logger.create(config.logLevel, '@google/cloud-debug'));
3333

34-
process.env.GCLOUD_PROJECT_NUM=0;
34+
process.env.GCLOUD_PROJECT=0;
3535

3636
var API = 'https://clouddebugger.googleapis.com';
3737

test/e2e/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports.runTest = function runTest() {
6363
assert.ok(api.debuggeeId_, 'debuglet has registered');
6464

6565
var debuggee = api.debuggeeId_;
66-
var project = api.projectNumber_;
66+
var project = api.project_;
6767

6868
// Get our own credentials because we need an extra scope
6969
var auth = new GoogleAuth();

test/standalone/test-debuglet.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var bp = {
3737

3838
describe(__filename, function(){
3939
beforeEach(function() {
40-
process.env.GCLOUD_PROJECT_NUM = 0;
40+
process.env.GCLOUD_PROJECT = 0;
4141
debuglet = new Debuglet(
4242
config, logger.create(config.logLevel, '@google/cloud-debug'));
4343
debuglet.once('started', function() {
@@ -50,7 +50,7 @@ describe(__filename, function(){
5050
});
5151

5252
it('should not start unless we know the project num', function(done) {
53-
delete process.env.GCLOUD_PROJECT_NUM;
53+
delete process.env.GCLOUD_PROJECT;
5454
var scope = nock('http://metadata.google.internal')
5555
.get('/computeMetadata/v1/project/numeric-project-id')
5656
.reply(404);
@@ -66,17 +66,23 @@ describe(__filename, function(){
6666
debuglet.start();
6767
});
6868

69-
it('should complain if GCLOUD_PROJECT_NUM is not numeric', function(done) {
70-
process.env.GCLOUD_PROJECT_NUM='11020304f2934';
69+
it('should accept non-numeric GCLOUD_PROJECT', function(done) {
70+
process.env.GCLOUD_PROJECT='11020304f2934';
7171

72-
debuglet.once('error', function(err) {
73-
assert(err);
74-
assert(err.message.indexOf('should be numeric') !== -1);
72+
var scope = nock(API)
73+
.post(REGISTER_PATH)
74+
.reply(200, {
75+
debuggee: {
76+
id: DEBUGGEE_ID
77+
}
78+
});
79+
80+
debuglet.once('registered', function(id) {
81+
assert(id === DEBUGGEE_ID);
82+
scope.done();
7583
done();
7684
});
77-
debuglet.once('started', function() {
78-
assert.fail();
79-
});
85+
8086
debuglet.start();
8187
});
8288

test/standalone/test-env-relative-repository-path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'use strict';
1818

19-
process.env.GCLOUD_PROJECT_NUM = 0;
19+
process.env.GCLOUD_PROJECT = 0;
2020
process.env.GCLOUD_DEBUG_REPO_APP_PATH = '/my/project/root';
2121

2222
var assert = require('assert');

0 commit comments

Comments
 (0)