Skip to content

Commit 02b2522

Browse files
yoshi-automationJustinBeckwith
authored andcommitted
feat: support apiEndpoint override in client constructor (#112)
1 parent d3273bb commit 02b2522

5 files changed

Lines changed: 77 additions & 7 deletions

File tree

packages/google-cloud-securitycenter/src/v1/security_center_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class SecurityCenterClient {
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
);
@@ -257,6 +261,14 @@ class SecurityCenterClient {
257261
return 'securitycenter.googleapis.com';
258262
}
259263

264+
/**
265+
* The DNS address for this API service - same as servicePath(),
266+
* exists for compatibility reasons.
267+
*/
268+
static get apiEndpoint() {
269+
return 'securitycenter.googleapis.com';
270+
}
271+
260272
/**
261273
* The port for this API service.
262274
*/

packages/google-cloud-securitycenter/src/v1beta1/security_center_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class SecurityCenterClient {
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
);
@@ -248,6 +252,14 @@ class SecurityCenterClient {
248252
return 'securitycenter.googleapis.com';
249253
}
250254

255+
/**
256+
* The DNS address for this API service - same as servicePath(),
257+
* exists for compatibility reasons.
258+
*/
259+
static get apiEndpoint() {
260+
return 'securitycenter.googleapis.com';
261+
}
262+
251263
/**
252264
* The port for this API service.
253265
*/

packages/google-cloud-securitycenter/synth.metadata

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"updateTime": "2019-05-23T20:32:45.718938Z",
2+
"updateTime": "2019-06-05T14:25:08.839987Z",
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": "6a2f0244d6a07f2683e4a8cec514425bb27cfa03",
16-
"internalRef": "249677018"
15+
"sha": "47c142a7cecc6efc9f6f8af804b8be55392b795b",
16+
"internalRef": "251635729"
1717
}
1818
},
1919
{

packages/google-cloud-securitycenter/test/gapic-v1.js

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

2525
describe('SecurityCenterClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath =
28+
securityCenterModule.v1.SecurityCenterClient.servicePath;
29+
assert(servicePath);
30+
});
31+
32+
it('has apiEndpoint', () => {
33+
const apiEndpoint =
34+
securityCenterModule.v1.SecurityCenterClient.apiEndpoint;
35+
assert(apiEndpoint);
36+
});
37+
38+
it('has port', () => {
39+
const port = securityCenterModule.v1.SecurityCenterClient.port;
40+
assert(port);
41+
assert(typeof port === 'number');
42+
});
43+
44+
it('should create a client with no options', () => {
45+
const client = new securityCenterModule.v1.SecurityCenterClient();
46+
assert(client);
47+
});
48+
2649
describe('createSource', () => {
2750
it('invokes createSource without error', done => {
2851
const client = new securityCenterModule.v1.SecurityCenterClient({

packages/google-cloud-securitycenter/test/gapic-v1beta1.js

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

2525
describe('SecurityCenterClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath =
28+
securityCenterModule.v1beta1.SecurityCenterClient.servicePath;
29+
assert(servicePath);
30+
});
31+
32+
it('has apiEndpoint', () => {
33+
const apiEndpoint =
34+
securityCenterModule.v1beta1.SecurityCenterClient.apiEndpoint;
35+
assert(apiEndpoint);
36+
});
37+
38+
it('has port', () => {
39+
const port = securityCenterModule.v1beta1.SecurityCenterClient.port;
40+
assert(port);
41+
assert(typeof port === 'number');
42+
});
43+
44+
it('should create a client with no options', () => {
45+
const client = new securityCenterModule.v1beta1.SecurityCenterClient();
46+
assert(client);
47+
});
48+
2649
describe('createSource', () => {
2750
it('invokes createSource without error', done => {
2851
const client = new securityCenterModule.v1beta1.SecurityCenterClient({

0 commit comments

Comments
 (0)