Skip to content

Commit 1ca13df

Browse files
yoshi-automationJustinBeckwith
authored andcommitted
feat: support apiEndpoint override in client constructor (#239)
1 parent e489350 commit 1ca13df

File tree

7 files changed

+107
-8
lines changed

7 files changed

+107
-8
lines changed

packages/google-cloud-tasks/src/v2/cloud_tasks_client.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class CloudTasksClient {
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
);
@@ -187,6 +191,14 @@ class CloudTasksClient {
187191
return 'cloudtasks.googleapis.com';
188192
}
189193

194+
/**
195+
* The DNS address for this API service - same as servicePath(),
196+
* exists for compatibility reasons.
197+
*/
198+
static get apiEndpoint() {
199+
return 'cloudtasks.googleapis.com';
200+
}
201+
190202
/**
191203
* The port for this API service.
192204
*/

packages/google-cloud-tasks/src/v2beta2/cloud_tasks_client.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class CloudTasksClient {
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
);
@@ -191,6 +195,14 @@ class CloudTasksClient {
191195
return 'cloudtasks.googleapis.com';
192196
}
193197

198+
/**
199+
* The DNS address for this API service - same as servicePath(),
200+
* exists for compatibility reasons.
201+
*/
202+
static get apiEndpoint() {
203+
return 'cloudtasks.googleapis.com';
204+
}
205+
194206
/**
195207
* The port for this API service.
196208
*/

packages/google-cloud-tasks/src/v2beta3/cloud_tasks_client.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class CloudTasksClient {
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
);
@@ -187,6 +191,14 @@ class CloudTasksClient {
187191
return 'cloudtasks.googleapis.com';
188192
}
189193

194+
/**
195+
* The DNS address for this API service - same as servicePath(),
196+
* exists for compatibility reasons.
197+
*/
198+
static get apiEndpoint() {
199+
return 'cloudtasks.googleapis.com';
200+
}
201+
190202
/**
191203
* The port for this API service.
192204
*/

packages/google-cloud-tasks/synth.metadata

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"updateTime": "2019-05-21T11:26:46.540067Z",
2+
"updateTime": "2019-06-05T14:27:56.003459Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.20.0",
8-
"dockerImage": "googleapis/artman@sha256:3246adac900f4bdbd62920e80de2e5877380e44036b3feae13667ec255ebf5ec"
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": "32a10f69e2c9ce15bba13ab1ff928bacebb25160",
16-
"internalRef": "249058354"
15+
"sha": "47c142a7cecc6efc9f6f8af804b8be55392b795b",
16+
"internalRef": "251635729"
1717
}
1818
},
1919
{

packages/google-cloud-tasks/test/gapic-v2.js

+21
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('CloudTasksClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath = tasksModule.v2.CloudTasksClient.servicePath;
28+
assert(servicePath);
29+
});
30+
31+
it('has apiEndpoint', () => {
32+
const apiEndpoint = tasksModule.v2.CloudTasksClient.apiEndpoint;
33+
assert(apiEndpoint);
34+
});
35+
36+
it('has port', () => {
37+
const port = tasksModule.v2.CloudTasksClient.port;
38+
assert(port);
39+
assert(typeof port === 'number');
40+
});
41+
42+
it('should create a client with no options', () => {
43+
const client = new tasksModule.v2.CloudTasksClient();
44+
assert(client);
45+
});
46+
2647
describe('listQueues', () => {
2748
it('invokes listQueues without error', done => {
2849
const client = new tasksModule.v2.CloudTasksClient({

packages/google-cloud-tasks/test/gapic-v2beta2.js

+21
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('CloudTasksClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath = tasksModule.v2beta2.CloudTasksClient.servicePath;
28+
assert(servicePath);
29+
});
30+
31+
it('has apiEndpoint', () => {
32+
const apiEndpoint = tasksModule.v2beta2.CloudTasksClient.apiEndpoint;
33+
assert(apiEndpoint);
34+
});
35+
36+
it('has port', () => {
37+
const port = tasksModule.v2beta2.CloudTasksClient.port;
38+
assert(port);
39+
assert(typeof port === 'number');
40+
});
41+
42+
it('should create a client with no options', () => {
43+
const client = new tasksModule.v2beta2.CloudTasksClient();
44+
assert(client);
45+
});
46+
2647
describe('listQueues', () => {
2748
it('invokes listQueues without error', done => {
2849
const client = new tasksModule.v2beta2.CloudTasksClient({

packages/google-cloud-tasks/test/gapic-v2beta3.js

+21
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('CloudTasksClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath = tasksModule.v2beta3.CloudTasksClient.servicePath;
28+
assert(servicePath);
29+
});
30+
31+
it('has apiEndpoint', () => {
32+
const apiEndpoint = tasksModule.v2beta3.CloudTasksClient.apiEndpoint;
33+
assert(apiEndpoint);
34+
});
35+
36+
it('has port', () => {
37+
const port = tasksModule.v2beta3.CloudTasksClient.port;
38+
assert(port);
39+
assert(typeof port === 'number');
40+
});
41+
42+
it('should create a client with no options', () => {
43+
const client = new tasksModule.v2beta3.CloudTasksClient();
44+
assert(client);
45+
});
46+
2647
describe('listQueues', () => {
2748
it('invokes listQueues without error', done => {
2849
const client = new tasksModule.v2beta3.CloudTasksClient({

0 commit comments

Comments
 (0)