Skip to content

Commit b8ae799

Browse files
yoshi-automationJustinBeckwith
authored andcommitted
feat: support apiEndpoint override in client constructor (#157)
1 parent f9af466 commit b8ae799

5 files changed

Lines changed: 73 additions & 7 deletions

File tree

packages/google-cloud-asset/src/v1/asset_service_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class AssetServiceClient {
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
);
@@ -183,6 +187,14 @@ class AssetServiceClient {
183187
return 'cloudasset.googleapis.com';
184188
}
185189

190+
/**
191+
* The DNS address for this API service - same as servicePath(),
192+
* exists for compatibility reasons.
193+
*/
194+
static get apiEndpoint() {
195+
return 'cloudasset.googleapis.com';
196+
}
197+
186198
/**
187199
* The port for this API service.
188200
*/

packages/google-cloud-asset/src/v1beta1/asset_service_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class AssetServiceClient {
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
);
@@ -183,6 +187,14 @@ class AssetServiceClient {
183187
return 'cloudasset.googleapis.com';
184188
}
185189

190+
/**
191+
* The DNS address for this API service - same as servicePath(),
192+
* exists for compatibility reasons.
193+
*/
194+
static get apiEndpoint() {
195+
return 'cloudasset.googleapis.com';
196+
}
197+
186198
/**
187199
* The port for this API service.
188200
*/

packages/google-cloud-asset/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-21T11:07:32.789700Z",
2+
"updateTime": "2019-06-05T14:12:31.290419Z",
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-asset/test/gapic-v1.js

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

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

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

0 commit comments

Comments
 (0)