|
15 | 15 | */ |
16 | 16 | 'use strict'; |
17 | 17 |
|
18 | | -var crypto = require('crypto'); |
19 | | -var path = require('path'); |
20 | 18 | var pjson = require('../package.json'); |
21 | | -var StatusMessage = require('./status-message.js'); |
22 | 19 | var _ = require('lodash'); |
23 | 20 |
|
24 | 21 | /** |
25 | 22 | * Creates a Debuggee service object. |
26 | 23 | * @ref https://cloud.google.com/debugger/api/reference/rest/v2/Debuggee |
27 | 24 | * |
28 | | - * @param {string} projectId - Google Cloud Project ID |
29 | | - * @param {string} uid - unique identified for the source code on this instance. |
30 | | - * @param {?object} serviceContext |
31 | | - * @param {string} serviceContext.service - A string identifying the service/ |
32 | | - * module that this instance belongs to. |
33 | | - * @param {string} serviceContext.version - A string identifying the version of |
34 | | - * the service. |
35 | | - * @param {?object} sourceContext |
36 | | - * @param {?string} description - A user specified string identifying this |
37 | | - * debuggable instance. |
38 | | - * @param {?string} errorMessage - A error string to register this as a erroring |
39 | | - * debuggable instance. This is useful if we have a problem starting the |
40 | | - * debugger support, and want to report to the API so that the users has a |
41 | | - * way of noticing. |
42 | | - * @param {?boolean} onGCP - set to true when the debuggee is running inside |
43 | | - * Google Cloud Platform. |
| 25 | + * @param {object} properties - an object with properties to use for Debuggee |
| 26 | + * initialization. |
| 27 | + * @param {object} properties.project - Google Cloud Project ID |
| 28 | + * @param {string} properties.uniquifier - Debuggee uniquifier within the |
| 29 | + * project. Any string that identifies the application within the project |
| 30 | + * can be used. Including environment and version or build IDs is |
| 31 | + * recommended. |
| 32 | + * @param {?string} properties.description - A user specified string identifyin |
| 33 | + * this debuggable instance (default: none) |
| 34 | + * @param {?string} properties.agentVersion - version ID of the agent. (default: |
| 35 | + * the version of this module) |
| 36 | + * @param {?object} labels - a set of custom properties about the debuggee that |
| 37 | + * are reported to the service. |
| 38 | + * @param {?array<object>} properties.sourceContexts |
| 39 | + * @param {?StatusMessage} properties.statusMessage - A error string to register |
| 40 | + * this as an erroring debuggable instance. This is useful if we have a |
| 41 | + * problem starting the debugger support, and want to report to the API so |
| 42 | + * that the user has a way of noticing. |
| 43 | + * TODO(ofrobots): has this been renamed to `status` in the API? |
44 | 44 | */ |
45 | | -function Debuggee(projectId, uid, serviceContext, sourceContext, |
46 | | - description, errorMessage, onGCP) { |
| 45 | +function Debuggee(properties) { |
47 | 46 | if (!(this instanceof Debuggee)) { |
48 | | - return new Debuggee(projectId, uid, serviceContext, sourceContext, |
49 | | - description, errorMessage, onGCP); |
| 47 | + return new Debuggee(properties); |
50 | 48 | } |
51 | 49 |
|
52 | | - if (!_.isString(projectId)) { |
53 | | - throw new Error('projectId must be a string'); |
| 50 | + properties = properties || {}; |
| 51 | + |
| 52 | + if (!_.isString(properties.project)) { |
| 53 | + throw new Error('properties.project must be a string'); |
54 | 54 | } |
55 | | - if (!_.isString(uid)) { |
56 | | - throw new Error('uid must be a string'); |
| 55 | + if (!_.isString(properties.uniquifier)) { |
| 56 | + throw new Error('properties.uniquifier must be a string'); |
57 | 57 | } |
58 | 58 |
|
59 | | - var cwd = process.cwd(); |
60 | | - var mainScript = path.relative(cwd, process.argv[1]); |
61 | | - |
62 | | - var version = 'google.com/node-' + (onGCP ? 'gcp' : 'standalone') + '/v' + |
63 | | - pjson.version; |
64 | | - var desc = process.title + ' ' + mainScript; |
65 | | - |
66 | | - var labels = { |
67 | | - 'main script': mainScript, |
68 | | - 'process.title': process.title, |
69 | | - 'node version': process.versions.node, |
70 | | - 'V8 version': process.versions.v8, |
71 | | - 'agent.name': pjson.name, |
72 | | - 'agent.version': pjson.version, |
73 | | - 'projectid': projectId |
74 | | - }; |
75 | | - |
76 | | - if (serviceContext) { |
77 | | - if (_.isString(serviceContext.service) && |
78 | | - serviceContext.service !== 'default') { |
79 | | - // As per app-engine-ids, the module label is not reported |
80 | | - // when it happens to be 'default'. |
81 | | - labels.module = serviceContext.service; |
82 | | - desc += ' module:' + serviceContext.service; |
83 | | - } |
84 | | - |
85 | | - if (_.isString(serviceContext.version)) { |
86 | | - labels.version = serviceContext.version; |
87 | | - desc += ' version:' + serviceContext.version; |
88 | | - } |
| 59 | + this.project = properties.project; |
| 60 | + this.uniquifier = properties.uniquifier; |
| 61 | + this.agentVersion = |
| 62 | + properties.agentVersion || (pjson.name + '/default/v' + pjson.version); |
| 63 | + if (properties.description) { |
| 64 | + this.description = properties.description; |
89 | 65 | } |
90 | | - |
91 | | - if (description) { |
92 | | - desc += ' description:' + description; |
| 66 | + if (properties.labels) { |
| 67 | + this.labels = properties.labels; |
93 | 68 | } |
94 | | - |
95 | | - var uniquifier = |
96 | | - desc + version + uid + sourceContext + JSON.stringify(labels); |
97 | | - uniquifier = crypto.createHash('sha1').update(uniquifier).digest('hex'); |
98 | | - |
99 | | - if (errorMessage) { |
100 | | - this.statusMessage = |
101 | | - new StatusMessage(StatusMessage.UNSPECIFIED, errorMessage, true); |
| 69 | + if (properties.sourceContexts) { |
| 70 | + this.sourceContexts = properties.sourceContexts; |
102 | 71 | } |
103 | | - |
104 | | - this.project = projectId; |
105 | | - this.uniquifier = uniquifier; |
106 | | - this.description = desc; |
107 | | - this.agentVersion = version; |
108 | | - this.labels = labels; |
109 | | - if (sourceContext) { |
110 | | - this.sourceContexts = [sourceContext]; |
| 72 | + if (properties.statusMessage) { |
| 73 | + this.statusMessage = properties.statusMessage; |
111 | 74 | } |
112 | 75 | } |
113 | 76 |
|
|
0 commit comments