Skip to content

Commit bda7124

Browse files
yoshi-automationJustinBeckwith
authored andcommitted
feat: support apiEndpoint override in client constructor (#505)
1 parent 4a3b80a commit bda7124

File tree

5 files changed

+108
-9
lines changed

5 files changed

+108
-9
lines changed

src/v2/config_service_v2_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class ConfigServiceV2Client {
5656
* API remote host.
5757
*/
5858
constructor(opts) {
59+
opts = opts || {};
5960
this._descriptors = {};
6061

62+
const servicePath =
63+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
64+
6165
// Ensure that options include the service address and port.
6266
opts = Object.assign(
6367
{
6468
clientConfig: {},
6569
port: this.constructor.port,
66-
servicePath: this.constructor.servicePath,
70+
servicePath,
6771
},
6872
opts
6973
);
@@ -176,6 +180,14 @@ class ConfigServiceV2Client {
176180
return 'logging.googleapis.com';
177181
}
178182

183+
/**
184+
* The DNS address for this API service - same as servicePath(),
185+
* exists for compatibility reasons.
186+
*/
187+
static get apiEndpoint() {
188+
return 'logging.googleapis.com';
189+
}
190+
179191
/**
180192
* The port for this API service.
181193
*/

src/v2/logging_service_v2_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class LoggingServiceV2Client {
5656
* API remote host.
5757
*/
5858
constructor(opts) {
59+
opts = opts || {};
5960
this._descriptors = {};
6061

62+
const servicePath =
63+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
64+
6165
// Ensure that options include the service address and port.
6266
opts = Object.assign(
6367
{
6468
clientConfig: {},
6569
port: this.constructor.port,
66-
servicePath: this.constructor.servicePath,
70+
servicePath,
6771
},
6872
opts
6973
);
@@ -202,6 +206,14 @@ class LoggingServiceV2Client {
202206
return 'logging.googleapis.com';
203207
}
204208

209+
/**
210+
* The DNS address for this API service - same as servicePath(),
211+
* exists for compatibility reasons.
212+
*/
213+
static get apiEndpoint() {
214+
return 'logging.googleapis.com';
215+
}
216+
205217
/**
206218
* The port for this API service.
207219
*/

src/v2/metrics_service_v2_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ class MetricsServiceV2Client {
5555
* API remote host.
5656
*/
5757
constructor(opts) {
58+
opts = opts || {};
5859
this._descriptors = {};
5960

61+
const servicePath =
62+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
63+
6064
// Ensure that options include the service address and port.
6165
opts = Object.assign(
6266
{
6367
clientConfig: {},
6468
port: this.constructor.port,
65-
servicePath: this.constructor.servicePath,
69+
servicePath,
6670
},
6771
opts
6872
);
@@ -168,6 +172,14 @@ class MetricsServiceV2Client {
168172
return 'logging.googleapis.com';
169173
}
170174

175+
/**
176+
* The DNS address for this API service - same as servicePath(),
177+
* exists for compatibility reasons.
178+
*/
179+
static get apiEndpoint() {
180+
return 'logging.googleapis.com';
181+
}
182+
171183
/**
172184
* The port for this API service.
173185
*/

synth.metadata

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"updateTime": "2019-06-02T12:17:31.339926Z",
2+
"updateTime": "2019-06-05T14:21:10.388885Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.22.0",
8-
"dockerImage": "googleapis/artman@sha256:72f6287a42490bfe1609aed491f29411af21df3f744199fe8bb8d276c1fdf419"
7+
"version": "0.23.1",
8+
"dockerImage": "googleapis/artman@sha256:9d5cae1454da64ac3a87028f8ef486b04889e351c83bb95e83b8fab3959faed0"
99
}
1010
},
1111
{
1212
"git": {
1313
"name": "googleapis",
1414
"remote": "https://github.com/googleapis/googleapis.git",
15-
"sha": "a8ee1416f4c588f2ab92da72e7c1f588c784d3e6",
16-
"internalRef": "250996044"
15+
"sha": "47c142a7cecc6efc9f6f8af804b8be55392b795b",
16+
"internalRef": "251635729"
1717
}
1818
},
1919
{
2020
"template": {
2121
"name": "node_library",
2222
"origin": "synthtool.gcp",
23-
"version": "2019.4.10"
23+
"version": "2019.5.2"
2424
}
2525
}
2626
],

test/gapic-v2.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ const error = new Error();
2323
error.code = FAKE_STATUS_CODE;
2424

2525
describe('LoggingServiceV2Client', () => {
26+
it('has servicePath', () => {
27+
const servicePath = loggingModule.v2.LoggingServiceV2Client.servicePath;
28+
assert(servicePath);
29+
});
30+
31+
it('has apiEndpoint', () => {
32+
const apiEndpoint = loggingModule.v2.LoggingServiceV2Client.apiEndpoint;
33+
assert(apiEndpoint);
34+
});
35+
36+
it('has port', () => {
37+
const port = loggingModule.v2.LoggingServiceV2Client.port;
38+
assert(port);
39+
assert(typeof port === 'number');
40+
});
41+
42+
it('should create a client with no options', () => {
43+
const client = new loggingModule.v2.LoggingServiceV2Client();
44+
assert(client);
45+
});
46+
2647
describe('deleteLog', () => {
2748
it('invokes deleteLog without error', done => {
2849
const client = new loggingModule.v2.LoggingServiceV2Client({
@@ -321,6 +342,27 @@ describe('LoggingServiceV2Client', () => {
321342
});
322343
});
323344
describe('ConfigServiceV2Client', () => {
345+
it('has servicePath', () => {
346+
const servicePath = loggingModule.v2.ConfigServiceV2Client.servicePath;
347+
assert(servicePath);
348+
});
349+
350+
it('has apiEndpoint', () => {
351+
const apiEndpoint = loggingModule.v2.ConfigServiceV2Client.apiEndpoint;
352+
assert(apiEndpoint);
353+
});
354+
355+
it('has port', () => {
356+
const port = loggingModule.v2.ConfigServiceV2Client.port;
357+
assert(port);
358+
assert(typeof port === 'number');
359+
});
360+
361+
it('should create a client with no options', () => {
362+
const client = new loggingModule.v2.ConfigServiceV2Client();
363+
assert(client);
364+
});
365+
324366
describe('listSinks', () => {
325367
it('invokes listSinks without error', done => {
326368
const client = new loggingModule.v2.ConfigServiceV2Client({
@@ -972,6 +1014,27 @@ describe('ConfigServiceV2Client', () => {
9721014
});
9731015
});
9741016
describe('MetricsServiceV2Client', () => {
1017+
it('has servicePath', () => {
1018+
const servicePath = loggingModule.v2.MetricsServiceV2Client.servicePath;
1019+
assert(servicePath);
1020+
});
1021+
1022+
it('has apiEndpoint', () => {
1023+
const apiEndpoint = loggingModule.v2.MetricsServiceV2Client.apiEndpoint;
1024+
assert(apiEndpoint);
1025+
});
1026+
1027+
it('has port', () => {
1028+
const port = loggingModule.v2.MetricsServiceV2Client.port;
1029+
assert(port);
1030+
assert(typeof port === 'number');
1031+
});
1032+
1033+
it('should create a client with no options', () => {
1034+
const client = new loggingModule.v2.MetricsServiceV2Client();
1035+
assert(client);
1036+
});
1037+
9751038
describe('listLogMetrics', () => {
9761039
it('invokes listLogMetrics without error', done => {
9771040
const client = new loggingModule.v2.MetricsServiceV2Client({

0 commit comments

Comments
 (0)