diff --git a/packages/google-cloud-memcache/samples/generated/v1/cloud_memcache.list_instances.js b/packages/google-cloud-memcache/samples/generated/v1/cloud_memcache.list_instances.js index 7a1eae4c608..ce47efea692 100644 --- a/packages/google-cloud-memcache/samples/generated/v1/cloud_memcache.list_instances.js +++ b/packages/google-cloud-memcache/samples/generated/v1/cloud_memcache.list_instances.js @@ -70,7 +70,7 @@ function main(parent) { }; // Run request - const iterable = await memcacheClient.listInstancesAsync(request); + const iterable = memcacheClient.listInstancesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-memcache/samples/generated/v1beta2/cloud_memcache.list_instances.js b/packages/google-cloud-memcache/samples/generated/v1beta2/cloud_memcache.list_instances.js index 39a29e0ac55..658dd042886 100644 --- a/packages/google-cloud-memcache/samples/generated/v1beta2/cloud_memcache.list_instances.js +++ b/packages/google-cloud-memcache/samples/generated/v1beta2/cloud_memcache.list_instances.js @@ -70,7 +70,7 @@ function main(parent) { }; // Run request - const iterable = await memcacheClient.listInstancesAsync(request); + const iterable = memcacheClient.listInstancesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-memcache/src/v1/cloud_memcache_client.ts b/packages/google-cloud-memcache/src/v1/cloud_memcache_client.ts index 061d7aaef25..aa631723911 100644 --- a/packages/google-cloud-memcache/src/v1/cloud_memcache_client.ts +++ b/packages/google-cloud-memcache/src/v1/cloud_memcache_client.ts @@ -33,6 +33,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/cloud_memcache_client_config.json`. @@ -68,6 +69,8 @@ export class CloudMemcacheClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -127,8 +130,20 @@ export class CloudMemcacheClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof CloudMemcacheClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'memcache.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -143,7 +158,7 @@ export class CloudMemcacheClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -168,10 +183,10 @@ export class CloudMemcacheClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.locationsClient = new this._gaxModule.LocationsClient( @@ -426,21 +441,52 @@ export class CloudMemcacheClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'memcache.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'memcache.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-memcache/src/v1beta2/cloud_memcache_client.ts b/packages/google-cloud-memcache/src/v1beta2/cloud_memcache_client.ts index 0ea14c0b565..c04be219289 100644 --- a/packages/google-cloud-memcache/src/v1beta2/cloud_memcache_client.ts +++ b/packages/google-cloud-memcache/src/v1beta2/cloud_memcache_client.ts @@ -33,6 +33,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta2/cloud_memcache_client_config.json`. @@ -68,6 +69,8 @@ export class CloudMemcacheClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -127,8 +130,20 @@ export class CloudMemcacheClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof CloudMemcacheClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'memcache.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -143,7 +158,7 @@ export class CloudMemcacheClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -168,10 +183,10 @@ export class CloudMemcacheClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.locationsClient = new this._gaxModule.LocationsClient( @@ -438,21 +453,52 @@ export class CloudMemcacheClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'memcache.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'memcache.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1.ts b/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1.ts index a3c507f833b..69f03b3876d 100644 --- a/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1.ts +++ b/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1.ts @@ -166,16 +166,62 @@ function stubAsyncIterationCall( describe('v1.CloudMemcacheClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - cloudmemcacheModule.v1.CloudMemcacheClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new cloudmemcacheModule.v1.CloudMemcacheClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'memcache.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - cloudmemcacheModule.v1.CloudMemcacheClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new cloudmemcacheModule.v1.CloudMemcacheClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + cloudmemcacheModule.v1.CloudMemcacheClient.servicePath; + assert.strictEqual(servicePath, 'memcache.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + cloudmemcacheModule.v1.CloudMemcacheClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'memcache.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new cloudmemcacheModule.v1.CloudMemcacheClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'memcache.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new cloudmemcacheModule.v1.CloudMemcacheClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'memcache.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new cloudmemcacheModule.v1.CloudMemcacheClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1beta2.ts b/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1beta2.ts index b50fb5f1315..c693d1ae46e 100644 --- a/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1beta2.ts +++ b/packages/google-cloud-memcache/test/gapic_cloud_memcache_v1beta2.ts @@ -166,16 +166,62 @@ function stubAsyncIterationCall( describe('v1beta2.CloudMemcacheClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - cloudmemcacheModule.v1beta2.CloudMemcacheClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new cloudmemcacheModule.v1beta2.CloudMemcacheClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'memcache.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - cloudmemcacheModule.v1beta2.CloudMemcacheClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new cloudmemcacheModule.v1beta2.CloudMemcacheClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + cloudmemcacheModule.v1beta2.CloudMemcacheClient.servicePath; + assert.strictEqual(servicePath, 'memcache.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + cloudmemcacheModule.v1beta2.CloudMemcacheClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'memcache.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new cloudmemcacheModule.v1beta2.CloudMemcacheClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'memcache.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new cloudmemcacheModule.v1beta2.CloudMemcacheClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'memcache.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new cloudmemcacheModule.v1beta2.CloudMemcacheClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_backups.js b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_backups.js index 8c2438bfc16..f5674aa9a15 100644 --- a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_backups.js +++ b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_backups.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listBackupsAsync(request); + const iterable = metastoreClient.listBackupsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_metadata_imports.js b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_metadata_imports.js index ced0ee397ea..4794894ab6e 100644 --- a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_metadata_imports.js +++ b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_metadata_imports.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listMetadataImportsAsync(request); + const iterable = metastoreClient.listMetadataImportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_services.js b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_services.js index c59bfe735a7..64e04b879c5 100644 --- a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_services.js +++ b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore.list_services.js @@ -75,7 +75,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listServicesAsync(request); + const iterable = metastoreClient.listServicesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore_federation.list_federations.js b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore_federation.list_federations.js index c4056ab9ff9..68f60f0ae91 100644 --- a/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore_federation.list_federations.js +++ b/packages/google-cloud-metastore/samples/generated/v1/dataproc_metastore_federation.list_federations.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listFederationsAsync(request); + const iterable = metastoreClient.listFederationsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_backups.js b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_backups.js index 0f623549abb..1011a1ca2ee 100644 --- a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_backups.js +++ b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_backups.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listBackupsAsync(request); + const iterable = metastoreClient.listBackupsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_metadata_imports.js b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_metadata_imports.js index ca77fcec050..f51306432fe 100644 --- a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_metadata_imports.js +++ b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_metadata_imports.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listMetadataImportsAsync(request); + const iterable = metastoreClient.listMetadataImportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_services.js b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_services.js index c6dc1e35489..308bc7040bb 100644 --- a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_services.js +++ b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore.list_services.js @@ -75,7 +75,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listServicesAsync(request); + const iterable = metastoreClient.listServicesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore_federation.list_federations.js b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore_federation.list_federations.js index 02b6579a063..fa66d32f2f4 100644 --- a/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore_federation.list_federations.js +++ b/packages/google-cloud-metastore/samples/generated/v1alpha/dataproc_metastore_federation.list_federations.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listFederationsAsync(request); + const iterable = metastoreClient.listFederationsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_backups.js b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_backups.js index b4e350ea876..acb25f78fda 100644 --- a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_backups.js +++ b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_backups.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listBackupsAsync(request); + const iterable = metastoreClient.listBackupsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_metadata_imports.js b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_metadata_imports.js index 63f7b692733..01e76828d73 100644 --- a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_metadata_imports.js +++ b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_metadata_imports.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listMetadataImportsAsync(request); + const iterable = metastoreClient.listMetadataImportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_services.js b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_services.js index 4406f4f6c2b..c2e486e3d91 100644 --- a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_services.js +++ b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore.list_services.js @@ -75,7 +75,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listServicesAsync(request); + const iterable = metastoreClient.listServicesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore_federation.list_federations.js b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore_federation.list_federations.js index dca6ab63115..9f62bbf19c4 100644 --- a/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore_federation.list_federations.js +++ b/packages/google-cloud-metastore/samples/generated/v1beta/dataproc_metastore_federation.list_federations.js @@ -74,7 +74,7 @@ function main(parent) { }; // Run request - const iterable = await metastoreClient.listFederationsAsync(request); + const iterable = metastoreClient.listFederationsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-metastore/src/v1/dataproc_metastore_client.ts b/packages/google-cloud-metastore/src/v1/dataproc_metastore_client.ts index 6ce44bdd8cb..5df4b59359f 100644 --- a/packages/google-cloud-metastore/src/v1/dataproc_metastore_client.ts +++ b/packages/google-cloud-metastore/src/v1/dataproc_metastore_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/dataproc_metastore_client_config.json`. @@ -72,6 +73,8 @@ export class DataprocMetastoreClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -132,8 +135,20 @@ export class DataprocMetastoreClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof DataprocMetastoreClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'metastore.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -148,7 +163,7 @@ export class DataprocMetastoreClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -173,10 +188,10 @@ export class DataprocMetastoreClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -574,21 +589,52 @@ export class DataprocMetastoreClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-metastore/src/v1/dataproc_metastore_federation_client.ts b/packages/google-cloud-metastore/src/v1/dataproc_metastore_federation_client.ts index 584eb7f09a2..2185a06bb5a 100644 --- a/packages/google-cloud-metastore/src/v1/dataproc_metastore_federation_client.ts +++ b/packages/google-cloud-metastore/src/v1/dataproc_metastore_federation_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/dataproc_metastore_federation_client_config.json`. @@ -68,6 +69,8 @@ export class DataprocMetastoreFederationClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -129,8 +132,20 @@ export class DataprocMetastoreFederationClient { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof DataprocMetastoreFederationClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'metastore.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -145,7 +160,7 @@ export class DataprocMetastoreFederationClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -170,10 +185,10 @@ export class DataprocMetastoreFederationClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -443,21 +458,52 @@ export class DataprocMetastoreFederationClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_client.ts b/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_client.ts index 5379641d4ea..71aa6f29a44 100644 --- a/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_client.ts +++ b/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1alpha/dataproc_metastore_client_config.json`. @@ -72,6 +73,8 @@ export class DataprocMetastoreClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -132,8 +135,20 @@ export class DataprocMetastoreClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof DataprocMetastoreClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'metastore.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -148,7 +163,7 @@ export class DataprocMetastoreClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -173,10 +188,10 @@ export class DataprocMetastoreClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -605,21 +620,52 @@ export class DataprocMetastoreClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_federation_client.ts b/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_federation_client.ts index ff1f6202a87..50575951e7b 100644 --- a/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_federation_client.ts +++ b/packages/google-cloud-metastore/src/v1alpha/dataproc_metastore_federation_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1alpha/dataproc_metastore_federation_client_config.json`. @@ -68,6 +69,8 @@ export class DataprocMetastoreFederationClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -129,8 +132,20 @@ export class DataprocMetastoreFederationClient { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof DataprocMetastoreFederationClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'metastore.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -145,7 +160,7 @@ export class DataprocMetastoreFederationClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -170,10 +185,10 @@ export class DataprocMetastoreFederationClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -469,21 +484,52 @@ export class DataprocMetastoreFederationClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_client.ts b/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_client.ts index a19bba3dd0c..6b3eb1bbf18 100644 --- a/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_client.ts +++ b/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta/dataproc_metastore_client_config.json`. @@ -72,6 +73,8 @@ export class DataprocMetastoreClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -132,8 +135,20 @@ export class DataprocMetastoreClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof DataprocMetastoreClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'metastore.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -148,7 +163,7 @@ export class DataprocMetastoreClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -173,10 +188,10 @@ export class DataprocMetastoreClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -604,21 +619,52 @@ export class DataprocMetastoreClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_federation_client.ts b/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_federation_client.ts index ac1ad5b805e..7c3397d57d3 100644 --- a/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_federation_client.ts +++ b/packages/google-cloud-metastore/src/v1beta/dataproc_metastore_federation_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta/dataproc_metastore_federation_client_config.json`. @@ -68,6 +69,8 @@ export class DataprocMetastoreFederationClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -129,8 +132,20 @@ export class DataprocMetastoreFederationClient { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof DataprocMetastoreFederationClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'metastore.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -145,7 +160,7 @@ export class DataprocMetastoreFederationClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -170,10 +185,10 @@ export class DataprocMetastoreFederationClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -469,21 +484,52 @@ export class DataprocMetastoreFederationClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'metastore.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1.ts b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1.ts index c870567f067..416dceed0db 100644 --- a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1.ts +++ b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1.ts @@ -167,18 +167,67 @@ function stubAsyncIterationCall( describe('v1.DataprocMetastoreFederationClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient - .servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient - .apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient + .servicePath; + assert.strictEqual(servicePath, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient( + {universeDomain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient( + {universe_domain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new dataprocmetastorefederationModule.v1.DataprocMetastoreFederationClient( + {universe_domain: 'example.com', universeDomain: 'example.net'} + ); + }); }); it('has port', () => { diff --git a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1alpha.ts b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1alpha.ts index 91b0b1e91b9..3c7859e4923 100644 --- a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1alpha.ts +++ b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1alpha.ts @@ -167,18 +167,67 @@ function stubAsyncIterationCall( describe('v1alpha.DataprocMetastoreFederationClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - dataprocmetastorefederationModule.v1alpha - .DataprocMetastoreFederationClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new dataprocmetastorefederationModule.v1alpha.DataprocMetastoreFederationClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - dataprocmetastorefederationModule.v1alpha - .DataprocMetastoreFederationClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new dataprocmetastorefederationModule.v1alpha.DataprocMetastoreFederationClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + dataprocmetastorefederationModule.v1alpha + .DataprocMetastoreFederationClient.servicePath; + assert.strictEqual(servicePath, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + dataprocmetastorefederationModule.v1alpha + .DataprocMetastoreFederationClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new dataprocmetastorefederationModule.v1alpha.DataprocMetastoreFederationClient( + {universeDomain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new dataprocmetastorefederationModule.v1alpha.DataprocMetastoreFederationClient( + {universe_domain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new dataprocmetastorefederationModule.v1alpha.DataprocMetastoreFederationClient( + {universe_domain: 'example.com', universeDomain: 'example.net'} + ); + }); }); it('has port', () => { diff --git a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1beta.ts b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1beta.ts index 4822acf1e4b..c2166e8fffa 100644 --- a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1beta.ts +++ b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_federation_v1beta.ts @@ -167,18 +167,67 @@ function stubAsyncIterationCall( describe('v1beta.DataprocMetastoreFederationClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - dataprocmetastorefederationModule.v1beta - .DataprocMetastoreFederationClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new dataprocmetastorefederationModule.v1beta.DataprocMetastoreFederationClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - dataprocmetastorefederationModule.v1beta - .DataprocMetastoreFederationClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new dataprocmetastorefederationModule.v1beta.DataprocMetastoreFederationClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + dataprocmetastorefederationModule.v1beta + .DataprocMetastoreFederationClient.servicePath; + assert.strictEqual(servicePath, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + dataprocmetastorefederationModule.v1beta + .DataprocMetastoreFederationClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new dataprocmetastorefederationModule.v1beta.DataprocMetastoreFederationClient( + {universeDomain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new dataprocmetastorefederationModule.v1beta.DataprocMetastoreFederationClient( + {universe_domain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new dataprocmetastorefederationModule.v1beta.DataprocMetastoreFederationClient( + {universe_domain: 'example.com', universeDomain: 'example.net'} + ); + }); }); it('has port', () => { diff --git a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1.ts b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1.ts index 9624df7f806..7b92de39b9f 100644 --- a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1.ts +++ b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1.ts @@ -167,16 +167,62 @@ function stubAsyncIterationCall( describe('v1.DataprocMetastoreClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - dataprocmetastoreModule.v1.DataprocMetastoreClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new dataprocmetastoreModule.v1.DataprocMetastoreClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - dataprocmetastoreModule.v1.DataprocMetastoreClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new dataprocmetastoreModule.v1.DataprocMetastoreClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + dataprocmetastoreModule.v1.DataprocMetastoreClient.servicePath; + assert.strictEqual(servicePath, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + dataprocmetastoreModule.v1.DataprocMetastoreClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new dataprocmetastoreModule.v1.DataprocMetastoreClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new dataprocmetastoreModule.v1.DataprocMetastoreClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new dataprocmetastoreModule.v1.DataprocMetastoreClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1alpha.ts b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1alpha.ts index 4916abe46b9..66d67be335f 100644 --- a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1alpha.ts +++ b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1alpha.ts @@ -167,16 +167,66 @@ function stubAsyncIterationCall( describe('v1alpha.DataprocMetastoreClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - dataprocmetastoreModule.v1alpha.DataprocMetastoreClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new dataprocmetastoreModule.v1alpha.DataprocMetastoreClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - dataprocmetastoreModule.v1alpha.DataprocMetastoreClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new dataprocmetastoreModule.v1alpha.DataprocMetastoreClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + dataprocmetastoreModule.v1alpha.DataprocMetastoreClient.servicePath; + assert.strictEqual(servicePath, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + dataprocmetastoreModule.v1alpha.DataprocMetastoreClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new dataprocmetastoreModule.v1alpha.DataprocMetastoreClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new dataprocmetastoreModule.v1alpha.DataprocMetastoreClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new dataprocmetastoreModule.v1alpha.DataprocMetastoreClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1beta.ts b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1beta.ts index 4244721dd9b..df0998251d3 100644 --- a/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1beta.ts +++ b/packages/google-cloud-metastore/test/gapic_dataproc_metastore_v1beta.ts @@ -167,16 +167,64 @@ function stubAsyncIterationCall( describe('v1beta.DataprocMetastoreClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - dataprocmetastoreModule.v1beta.DataprocMetastoreClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new dataprocmetastoreModule.v1beta.DataprocMetastoreClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - dataprocmetastoreModule.v1beta.DataprocMetastoreClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new dataprocmetastoreModule.v1beta.DataprocMetastoreClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + dataprocmetastoreModule.v1beta.DataprocMetastoreClient.servicePath; + assert.strictEqual(servicePath, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + dataprocmetastoreModule.v1beta.DataprocMetastoreClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'metastore.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new dataprocmetastoreModule.v1beta.DataprocMetastoreClient( + {universeDomain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new dataprocmetastoreModule.v1beta.DataprocMetastoreClient( + {universe_domain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'metastore.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new dataprocmetastoreModule.v1beta.DataprocMetastoreClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_assets.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_assets.js index 2d99eae9ed3..260a28024bc 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_assets.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_assets.js @@ -67,7 +67,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listAssetsAsync(request); + const iterable = migrationcenterClient.listAssetsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_error_frames.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_error_frames.js index fcfc7d5a5b8..f09f466bac1 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_error_frames.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_error_frames.js @@ -60,7 +60,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listErrorFramesAsync(request); + const iterable = migrationcenterClient.listErrorFramesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_groups.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_groups.js index 54569db8d59..4d21a38897e 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_groups.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_groups.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listGroupsAsync(request); + const iterable = migrationcenterClient.listGroupsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_data_files.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_data_files.js index 97d592948c7..8fe5cab848c 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_data_files.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_data_files.js @@ -68,7 +68,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listImportDataFilesAsync(request); + const iterable = migrationcenterClient.listImportDataFilesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_jobs.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_jobs.js index 146a5d44a0f..af4833ee19e 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_jobs.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_import_jobs.js @@ -68,7 +68,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listImportJobsAsync(request); + const iterable = migrationcenterClient.listImportJobsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_preference_sets.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_preference_sets.js index 479bd88c620..76f8908be07 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_preference_sets.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_preference_sets.js @@ -60,7 +60,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listPreferenceSetsAsync(request); + const iterable = migrationcenterClient.listPreferenceSetsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_report_configs.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_report_configs.js index b4ab6a4b9b5..f1152b25ae6 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_report_configs.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_report_configs.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listReportConfigsAsync(request); + const iterable = migrationcenterClient.listReportConfigsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_reports.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_reports.js index facf3ddcec4..b6efc90d460 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_reports.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_reports.js @@ -67,7 +67,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listReportsAsync(request); + const iterable = migrationcenterClient.listReportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_sources.js b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_sources.js index 14506c6001a..53ac3cfa204 100644 --- a/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_sources.js +++ b/packages/google-cloud-migrationcenter/samples/generated/v1/migration_center.list_sources.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await migrationcenterClient.listSourcesAsync(request); + const iterable = migrationcenterClient.listSourcesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-migrationcenter/src/v1/migration_center_client.ts b/packages/google-cloud-migrationcenter/src/v1/migration_center_client.ts index 3c052c9d9a4..8ddded2ff17 100644 --- a/packages/google-cloud-migrationcenter/src/v1/migration_center_client.ts +++ b/packages/google-cloud-migrationcenter/src/v1/migration_center_client.ts @@ -33,6 +33,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/migration_center_client_config.json`. @@ -54,6 +55,8 @@ export class MigrationCenterClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -113,8 +116,20 @@ export class MigrationCenterClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof MigrationCenterClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'migrationcenter.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -129,7 +144,7 @@ export class MigrationCenterClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -154,10 +169,10 @@ export class MigrationCenterClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.locationsClient = new this._gaxModule.LocationsClient( @@ -709,21 +724,52 @@ export class MigrationCenterClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'migrationcenter.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'migrationcenter.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-migrationcenter/test/gapic_migration_center_v1.ts b/packages/google-cloud-migrationcenter/test/gapic_migration_center_v1.ts index e98e2aac85c..a22f57d6e3d 100644 --- a/packages/google-cloud-migrationcenter/test/gapic_migration_center_v1.ts +++ b/packages/google-cloud-migrationcenter/test/gapic_migration_center_v1.ts @@ -166,16 +166,62 @@ function stubAsyncIterationCall( describe('v1.MigrationCenterClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - migrationcenterModule.v1.MigrationCenterClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new migrationcenterModule.v1.MigrationCenterClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'migrationcenter.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - migrationcenterModule.v1.MigrationCenterClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new migrationcenterModule.v1.MigrationCenterClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + migrationcenterModule.v1.MigrationCenterClient.servicePath; + assert.strictEqual(servicePath, 'migrationcenter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + migrationcenterModule.v1.MigrationCenterClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'migrationcenter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new migrationcenterModule.v1.MigrationCenterClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'migrationcenter.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new migrationcenterModule.v1.MigrationCenterClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'migrationcenter.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new migrationcenterModule.v1.MigrationCenterClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_active_directories.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_active_directories.js index 25b69b9d322..361da61d43d 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_active_directories.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_active_directories.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listActiveDirectoriesAsync(request); + const iterable = netappClient.listActiveDirectoriesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_policies.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_policies.js index 434b743d3e1..6b2ee9b8abf 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_policies.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_policies.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listBackupPoliciesAsync(request); + const iterable = netappClient.listBackupPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_vaults.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_vaults.js index 76eeca7b9d5..1fd798229b2 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_vaults.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backup_vaults.js @@ -65,7 +65,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listBackupVaultsAsync(request); + const iterable = netappClient.listBackupVaultsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backups.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backups.js index 310bfd59414..59a98ac21b5 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backups.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_backups.js @@ -76,7 +76,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listBackupsAsync(request); + const iterable = netappClient.listBackupsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_kms_configs.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_kms_configs.js index eba8501918a..b51b6693e23 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_kms_configs.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_kms_configs.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listKmsConfigsAsync(request); + const iterable = netappClient.listKmsConfigsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_replications.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_replications.js index c9a94bb86ae..620ed160bc1 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_replications.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_replications.js @@ -65,7 +65,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listReplicationsAsync(request); + const iterable = netappClient.listReplicationsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_snapshots.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_snapshots.js index caa0eea816c..1e388ac553c 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_snapshots.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_snapshots.js @@ -65,7 +65,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listSnapshotsAsync(request); + const iterable = netappClient.listSnapshotsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_storage_pools.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_storage_pools.js index 6c63e4882fe..c1a775dc165 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_storage_pools.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_storage_pools.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listStoragePoolsAsync(request); + const iterable = netappClient.listStoragePoolsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_volumes.js b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_volumes.js index cd9cd6ef840..1476d22e18d 100644 --- a/packages/google-cloud-netapp/samples/generated/v1/net_app.list_volumes.js +++ b/packages/google-cloud-netapp/samples/generated/v1/net_app.list_volumes.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await netappClient.listVolumesAsync(request); + const iterable = netappClient.listVolumesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-netapp/src/v1/net_app_client.ts b/packages/google-cloud-netapp/src/v1/net_app_client.ts index 32233783b65..31421c33b8d 100644 --- a/packages/google-cloud-netapp/src/v1/net_app_client.ts +++ b/packages/google-cloud-netapp/src/v1/net_app_client.ts @@ -33,6 +33,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/net_app_client_config.json`. @@ -54,6 +55,8 @@ export class NetAppClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -113,8 +116,20 @@ export class NetAppClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NetAppClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'netapp.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -129,7 +144,7 @@ export class NetAppClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -154,10 +169,10 @@ export class NetAppClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.locationsClient = new this._gaxModule.LocationsClient( @@ -810,21 +825,52 @@ export class NetAppClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'netapp.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'netapp.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-netapp/test/gapic_net_app_v1.ts b/packages/google-cloud-netapp/test/gapic_net_app_v1.ts index 793fd2f0a8b..d4e5a326871 100644 --- a/packages/google-cloud-netapp/test/gapic_net_app_v1.ts +++ b/packages/google-cloud-netapp/test/gapic_net_app_v1.ts @@ -166,14 +166,60 @@ function stubAsyncIterationCall( describe('v1.NetAppClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = netappModule.v1.NetAppClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new netappModule.v1.NetAppClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'netapp.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = netappModule.v1.NetAppClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new netappModule.v1.NetAppClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = netappModule.v1.NetAppClient.servicePath; + assert.strictEqual(servicePath, 'netapp.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = netappModule.v1.NetAppClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'netapp.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new netappModule.v1.NetAppClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'netapp.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new netappModule.v1.NetAppClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'netapp.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new netappModule.v1.NetAppClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_groups.js b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_groups.js index caf3f9483ed..8b5b89ded83 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_groups.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_groups.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listGroupsAsync(request); + const iterable = networkconnectivityClient.listGroupsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hub_spokes.js b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hub_spokes.js index f8eceb44970..8eb62cd4af6 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hub_spokes.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hub_spokes.js @@ -79,7 +79,7 @@ function main(name) { }; // Run request - const iterable = await networkconnectivityClient.listHubSpokesAsync(request); + const iterable = networkconnectivityClient.listHubSpokesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hubs.js b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hubs.js index 5c098e360fc..40aa1404dac 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hubs.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_hubs.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listHubsAsync(request); + const iterable = networkconnectivityClient.listHubsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_route_tables.js b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_route_tables.js index b612899ee01..45ef554a2fa 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_route_tables.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_route_tables.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listRouteTablesAsync(request); + const iterable = networkconnectivityClient.listRouteTablesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_routes.js b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_routes.js index 1dbca584e7a..e11a3aa9790 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_routes.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_routes.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listRoutesAsync(request); + const iterable = networkconnectivityClient.listRoutesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_spokes.js b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_spokes.js index 05123f6e52f..06304fb06bb 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_spokes.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1/hub_service.list_spokes.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listSpokesAsync(request); + const iterable = networkconnectivityClient.listSpokesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1/policy_based_routing_service.list_policy_based_routes.js b/packages/google-cloud-networkconnectivity/samples/generated/v1/policy_based_routing_service.list_policy_based_routes.js index fbb50090b9e..cdc6382a196 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1/policy_based_routing_service.list_policy_based_routes.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1/policy_based_routing_service.list_policy_based_routes.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listPolicyBasedRoutesAsync(request); + const iterable = networkconnectivityClient.listPolicyBasedRoutesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_hubs.js b/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_hubs.js index e3f06790d5c..5a66df44876 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_hubs.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_hubs.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listHubsAsync(request); + const iterable = networkconnectivityClient.listHubsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_spokes.js b/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_spokes.js index 03705bd795c..aacfeb6efb3 100644 --- a/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_spokes.js +++ b/packages/google-cloud-networkconnectivity/samples/generated/v1alpha1/hub_service.list_spokes.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await networkconnectivityClient.listSpokesAsync(request); + const iterable = networkconnectivityClient.listSpokesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkconnectivity/src/v1/hub_service_client.ts b/packages/google-cloud-networkconnectivity/src/v1/hub_service_client.ts index a03d1b24138..b47089abc2e 100644 --- a/packages/google-cloud-networkconnectivity/src/v1/hub_service_client.ts +++ b/packages/google-cloud-networkconnectivity/src/v1/hub_service_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/hub_service_client_config.json`. @@ -58,6 +59,8 @@ export class HubServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -118,8 +121,20 @@ export class HubServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof HubServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkconnectivity.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -134,7 +149,7 @@ export class HubServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -159,10 +174,10 @@ export class HubServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -555,21 +570,52 @@ export class HubServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkconnectivity.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkconnectivity.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkconnectivity/src/v1/policy_based_routing_service_client.ts b/packages/google-cloud-networkconnectivity/src/v1/policy_based_routing_service_client.ts index f32a5aab6f9..3e25eacd869 100644 --- a/packages/google-cloud-networkconnectivity/src/v1/policy_based_routing_service_client.ts +++ b/packages/google-cloud-networkconnectivity/src/v1/policy_based_routing_service_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/policy_based_routing_service_client_config.json`. @@ -57,6 +58,8 @@ export class PolicyBasedRoutingServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -118,8 +121,20 @@ export class PolicyBasedRoutingServiceClient { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof PolicyBasedRoutingServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkconnectivity.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -134,7 +149,7 @@ export class PolicyBasedRoutingServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -159,10 +174,10 @@ export class PolicyBasedRoutingServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -449,21 +464,52 @@ export class PolicyBasedRoutingServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkconnectivity.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkconnectivity.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkconnectivity/src/v1alpha1/hub_service_client.ts b/packages/google-cloud-networkconnectivity/src/v1alpha1/hub_service_client.ts index 282a46f38e2..40a5bb83260 100644 --- a/packages/google-cloud-networkconnectivity/src/v1alpha1/hub_service_client.ts +++ b/packages/google-cloud-networkconnectivity/src/v1alpha1/hub_service_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1alpha1/hub_service_client_config.json`. @@ -55,6 +56,8 @@ export class HubServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -113,8 +116,20 @@ export class HubServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof HubServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkconnectivity.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -129,7 +144,7 @@ export class HubServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -154,10 +169,10 @@ export class HubServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -457,21 +472,52 @@ export class HubServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkconnectivity.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkconnectivity.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1.ts b/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1.ts index d389b544b4c..0f97ace731e 100644 --- a/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1.ts +++ b/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1.ts @@ -167,14 +167,60 @@ function stubAsyncIterationCall( describe('v1.HubServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = hubserviceModule.v1.HubServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new hubserviceModule.v1.HubServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkconnectivity.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = hubserviceModule.v1.HubServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new hubserviceModule.v1.HubServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = hubserviceModule.v1.HubServiceClient.servicePath; + assert.strictEqual(servicePath, 'networkconnectivity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = hubserviceModule.v1.HubServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkconnectivity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new hubserviceModule.v1.HubServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkconnectivity.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new hubserviceModule.v1.HubServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkconnectivity.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new hubserviceModule.v1.HubServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1alpha1.ts b/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1alpha1.ts index f05cde44471..42dd691b010 100644 --- a/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1alpha1.ts +++ b/packages/google-cloud-networkconnectivity/test/gapic_hub_service_v1alpha1.ts @@ -161,16 +161,62 @@ function stubAsyncIterationCall( describe('v1alpha1.HubServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - hubserviceModule.v1alpha1.HubServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new hubserviceModule.v1alpha1.HubServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkconnectivity.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - hubserviceModule.v1alpha1.HubServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new hubserviceModule.v1alpha1.HubServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + hubserviceModule.v1alpha1.HubServiceClient.servicePath; + assert.strictEqual(servicePath, 'networkconnectivity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + hubserviceModule.v1alpha1.HubServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkconnectivity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new hubserviceModule.v1alpha1.HubServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkconnectivity.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new hubserviceModule.v1alpha1.HubServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkconnectivity.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new hubserviceModule.v1alpha1.HubServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkconnectivity/test/gapic_policy_based_routing_service_v1.ts b/packages/google-cloud-networkconnectivity/test/gapic_policy_based_routing_service_v1.ts index a3121e44908..4b98d55ea68 100644 --- a/packages/google-cloud-networkconnectivity/test/gapic_policy_based_routing_service_v1.ts +++ b/packages/google-cloud-networkconnectivity/test/gapic_policy_based_routing_service_v1.ts @@ -167,18 +167,68 @@ function stubAsyncIterationCall( describe('v1.PolicyBasedRoutingServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient - .servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkconnectivity.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient - .apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient + .servicePath; + assert.strictEqual(servicePath, 'networkconnectivity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkconnectivity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkconnectivity.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkconnectivity.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new policybasedroutingserviceModule.v1.PolicyBasedRoutingServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkmanagement/samples/generated/v1/reachability_service.list_connectivity_tests.js b/packages/google-cloud-networkmanagement/samples/generated/v1/reachability_service.list_connectivity_tests.js index 5319a357f07..11366d5248a 100644 --- a/packages/google-cloud-networkmanagement/samples/generated/v1/reachability_service.list_connectivity_tests.js +++ b/packages/google-cloud-networkmanagement/samples/generated/v1/reachability_service.list_connectivity_tests.js @@ -78,7 +78,7 @@ function main(parent) { }; // Run request - const iterable = await networkmanagementClient.listConnectivityTestsAsync(request); + const iterable = networkmanagementClient.listConnectivityTestsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkmanagement/samples/generated/v1beta1/reachability_service.list_connectivity_tests.js b/packages/google-cloud-networkmanagement/samples/generated/v1beta1/reachability_service.list_connectivity_tests.js index 381907b9eda..0f13d2d7bd8 100644 --- a/packages/google-cloud-networkmanagement/samples/generated/v1beta1/reachability_service.list_connectivity_tests.js +++ b/packages/google-cloud-networkmanagement/samples/generated/v1beta1/reachability_service.list_connectivity_tests.js @@ -78,7 +78,7 @@ function main(parent) { }; // Run request - const iterable = await networkmanagementClient.listConnectivityTestsAsync(request); + const iterable = networkmanagementClient.listConnectivityTestsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkmanagement/src/v1/reachability_service_client.ts b/packages/google-cloud-networkmanagement/src/v1/reachability_service_client.ts index f8e7d16f1cc..ad66d9c1534 100644 --- a/packages/google-cloud-networkmanagement/src/v1/reachability_service_client.ts +++ b/packages/google-cloud-networkmanagement/src/v1/reachability_service_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/reachability_service_client_config.json`. @@ -59,6 +60,8 @@ export class ReachabilityServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -117,8 +120,20 @@ export class ReachabilityServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ReachabilityServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkmanagement.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -133,7 +148,7 @@ export class ReachabilityServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -158,10 +173,10 @@ export class ReachabilityServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -412,21 +427,52 @@ export class ReachabilityServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkmanagement.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkmanagement.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkmanagement/src/v1beta1/reachability_service_client.ts b/packages/google-cloud-networkmanagement/src/v1beta1/reachability_service_client.ts index a157defa1cd..6be1cf633c2 100644 --- a/packages/google-cloud-networkmanagement/src/v1beta1/reachability_service_client.ts +++ b/packages/google-cloud-networkmanagement/src/v1beta1/reachability_service_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/reachability_service_client_config.json`. @@ -59,6 +60,8 @@ export class ReachabilityServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -117,8 +120,20 @@ export class ReachabilityServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ReachabilityServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkmanagement.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -133,7 +148,7 @@ export class ReachabilityServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -158,10 +173,10 @@ export class ReachabilityServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -412,21 +427,52 @@ export class ReachabilityServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkmanagement.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkmanagement.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1.ts b/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1.ts index 453d87127d6..d77d5955495 100644 --- a/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1.ts +++ b/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1.ts @@ -161,16 +161,64 @@ function stubAsyncIterationCall( describe('v1.ReachabilityServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - reachabilityserviceModule.v1.ReachabilityServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new reachabilityserviceModule.v1.ReachabilityServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkmanagement.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - reachabilityserviceModule.v1.ReachabilityServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new reachabilityserviceModule.v1.ReachabilityServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + reachabilityserviceModule.v1.ReachabilityServiceClient.servicePath; + assert.strictEqual(servicePath, 'networkmanagement.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + reachabilityserviceModule.v1.ReachabilityServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkmanagement.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new reachabilityserviceModule.v1.ReachabilityServiceClient( + {universeDomain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkmanagement.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new reachabilityserviceModule.v1.ReachabilityServiceClient( + {universe_domain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkmanagement.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new reachabilityserviceModule.v1.ReachabilityServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1beta1.ts b/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1beta1.ts index 98258687546..49050e8a04f 100644 --- a/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1beta1.ts +++ b/packages/google-cloud-networkmanagement/test/gapic_reachability_service_v1beta1.ts @@ -161,16 +161,68 @@ function stubAsyncIterationCall( describe('v1beta1.ReachabilityServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - reachabilityserviceModule.v1beta1.ReachabilityServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new reachabilityserviceModule.v1beta1.ReachabilityServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkmanagement.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - reachabilityserviceModule.v1beta1.ReachabilityServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new reachabilityserviceModule.v1beta1.ReachabilityServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + reachabilityserviceModule.v1beta1.ReachabilityServiceClient + .servicePath; + assert.strictEqual(servicePath, 'networkmanagement.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + reachabilityserviceModule.v1beta1.ReachabilityServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkmanagement.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new reachabilityserviceModule.v1beta1.ReachabilityServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkmanagement.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new reachabilityserviceModule.v1beta1.ReachabilityServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkmanagement.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new reachabilityserviceModule.v1beta1.ReachabilityServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_authorization_policies.js b/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_authorization_policies.js index 82fd0e885ce..ac6ddecc253 100644 --- a/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_authorization_policies.js +++ b/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_authorization_policies.js @@ -59,7 +59,7 @@ function main(parent) { }; // Run request - const iterable = await networksecurityClient.listAuthorizationPoliciesAsync(request); + const iterable = networksecurityClient.listAuthorizationPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_client_tls_policies.js b/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_client_tls_policies.js index e5a456f07c6..eafb4f93f83 100644 --- a/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_client_tls_policies.js +++ b/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_client_tls_policies.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await networksecurityClient.listClientTlsPoliciesAsync(request); + const iterable = networksecurityClient.listClientTlsPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_server_tls_policies.js b/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_server_tls_policies.js index cdc126ce9f0..3f97c7b1686 100644 --- a/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_server_tls_policies.js +++ b/packages/google-cloud-networksecurity/samples/generated/v1/network_security.list_server_tls_policies.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await networksecurityClient.listServerTlsPoliciesAsync(request); + const iterable = networksecurityClient.listServerTlsPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_authorization_policies.js b/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_authorization_policies.js index 800c5e655c8..4b2da3d9eb1 100644 --- a/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_authorization_policies.js +++ b/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_authorization_policies.js @@ -59,7 +59,7 @@ function main(parent) { }; // Run request - const iterable = await networksecurityClient.listAuthorizationPoliciesAsync(request); + const iterable = networksecurityClient.listAuthorizationPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_client_tls_policies.js b/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_client_tls_policies.js index 3c55a54b159..a1e930d3e0f 100644 --- a/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_client_tls_policies.js +++ b/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_client_tls_policies.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await networksecurityClient.listClientTlsPoliciesAsync(request); + const iterable = networksecurityClient.listClientTlsPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_server_tls_policies.js b/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_server_tls_policies.js index bbff65c7bed..f999d6242b3 100644 --- a/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_server_tls_policies.js +++ b/packages/google-cloud-networksecurity/samples/generated/v1beta1/network_security.list_server_tls_policies.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await networksecurityClient.listServerTlsPoliciesAsync(request); + const iterable = networksecurityClient.listServerTlsPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networksecurity/src/v1/network_security_client.ts b/packages/google-cloud-networksecurity/src/v1/network_security_client.ts index f17816d456a..3459e446246 100644 --- a/packages/google-cloud-networksecurity/src/v1/network_security_client.ts +++ b/packages/google-cloud-networksecurity/src/v1/network_security_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/network_security_client_config.json`. @@ -58,6 +59,8 @@ export class NetworkSecurityClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -118,8 +121,20 @@ export class NetworkSecurityClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NetworkSecurityClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networksecurity.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -134,7 +149,7 @@ export class NetworkSecurityClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -159,10 +174,10 @@ export class NetworkSecurityClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -536,21 +551,52 @@ export class NetworkSecurityClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networksecurity.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networksecurity.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networksecurity/src/v1beta1/network_security_client.ts b/packages/google-cloud-networksecurity/src/v1beta1/network_security_client.ts index b2ce3230a27..53a8bdeca9f 100644 --- a/packages/google-cloud-networksecurity/src/v1beta1/network_security_client.ts +++ b/packages/google-cloud-networksecurity/src/v1beta1/network_security_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/network_security_client_config.json`. @@ -58,6 +59,8 @@ export class NetworkSecurityClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -118,8 +121,20 @@ export class NetworkSecurityClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NetworkSecurityClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networksecurity.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -134,7 +149,7 @@ export class NetworkSecurityClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -159,10 +174,10 @@ export class NetworkSecurityClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -537,21 +552,52 @@ export class NetworkSecurityClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networksecurity.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networksecurity.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networksecurity/test/gapic_network_security_v1.ts b/packages/google-cloud-networksecurity/test/gapic_network_security_v1.ts index 7aa10cc5a88..de3d00e9688 100644 --- a/packages/google-cloud-networksecurity/test/gapic_network_security_v1.ts +++ b/packages/google-cloud-networksecurity/test/gapic_network_security_v1.ts @@ -167,16 +167,62 @@ function stubAsyncIterationCall( describe('v1.NetworkSecurityClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - networksecurityModule.v1.NetworkSecurityClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new networksecurityModule.v1.NetworkSecurityClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networksecurity.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - networksecurityModule.v1.NetworkSecurityClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new networksecurityModule.v1.NetworkSecurityClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + networksecurityModule.v1.NetworkSecurityClient.servicePath; + assert.strictEqual(servicePath, 'networksecurity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + networksecurityModule.v1.NetworkSecurityClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networksecurity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new networksecurityModule.v1.NetworkSecurityClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networksecurity.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new networksecurityModule.v1.NetworkSecurityClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networksecurity.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new networksecurityModule.v1.NetworkSecurityClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networksecurity/test/gapic_network_security_v1beta1.ts b/packages/google-cloud-networksecurity/test/gapic_network_security_v1beta1.ts index e8e57469318..de1a17bdf64 100644 --- a/packages/google-cloud-networksecurity/test/gapic_network_security_v1beta1.ts +++ b/packages/google-cloud-networksecurity/test/gapic_network_security_v1beta1.ts @@ -167,16 +167,62 @@ function stubAsyncIterationCall( describe('v1beta1.NetworkSecurityClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - networksecurityModule.v1beta1.NetworkSecurityClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new networksecurityModule.v1beta1.NetworkSecurityClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networksecurity.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - networksecurityModule.v1beta1.NetworkSecurityClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new networksecurityModule.v1beta1.NetworkSecurityClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + networksecurityModule.v1beta1.NetworkSecurityClient.servicePath; + assert.strictEqual(servicePath, 'networksecurity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + networksecurityModule.v1beta1.NetworkSecurityClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networksecurity.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new networksecurityModule.v1beta1.NetworkSecurityClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networksecurity.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new networksecurityModule.v1beta1.NetworkSecurityClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networksecurity.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new networksecurityModule.v1beta1.NetworkSecurityClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_endpoint_policies.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_endpoint_policies.js index 0a4acf5c0b0..3c0c5bdf594 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_endpoint_policies.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_endpoint_policies.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listEndpointPoliciesAsync(request); + const iterable = networkservicesClient.listEndpointPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_gateways.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_gateways.js index 9a1be1a2ae1..93055049cf3 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_gateways.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_gateways.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listGatewaysAsync(request); + const iterable = networkservicesClient.listGatewaysAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_grpc_routes.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_grpc_routes.js index 75fba62e8a8..64413a4b9a7 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_grpc_routes.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_grpc_routes.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listGrpcRoutesAsync(request); + const iterable = networkservicesClient.listGrpcRoutesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_http_routes.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_http_routes.js index be2081338e4..0b9d46555c7 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_http_routes.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_http_routes.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listHttpRoutesAsync(request); + const iterable = networkservicesClient.listHttpRoutesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_meshes.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_meshes.js index 976d7ce2bfb..8e1558883fd 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_meshes.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_meshes.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listMeshesAsync(request); + const iterable = networkservicesClient.listMeshesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_service_bindings.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_service_bindings.js index 9be4a267490..9022da95ca9 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_service_bindings.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_service_bindings.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listServiceBindingsAsync(request); + const iterable = networkservicesClient.listServiceBindingsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tcp_routes.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tcp_routes.js index 42fa5000f86..458631705d0 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tcp_routes.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tcp_routes.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listTcpRoutesAsync(request); + const iterable = networkservicesClient.listTcpRoutesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tls_routes.js b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tls_routes.js index 215b925a590..c7db9d9aac3 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tls_routes.js +++ b/packages/google-cloud-networkservices/samples/generated/v1/network_services.list_tls_routes.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listTlsRoutesAsync(request); + const iterable = networkservicesClient.listTlsRoutesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_route_extensions.js b/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_route_extensions.js index 30e0f30fc67..c228ab994a0 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_route_extensions.js +++ b/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_route_extensions.js @@ -65,7 +65,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listLbRouteExtensionsAsync(request); + const iterable = networkservicesClient.listLbRouteExtensionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_traffic_extensions.js b/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_traffic_extensions.js index 51e2e62571c..73f0d9006d6 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_traffic_extensions.js +++ b/packages/google-cloud-networkservices/samples/generated/v1beta1/dep_service.list_lb_traffic_extensions.js @@ -65,7 +65,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listLbTrafficExtensionsAsync(request); + const iterable = networkservicesClient.listLbTrafficExtensionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/samples/generated/v1beta1/network_services.list_endpoint_policies.js b/packages/google-cloud-networkservices/samples/generated/v1beta1/network_services.list_endpoint_policies.js index 7cb99e1cff1..2c3b5bec2e8 100644 --- a/packages/google-cloud-networkservices/samples/generated/v1beta1/network_services.list_endpoint_policies.js +++ b/packages/google-cloud-networkservices/samples/generated/v1beta1/network_services.list_endpoint_policies.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await networkservicesClient.listEndpointPoliciesAsync(request); + const iterable = networkservicesClient.listEndpointPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-networkservices/src/v1/network_services_client.ts b/packages/google-cloud-networkservices/src/v1/network_services_client.ts index 8e23a6aa4b0..63a098093ba 100644 --- a/packages/google-cloud-networkservices/src/v1/network_services_client.ts +++ b/packages/google-cloud-networkservices/src/v1/network_services_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/network_services_client_config.json`. @@ -55,6 +56,8 @@ export class NetworkServicesClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -115,8 +118,20 @@ export class NetworkServicesClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NetworkServicesClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkservices.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -131,7 +146,7 @@ export class NetworkServicesClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -156,10 +171,10 @@ export class NetworkServicesClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -771,21 +786,52 @@ export class NetworkServicesClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkservices.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkservices.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkservices/src/v1beta1/dep_service_client.ts b/packages/google-cloud-networkservices/src/v1beta1/dep_service_client.ts index 47067fe5a10..f4f79baad28 100644 --- a/packages/google-cloud-networkservices/src/v1beta1/dep_service_client.ts +++ b/packages/google-cloud-networkservices/src/v1beta1/dep_service_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/dep_service_client_config.json`. @@ -52,6 +53,8 @@ export class DepServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class DepServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof DepServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkservices.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class DepServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class DepServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -457,21 +472,52 @@ export class DepServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkservices.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkservices.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkservices/src/v1beta1/network_services_client.ts b/packages/google-cloud-networkservices/src/v1beta1/network_services_client.ts index 6f1dafcb5d7..9355d360d3e 100644 --- a/packages/google-cloud-networkservices/src/v1beta1/network_services_client.ts +++ b/packages/google-cloud-networkservices/src/v1beta1/network_services_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/network_services_client_config.json`. @@ -51,6 +52,8 @@ export class NetworkServicesClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -109,8 +112,20 @@ export class NetworkServicesClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NetworkServicesClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'networkservices.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -125,7 +140,7 @@ export class NetworkServicesClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -150,10 +165,10 @@ export class NetworkServicesClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -384,21 +399,52 @@ export class NetworkServicesClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkservices.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'networkservices.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-networkservices/test/gapic_dep_service_v1beta1.ts b/packages/google-cloud-networkservices/test/gapic_dep_service_v1beta1.ts index 37b258b99a3..17db2ef906d 100644 --- a/packages/google-cloud-networkservices/test/gapic_dep_service_v1beta1.ts +++ b/packages/google-cloud-networkservices/test/gapic_dep_service_v1beta1.ts @@ -161,14 +161,62 @@ function stubAsyncIterationCall( describe('v1beta1.DepServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = depserviceModule.v1beta1.DepServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new depserviceModule.v1beta1.DepServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkservices.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = depserviceModule.v1beta1.DepServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new depserviceModule.v1beta1.DepServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + depserviceModule.v1beta1.DepServiceClient.servicePath; + assert.strictEqual(servicePath, 'networkservices.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + depserviceModule.v1beta1.DepServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkservices.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new depserviceModule.v1beta1.DepServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkservices.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new depserviceModule.v1beta1.DepServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkservices.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new depserviceModule.v1beta1.DepServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkservices/test/gapic_network_services_v1.ts b/packages/google-cloud-networkservices/test/gapic_network_services_v1.ts index 15853c67d10..25a4d73a3e1 100644 --- a/packages/google-cloud-networkservices/test/gapic_network_services_v1.ts +++ b/packages/google-cloud-networkservices/test/gapic_network_services_v1.ts @@ -167,16 +167,62 @@ function stubAsyncIterationCall( describe('v1.NetworkServicesClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - networkservicesModule.v1.NetworkServicesClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new networkservicesModule.v1.NetworkServicesClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkservices.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - networkservicesModule.v1.NetworkServicesClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new networkservicesModule.v1.NetworkServicesClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + networkservicesModule.v1.NetworkServicesClient.servicePath; + assert.strictEqual(servicePath, 'networkservices.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + networkservicesModule.v1.NetworkServicesClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkservices.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new networkservicesModule.v1.NetworkServicesClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkservices.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new networkservicesModule.v1.NetworkServicesClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkservices.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new networkservicesModule.v1.NetworkServicesClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-networkservices/test/gapic_network_services_v1beta1.ts b/packages/google-cloud-networkservices/test/gapic_network_services_v1beta1.ts index ae2eefdd4b1..1eb4b6b28f7 100644 --- a/packages/google-cloud-networkservices/test/gapic_network_services_v1beta1.ts +++ b/packages/google-cloud-networkservices/test/gapic_network_services_v1beta1.ts @@ -161,16 +161,62 @@ function stubAsyncIterationCall( describe('v1beta1.NetworkServicesClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - networkservicesModule.v1beta1.NetworkServicesClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new networkservicesModule.v1beta1.NetworkServicesClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkservices.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - networkservicesModule.v1beta1.NetworkServicesClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new networkservicesModule.v1beta1.NetworkServicesClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + networkservicesModule.v1beta1.NetworkServicesClient.servicePath; + assert.strictEqual(servicePath, 'networkservices.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + networkservicesModule.v1beta1.NetworkServicesClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'networkservices.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new networkservicesModule.v1beta1.NetworkServicesClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkservices.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new networkservicesModule.v1beta1.NetworkServicesClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'networkservices.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new networkservicesModule.v1beta1.NetworkServicesClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-notebooks/samples/generated/v1/managed_notebook_service.list_runtimes.js b/packages/google-cloud-notebooks/samples/generated/v1/managed_notebook_service.list_runtimes.js index b5c34924570..229e515bee3 100644 --- a/packages/google-cloud-notebooks/samples/generated/v1/managed_notebook_service.list_runtimes.js +++ b/packages/google-cloud-notebooks/samples/generated/v1/managed_notebook_service.list_runtimes.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listRuntimesAsync(request); + const iterable = notebooksClient.listRuntimesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_environments.js b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_environments.js index 2d2f4b91777..aa096e438a3 100644 --- a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_environments.js +++ b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_environments.js @@ -55,7 +55,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listEnvironmentsAsync(request); + const iterable = notebooksClient.listEnvironmentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_executions.js b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_executions.js index 30ee0b4dc4c..f71ba25b492 100644 --- a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_executions.js +++ b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_executions.js @@ -66,7 +66,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listExecutionsAsync(request); + const iterable = notebooksClient.listExecutionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_instances.js b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_instances.js index ec59ad96b2c..1887edb59bb 100644 --- a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_instances.js +++ b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_instances.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listInstancesAsync(request); + const iterable = notebooksClient.listInstancesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_schedules.js b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_schedules.js index cd93151464c..554b33be21e 100644 --- a/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_schedules.js +++ b/packages/google-cloud-notebooks/samples/generated/v1/notebook_service.list_schedules.js @@ -64,7 +64,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listSchedulesAsync(request); + const iterable = notebooksClient.listSchedulesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_environments.js b/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_environments.js index 34449eb6c31..395f33cf912 100644 --- a/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_environments.js +++ b/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_environments.js @@ -55,7 +55,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listEnvironmentsAsync(request); + const iterable = notebooksClient.listEnvironmentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_instances.js b/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_instances.js index 426dfaed3fb..8e4d73b6507 100644 --- a/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_instances.js +++ b/packages/google-cloud-notebooks/samples/generated/v1beta1/notebook_service.list_instances.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listInstancesAsync(request); + const iterable = notebooksClient.listInstancesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/samples/generated/v2/notebook_service.list_instances.js b/packages/google-cloud-notebooks/samples/generated/v2/notebook_service.list_instances.js index a5b9e7d70b0..e7c223af46f 100644 --- a/packages/google-cloud-notebooks/samples/generated/v2/notebook_service.list_instances.js +++ b/packages/google-cloud-notebooks/samples/generated/v2/notebook_service.list_instances.js @@ -65,7 +65,7 @@ function main(parent) { }; // Run request - const iterable = await notebooksClient.listInstancesAsync(request); + const iterable = notebooksClient.listInstancesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-notebooks/src/v1/managed_notebook_service_client.ts b/packages/google-cloud-notebooks/src/v1/managed_notebook_service_client.ts index 76a8a630153..c6dbcb39811 100644 --- a/packages/google-cloud-notebooks/src/v1/managed_notebook_service_client.ts +++ b/packages/google-cloud-notebooks/src/v1/managed_notebook_service_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/managed_notebook_service_client_config.json`. @@ -56,6 +57,8 @@ export class ManagedNotebookServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -117,8 +120,20 @@ export class ManagedNotebookServiceClient { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof ManagedNotebookServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'notebooks.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -133,7 +148,7 @@ export class ManagedNotebookServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -158,10 +173,10 @@ export class ManagedNotebookServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -512,21 +527,52 @@ export class ManagedNotebookServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-notebooks/src/v1/notebook_service_client.ts b/packages/google-cloud-notebooks/src/v1/notebook_service_client.ts index 5b487363618..2099055bf2d 100644 --- a/packages/google-cloud-notebooks/src/v1/notebook_service_client.ts +++ b/packages/google-cloud-notebooks/src/v1/notebook_service_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/notebook_service_client_config.json`. @@ -56,6 +57,8 @@ export class NotebookServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -116,8 +119,20 @@ export class NotebookServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NotebookServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'notebooks.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -132,7 +147,7 @@ export class NotebookServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -157,10 +172,10 @@ export class NotebookServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -699,21 +714,52 @@ export class NotebookServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-notebooks/src/v1beta1/notebook_service_client.ts b/packages/google-cloud-notebooks/src/v1beta1/notebook_service_client.ts index ca36249b431..30416a6b548 100644 --- a/packages/google-cloud-notebooks/src/v1beta1/notebook_service_client.ts +++ b/packages/google-cloud-notebooks/src/v1beta1/notebook_service_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/notebook_service_client_config.json`. @@ -56,6 +57,8 @@ export class NotebookServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -116,8 +119,20 @@ export class NotebookServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NotebookServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'notebooks.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -132,7 +147,7 @@ export class NotebookServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -157,10 +172,10 @@ export class NotebookServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -545,21 +560,52 @@ export class NotebookServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-notebooks/src/v2/notebook_service_client.ts b/packages/google-cloud-notebooks/src/v2/notebook_service_client.ts index 2cec42a68cc..32a6b44c61a 100644 --- a/packages/google-cloud-notebooks/src/v2/notebook_service_client.ts +++ b/packages/google-cloud-notebooks/src/v2/notebook_service_client.ts @@ -35,6 +35,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v2/notebook_service_client_config.json`. @@ -56,6 +57,8 @@ export class NotebookServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -116,8 +119,20 @@ export class NotebookServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof NotebookServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'notebooks.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -132,7 +147,7 @@ export class NotebookServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -157,10 +172,10 @@ export class NotebookServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); @@ -469,21 +484,52 @@ export class NotebookServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'notebooks.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-notebooks/test/gapic_managed_notebook_service_v1.ts b/packages/google-cloud-notebooks/test/gapic_managed_notebook_service_v1.ts index 8620b91f2d6..02a553bfc9e 100644 --- a/packages/google-cloud-notebooks/test/gapic_managed_notebook_service_v1.ts +++ b/packages/google-cloud-notebooks/test/gapic_managed_notebook_service_v1.ts @@ -167,18 +167,68 @@ function stubAsyncIterationCall( describe('v1.ManagedNotebookServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - managednotebookserviceModule.v1.ManagedNotebookServiceClient - .servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new managednotebookserviceModule.v1.ManagedNotebookServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - managednotebookserviceModule.v1.ManagedNotebookServiceClient - .apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new managednotebookserviceModule.v1.ManagedNotebookServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + managednotebookserviceModule.v1.ManagedNotebookServiceClient + .servicePath; + assert.strictEqual(servicePath, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + managednotebookserviceModule.v1.ManagedNotebookServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new managednotebookserviceModule.v1.ManagedNotebookServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new managednotebookserviceModule.v1.ManagedNotebookServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new managednotebookserviceModule.v1.ManagedNotebookServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-notebooks/test/gapic_notebook_service_v1.ts b/packages/google-cloud-notebooks/test/gapic_notebook_service_v1.ts index e38252a526f..d21726f8194 100644 --- a/packages/google-cloud-notebooks/test/gapic_notebook_service_v1.ts +++ b/packages/google-cloud-notebooks/test/gapic_notebook_service_v1.ts @@ -167,16 +167,62 @@ function stubAsyncIterationCall( describe('v1.NotebookServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - notebookserviceModule.v1.NotebookServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new notebookserviceModule.v1.NotebookServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - notebookserviceModule.v1.NotebookServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new notebookserviceModule.v1.NotebookServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + notebookserviceModule.v1.NotebookServiceClient.servicePath; + assert.strictEqual(servicePath, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + notebookserviceModule.v1.NotebookServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new notebookserviceModule.v1.NotebookServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new notebookserviceModule.v1.NotebookServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new notebookserviceModule.v1.NotebookServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-notebooks/test/gapic_notebook_service_v1beta1.ts b/packages/google-cloud-notebooks/test/gapic_notebook_service_v1beta1.ts index 81d26563fdd..2f4136ad23e 100644 --- a/packages/google-cloud-notebooks/test/gapic_notebook_service_v1beta1.ts +++ b/packages/google-cloud-notebooks/test/gapic_notebook_service_v1beta1.ts @@ -167,16 +167,62 @@ function stubAsyncIterationCall( describe('v1beta1.NotebookServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - notebookserviceModule.v1beta1.NotebookServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new notebookserviceModule.v1beta1.NotebookServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - notebookserviceModule.v1beta1.NotebookServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new notebookserviceModule.v1beta1.NotebookServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + notebookserviceModule.v1beta1.NotebookServiceClient.servicePath; + assert.strictEqual(servicePath, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + notebookserviceModule.v1beta1.NotebookServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new notebookserviceModule.v1beta1.NotebookServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new notebookserviceModule.v1beta1.NotebookServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new notebookserviceModule.v1beta1.NotebookServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-notebooks/test/gapic_notebook_service_v2.ts b/packages/google-cloud-notebooks/test/gapic_notebook_service_v2.ts index 4ad0b2cbb99..1a90f47dab6 100644 --- a/packages/google-cloud-notebooks/test/gapic_notebook_service_v2.ts +++ b/packages/google-cloud-notebooks/test/gapic_notebook_service_v2.ts @@ -167,16 +167,62 @@ function stubAsyncIterationCall( describe('v2.NotebookServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - notebookserviceModule.v2.NotebookServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new notebookserviceModule.v2.NotebookServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - notebookserviceModule.v2.NotebookServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new notebookserviceModule.v2.NotebookServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + notebookserviceModule.v2.NotebookServiceClient.servicePath; + assert.strictEqual(servicePath, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + notebookserviceModule.v2.NotebookServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'notebooks.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new notebookserviceModule.v2.NotebookServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new notebookserviceModule.v2.NotebookServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'notebooks.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new notebookserviceModule.v2.NotebookServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-optimization/src/v1/fleet_routing_client.ts b/packages/google-cloud-optimization/src/v1/fleet_routing_client.ts index 62138fdbe7c..985ed60b807 100644 --- a/packages/google-cloud-optimization/src/v1/fleet_routing_client.ts +++ b/packages/google-cloud-optimization/src/v1/fleet_routing_client.ts @@ -29,6 +29,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/fleet_routing_client_config.json`. @@ -66,6 +67,8 @@ export class FleetRoutingClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -123,8 +126,20 @@ export class FleetRoutingClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof FleetRoutingClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'cloudoptimization.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -139,7 +154,7 @@ export class FleetRoutingClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -164,10 +179,10 @@ export class FleetRoutingClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -308,21 +323,52 @@ export class FleetRoutingClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'cloudoptimization.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'cloudoptimization.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-optimization/test/gapic_fleet_routing_v1.ts b/packages/google-cloud-optimization/test/gapic_fleet_routing_v1.ts index 8eba3466d1a..b2136fb246a 100644 --- a/packages/google-cloud-optimization/test/gapic_fleet_routing_v1.ts +++ b/packages/google-cloud-optimization/test/gapic_fleet_routing_v1.ts @@ -121,14 +121,62 @@ function stubAsyncIterationCall( describe('v1.FleetRoutingClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = fleetroutingModule.v1.FleetRoutingClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new fleetroutingModule.v1.FleetRoutingClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'cloudoptimization.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = fleetroutingModule.v1.FleetRoutingClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new fleetroutingModule.v1.FleetRoutingClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + fleetroutingModule.v1.FleetRoutingClient.servicePath; + assert.strictEqual(servicePath, 'cloudoptimization.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + fleetroutingModule.v1.FleetRoutingClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'cloudoptimization.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new fleetroutingModule.v1.FleetRoutingClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'cloudoptimization.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new fleetroutingModule.v1.FleetRoutingClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'cloudoptimization.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new fleetroutingModule.v1.FleetRoutingClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/environments.list_environments.js b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/environments.list_environments.js index f94b93a2b36..39900edd8d9 100644 --- a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/environments.list_environments.js +++ b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/environments.list_environments.js @@ -54,7 +54,7 @@ function main() { }; // Run request - const iterable = await serviceClient.listEnvironmentsAsync(request); + const iterable = serviceClient.listEnvironmentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/image_versions.list_image_versions.js b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/image_versions.list_image_versions.js index 6229496922c..1c70cd85eb6 100644 --- a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/image_versions.list_image_versions.js +++ b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1/image_versions.list_image_versions.js @@ -58,7 +58,7 @@ function main() { }; // Run request - const iterable = await serviceClient.listImageVersionsAsync(request); + const iterable = serviceClient.listImageVersionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/environments.list_environments.js b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/environments.list_environments.js index a5b4ca1132d..86654938f4d 100644 --- a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/environments.list_environments.js +++ b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/environments.list_environments.js @@ -54,7 +54,7 @@ function main() { }; // Run request - const iterable = await serviceClient.listEnvironmentsAsync(request); + const iterable = serviceClient.listEnvironmentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/image_versions.list_image_versions.js b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/image_versions.list_image_versions.js index 022aee2ac7f..8a9d5aa745a 100644 --- a/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/image_versions.list_image_versions.js +++ b/packages/google-cloud-orchestration-airflow-service/samples/generated/v1beta1/image_versions.list_image_versions.js @@ -58,7 +58,7 @@ function main() { }; // Run request - const iterable = await serviceClient.listImageVersionsAsync(request); + const iterable = serviceClient.listImageVersionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-orchestration-airflow-service/src/v1/environments_client.ts b/packages/google-cloud-orchestration-airflow-service/src/v1/environments_client.ts index afbbb4ebfb6..f2f7f96ac1e 100644 --- a/packages/google-cloud-orchestration-airflow-service/src/v1/environments_client.ts +++ b/packages/google-cloud-orchestration-airflow-service/src/v1/environments_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/environments_client_config.json`. @@ -52,6 +53,8 @@ export class EnvironmentsClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class EnvironmentsClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof EnvironmentsClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'composer.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class EnvironmentsClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class EnvironmentsClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -392,21 +407,52 @@ export class EnvironmentsClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-orchestration-airflow-service/src/v1/image_versions_client.ts b/packages/google-cloud-orchestration-airflow-service/src/v1/image_versions_client.ts index 46d40fbc970..cf442bb46d2 100644 --- a/packages/google-cloud-orchestration-airflow-service/src/v1/image_versions_client.ts +++ b/packages/google-cloud-orchestration-airflow-service/src/v1/image_versions_client.ts @@ -29,6 +29,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/image_versions_client_config.json`. @@ -50,6 +51,8 @@ export class ImageVersionsClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -107,8 +110,20 @@ export class ImageVersionsClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ImageVersionsClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'composer.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -123,7 +138,7 @@ export class ImageVersionsClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -148,10 +163,10 @@ export class ImageVersionsClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -275,21 +290,52 @@ export class ImageVersionsClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-orchestration-airflow-service/src/v1beta1/environments_client.ts b/packages/google-cloud-orchestration-airflow-service/src/v1beta1/environments_client.ts index 4ba77869b7a..ca17d4f2d1a 100644 --- a/packages/google-cloud-orchestration-airflow-service/src/v1beta1/environments_client.ts +++ b/packages/google-cloud-orchestration-airflow-service/src/v1beta1/environments_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/environments_client_config.json`. @@ -52,6 +53,8 @@ export class EnvironmentsClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class EnvironmentsClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof EnvironmentsClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'composer.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class EnvironmentsClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class EnvironmentsClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -416,21 +431,52 @@ export class EnvironmentsClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-orchestration-airflow-service/src/v1beta1/image_versions_client.ts b/packages/google-cloud-orchestration-airflow-service/src/v1beta1/image_versions_client.ts index 2af0b20d4d2..1c71a7d4890 100644 --- a/packages/google-cloud-orchestration-airflow-service/src/v1beta1/image_versions_client.ts +++ b/packages/google-cloud-orchestration-airflow-service/src/v1beta1/image_versions_client.ts @@ -29,6 +29,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/image_versions_client_config.json`. @@ -50,6 +51,8 @@ export class ImageVersionsClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -107,8 +110,20 @@ export class ImageVersionsClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ImageVersionsClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'composer.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -123,7 +138,7 @@ export class ImageVersionsClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -148,10 +163,10 @@ export class ImageVersionsClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -275,21 +290,52 @@ export class ImageVersionsClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'composer.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1.ts b/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1.ts index 307f0d185f6..ce9f51e0687 100644 --- a/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1.ts +++ b/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1.ts @@ -161,14 +161,62 @@ function stubAsyncIterationCall( describe('v1.EnvironmentsClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = environmentsModule.v1.EnvironmentsClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new environmentsModule.v1.EnvironmentsClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = environmentsModule.v1.EnvironmentsClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new environmentsModule.v1.EnvironmentsClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + environmentsModule.v1.EnvironmentsClient.servicePath; + assert.strictEqual(servicePath, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + environmentsModule.v1.EnvironmentsClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new environmentsModule.v1.EnvironmentsClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new environmentsModule.v1.EnvironmentsClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new environmentsModule.v1.EnvironmentsClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1beta1.ts b/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1beta1.ts index 47bc2e8b1dd..25dad8f23f1 100644 --- a/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1beta1.ts +++ b/packages/google-cloud-orchestration-airflow-service/test/gapic_environments_v1beta1.ts @@ -161,16 +161,62 @@ function stubAsyncIterationCall( describe('v1beta1.EnvironmentsClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - environmentsModule.v1beta1.EnvironmentsClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new environmentsModule.v1beta1.EnvironmentsClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - environmentsModule.v1beta1.EnvironmentsClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new environmentsModule.v1beta1.EnvironmentsClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + environmentsModule.v1beta1.EnvironmentsClient.servicePath; + assert.strictEqual(servicePath, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + environmentsModule.v1beta1.EnvironmentsClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new environmentsModule.v1beta1.EnvironmentsClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new environmentsModule.v1beta1.EnvironmentsClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new environmentsModule.v1beta1.EnvironmentsClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1.ts b/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1.ts index a892ef0212c..d5c6547510a 100644 --- a/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1.ts +++ b/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1.ts @@ -129,16 +129,62 @@ function stubAsyncIterationCall( describe('v1.ImageVersionsClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - imageversionsModule.v1.ImageVersionsClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new imageversionsModule.v1.ImageVersionsClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageversionsModule.v1.ImageVersionsClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new imageversionsModule.v1.ImageVersionsClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + imageversionsModule.v1.ImageVersionsClient.servicePath; + assert.strictEqual(servicePath, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + imageversionsModule.v1.ImageVersionsClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new imageversionsModule.v1.ImageVersionsClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new imageversionsModule.v1.ImageVersionsClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new imageversionsModule.v1.ImageVersionsClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1beta1.ts b/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1beta1.ts index 340d9af7457..16ddd99ed1b 100644 --- a/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1beta1.ts +++ b/packages/google-cloud-orchestration-airflow-service/test/gapic_image_versions_v1beta1.ts @@ -129,16 +129,62 @@ function stubAsyncIterationCall( describe('v1beta1.ImageVersionsClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - imageversionsModule.v1beta1.ImageVersionsClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new imageversionsModule.v1beta1.ImageVersionsClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageversionsModule.v1beta1.ImageVersionsClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new imageversionsModule.v1beta1.ImageVersionsClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + imageversionsModule.v1beta1.ImageVersionsClient.servicePath; + assert.strictEqual(servicePath, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + imageversionsModule.v1beta1.ImageVersionsClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'composer.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new imageversionsModule.v1beta1.ImageVersionsClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new imageversionsModule.v1beta1.ImageVersionsClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'composer.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new imageversionsModule.v1beta1.ImageVersionsClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_constraints.js b/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_constraints.js index a4f2164d9e3..19a4753affb 100644 --- a/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_constraints.js +++ b/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_constraints.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await orgpolicyClient.listConstraintsAsync(request); + const iterable = orgpolicyClient.listConstraintsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_custom_constraints.js b/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_custom_constraints.js index 1873e7632fb..f9090cd9197 100644 --- a/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_custom_constraints.js +++ b/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_custom_constraints.js @@ -60,7 +60,7 @@ function main(parent) { }; // Run request - const iterable = await orgpolicyClient.listCustomConstraintsAsync(request); + const iterable = orgpolicyClient.listCustomConstraintsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_policies.js b/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_policies.js index 6b4afc9f481..73a2aa54dd1 100644 --- a/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_policies.js +++ b/packages/google-cloud-orgpolicy/samples/generated/v2/org_policy.list_policies.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await orgpolicyClient.listPoliciesAsync(request); + const iterable = orgpolicyClient.listPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-orgpolicy/src/v2/org_policy_client.ts b/packages/google-cloud-orgpolicy/src/v2/org_policy_client.ts index b9ccfb0573a..0412499ea89 100644 --- a/packages/google-cloud-orgpolicy/src/v2/org_policy_client.ts +++ b/packages/google-cloud-orgpolicy/src/v2/org_policy_client.ts @@ -29,6 +29,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v2/org_policy_client_config.json`. @@ -69,6 +70,8 @@ export class OrgPolicyClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -126,8 +129,20 @@ export class OrgPolicyClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof OrgPolicyClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'orgpolicy.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -142,7 +157,7 @@ export class OrgPolicyClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -167,10 +182,10 @@ export class OrgPolicyClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -340,21 +355,52 @@ export class OrgPolicyClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'orgpolicy.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'orgpolicy.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-orgpolicy/test/gapic_org_policy_v2.ts b/packages/google-cloud-orgpolicy/test/gapic_org_policy_v2.ts index a004d4a092b..ad11838c217 100644 --- a/packages/google-cloud-orgpolicy/test/gapic_org_policy_v2.ts +++ b/packages/google-cloud-orgpolicy/test/gapic_org_policy_v2.ts @@ -129,14 +129,60 @@ function stubAsyncIterationCall( describe('v2.OrgPolicyClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = orgpolicyModule.v2.OrgPolicyClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new orgpolicyModule.v2.OrgPolicyClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'orgpolicy.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = orgpolicyModule.v2.OrgPolicyClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new orgpolicyModule.v2.OrgPolicyClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = orgpolicyModule.v2.OrgPolicyClient.servicePath; + assert.strictEqual(servicePath, 'orgpolicy.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = orgpolicyModule.v2.OrgPolicyClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'orgpolicy.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'orgpolicy.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'orgpolicy.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new orgpolicyModule.v2.OrgPolicyClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_deployments.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_deployments.js index 6df215d33c8..c88b6e20753 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_deployments.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_deployments.js @@ -57,7 +57,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listPatchDeploymentsAsync(request); + const iterable = osconfigClient.listPatchDeploymentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_job_instance_details.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_job_instance_details.js index ce14ecac12e..840a3b6e3a3 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_job_instance_details.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_job_instance_details.js @@ -62,7 +62,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listPatchJobInstanceDetailsAsync(request); + const iterable = osconfigClient.listPatchJobInstanceDetailsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_jobs.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_jobs.js index 2b2de7edbd9..108b399955c 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_jobs.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_service.list_patch_jobs.js @@ -61,7 +61,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listPatchJobsAsync(request); + const iterable = osconfigClient.listPatchJobsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_inventories.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_inventories.js index a78eaf22416..f2462881bf2 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_inventories.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_inventories.js @@ -68,7 +68,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listInventoriesAsync(request); + const iterable = osconfigClient.listInventoriesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_reports.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_reports.js index 653f3200851..6973ed9279b 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_reports.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_reports.js @@ -78,7 +78,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listOSPolicyAssignmentReportsAsync(request); + const iterable = osconfigClient.listOSPolicyAssignmentReportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_revisions.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_revisions.js index 29fea541990..c41d9e9f0b2 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_revisions.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignment_revisions.js @@ -56,7 +56,7 @@ function main(name) { }; // Run request - const iterable = await osconfigClient.listOSPolicyAssignmentRevisionsAsync(request); + const iterable = osconfigClient.listOSPolicyAssignmentRevisionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignments.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignments.js index 9580d54b928..b80631b2bc9 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignments.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_o_s_policy_assignments.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listOSPolicyAssignmentsAsync(request); + const iterable = osconfigClient.listOSPolicyAssignmentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_vulnerability_reports.js b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_vulnerability_reports.js index 0cd8f48be35..6feef375bda 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_vulnerability_reports.js +++ b/packages/google-cloud-osconfig/samples/generated/v1/os_config_zonal_service.list_vulnerability_reports.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listVulnerabilityReportsAsync(request); + const iterable = osconfigClient.listVulnerabilityReportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_instance_o_s_policies_compliances.js b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_instance_o_s_policies_compliances.js index 48ee0a21449..ecc15928b7d 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_instance_o_s_policies_compliances.js +++ b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_instance_o_s_policies_compliances.js @@ -64,7 +64,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listInstanceOSPoliciesCompliancesAsync(request); + const iterable = osconfigClient.listInstanceOSPoliciesCompliancesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_inventories.js b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_inventories.js index 61726a11977..1e67479d6ef 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_inventories.js +++ b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_inventories.js @@ -68,7 +68,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listInventoriesAsync(request); + const iterable = osconfigClient.listInventoriesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_reports.js b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_reports.js index 47d6b3c4550..7de9dc18b78 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_reports.js +++ b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_reports.js @@ -78,7 +78,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listOSPolicyAssignmentReportsAsync(request); + const iterable = osconfigClient.listOSPolicyAssignmentReportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_revisions.js b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_revisions.js index aee74f79b9d..84110204dfd 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_revisions.js +++ b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignment_revisions.js @@ -56,7 +56,7 @@ function main(name) { }; // Run request - const iterable = await osconfigClient.listOSPolicyAssignmentRevisionsAsync(request); + const iterable = osconfigClient.listOSPolicyAssignmentRevisionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignments.js b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignments.js index db42055da8f..349cb1b4300 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignments.js +++ b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_o_s_policy_assignments.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listOSPolicyAssignmentsAsync(request); + const iterable = osconfigClient.listOSPolicyAssignmentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_vulnerability_reports.js b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_vulnerability_reports.js index b0b1c6c2a0f..d2776c67c39 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_vulnerability_reports.js +++ b/packages/google-cloud-osconfig/samples/generated/v1alpha/os_config_zonal_service.list_vulnerability_reports.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listVulnerabilityReportsAsync(request); + const iterable = osconfigClient.listVulnerabilityReportsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_guest_policies.js b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_guest_policies.js index 8ce1a3bb843..188f8b8bd75 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_guest_policies.js +++ b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_guest_policies.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listGuestPoliciesAsync(request); + const iterable = osconfigClient.listGuestPoliciesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_deployments.js b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_deployments.js index 9ad45d3b2bf..839093001ef 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_deployments.js +++ b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_deployments.js @@ -55,7 +55,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listPatchDeploymentsAsync(request); + const iterable = osconfigClient.listPatchDeploymentsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_job_instance_details.js b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_job_instance_details.js index d4aefda3d72..58bd32b6266 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_job_instance_details.js +++ b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_job_instance_details.js @@ -61,7 +61,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listPatchJobInstanceDetailsAsync(request); + const iterable = osconfigClient.listPatchJobInstanceDetailsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_jobs.js b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_jobs.js index 625595712c3..f6a68c1e791 100644 --- a/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_jobs.js +++ b/packages/google-cloud-osconfig/samples/generated/v1beta/os_config_service.list_patch_jobs.js @@ -61,7 +61,7 @@ function main(parent) { }; // Run request - const iterable = await osconfigClient.listPatchJobsAsync(request); + const iterable = osconfigClient.listPatchJobsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-osconfig/src/v1/os_config_service_client.ts b/packages/google-cloud-osconfig/src/v1/os_config_service_client.ts index 8d3c574ca12..4aae1f260f2 100644 --- a/packages/google-cloud-osconfig/src/v1/os_config_service_client.ts +++ b/packages/google-cloud-osconfig/src/v1/os_config_service_client.ts @@ -29,6 +29,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/os_config_service_client_config.json`. @@ -53,6 +54,8 @@ export class OsConfigServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class OsConfigServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof OsConfigServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'osconfig.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class OsConfigServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class OsConfigServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -315,21 +330,52 @@ export class OsConfigServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-osconfig/src/v1/os_config_zonal_service_client.ts b/packages/google-cloud-osconfig/src/v1/os_config_zonal_service_client.ts index bfc5cc86c32..db00597ea00 100644 --- a/packages/google-cloud-osconfig/src/v1/os_config_zonal_service_client.ts +++ b/packages/google-cloud-osconfig/src/v1/os_config_zonal_service_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/os_config_zonal_service_client_config.json`. @@ -55,6 +56,8 @@ export class OsConfigZonalServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -113,8 +116,20 @@ export class OsConfigZonalServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof OsConfigZonalServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'osconfig.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -129,7 +144,7 @@ export class OsConfigZonalServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -154,10 +169,10 @@ export class OsConfigZonalServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -405,21 +420,52 @@ export class OsConfigZonalServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-osconfig/src/v1alpha/os_config_zonal_service_client.ts b/packages/google-cloud-osconfig/src/v1alpha/os_config_zonal_service_client.ts index 5279267a3a2..1039c768e39 100644 --- a/packages/google-cloud-osconfig/src/v1alpha/os_config_zonal_service_client.ts +++ b/packages/google-cloud-osconfig/src/v1alpha/os_config_zonal_service_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1alpha/os_config_zonal_service_client_config.json`. @@ -55,6 +56,8 @@ export class OsConfigZonalServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -113,8 +116,20 @@ export class OsConfigZonalServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof OsConfigZonalServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'osconfig.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -129,7 +144,7 @@ export class OsConfigZonalServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -154,10 +169,10 @@ export class OsConfigZonalServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -411,21 +426,52 @@ export class OsConfigZonalServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-osconfig/src/v1beta/os_config_service_client.ts b/packages/google-cloud-osconfig/src/v1beta/os_config_service_client.ts index 281715e71bf..f9fdb19fc53 100644 --- a/packages/google-cloud-osconfig/src/v1beta/os_config_service_client.ts +++ b/packages/google-cloud-osconfig/src/v1beta/os_config_service_client.ts @@ -29,6 +29,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta/os_config_service_client_config.json`. @@ -53,6 +54,8 @@ export class OsConfigServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class OsConfigServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof OsConfigServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'osconfig.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class OsConfigServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class OsConfigServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -317,21 +332,52 @@ export class OsConfigServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'osconfig.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-osconfig/test/gapic_os_config_service_v1.ts b/packages/google-cloud-osconfig/test/gapic_os_config_service_v1.ts index 9fd55d16295..9ff33e61b14 100644 --- a/packages/google-cloud-osconfig/test/gapic_os_config_service_v1.ts +++ b/packages/google-cloud-osconfig/test/gapic_os_config_service_v1.ts @@ -129,16 +129,62 @@ function stubAsyncIterationCall( describe('v1.OsConfigServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - osconfigserviceModule.v1.OsConfigServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new osconfigserviceModule.v1.OsConfigServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - osconfigserviceModule.v1.OsConfigServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new osconfigserviceModule.v1.OsConfigServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + osconfigserviceModule.v1.OsConfigServiceClient.servicePath; + assert.strictEqual(servicePath, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + osconfigserviceModule.v1.OsConfigServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new osconfigserviceModule.v1.OsConfigServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new osconfigserviceModule.v1.OsConfigServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new osconfigserviceModule.v1.OsConfigServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-osconfig/test/gapic_os_config_service_v1beta.ts b/packages/google-cloud-osconfig/test/gapic_os_config_service_v1beta.ts index 592b65fd3d9..de1fab9e476 100644 --- a/packages/google-cloud-osconfig/test/gapic_os_config_service_v1beta.ts +++ b/packages/google-cloud-osconfig/test/gapic_os_config_service_v1beta.ts @@ -129,16 +129,62 @@ function stubAsyncIterationCall( describe('v1beta.OsConfigServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - osconfigserviceModule.v1beta.OsConfigServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new osconfigserviceModule.v1beta.OsConfigServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - osconfigserviceModule.v1beta.OsConfigServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new osconfigserviceModule.v1beta.OsConfigServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + osconfigserviceModule.v1beta.OsConfigServiceClient.servicePath; + assert.strictEqual(servicePath, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + osconfigserviceModule.v1beta.OsConfigServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new osconfigserviceModule.v1beta.OsConfigServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new osconfigserviceModule.v1beta.OsConfigServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new osconfigserviceModule.v1beta.OsConfigServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1.ts b/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1.ts index 66be5261ff5..c1ddfaddd07 100644 --- a/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1.ts +++ b/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1.ts @@ -161,16 +161,66 @@ function stubAsyncIterationCall( describe('v1.OsConfigZonalServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - osconfigzonalserviceModule.v1.OsConfigZonalServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new osconfigzonalserviceModule.v1.OsConfigZonalServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - osconfigzonalserviceModule.v1.OsConfigZonalServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new osconfigzonalserviceModule.v1.OsConfigZonalServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + osconfigzonalserviceModule.v1.OsConfigZonalServiceClient.servicePath; + assert.strictEqual(servicePath, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + osconfigzonalserviceModule.v1.OsConfigZonalServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new osconfigzonalserviceModule.v1.OsConfigZonalServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new osconfigzonalserviceModule.v1.OsConfigZonalServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new osconfigzonalserviceModule.v1.OsConfigZonalServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1alpha.ts b/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1alpha.ts index 0b5aad2914f..b61f1a49bef 100644 --- a/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1alpha.ts +++ b/packages/google-cloud-osconfig/test/gapic_os_config_zonal_service_v1alpha.ts @@ -161,18 +161,68 @@ function stubAsyncIterationCall( describe('v1alpha.OsConfigZonalServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient - .servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient - .apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient + .servicePath; + assert.strictEqual(servicePath, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'osconfig.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'osconfig.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new osconfigzonalserviceModule.v1alpha.OsConfigZonalServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-oslogin/src/v1/os_login_service_client.ts b/packages/google-cloud-oslogin/src/v1/os_login_service_client.ts index dd3407ddabd..0b0ca156a37 100644 --- a/packages/google-cloud-oslogin/src/v1/os_login_service_client.ts +++ b/packages/google-cloud-oslogin/src/v1/os_login_service_client.ts @@ -27,6 +27,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/os_login_service_client_config.json`. @@ -51,6 +52,8 @@ export class OsLoginServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -108,8 +111,20 @@ export class OsLoginServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof OsLoginServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'oslogin.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -124,7 +139,7 @@ export class OsLoginServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -149,10 +164,10 @@ export class OsLoginServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -276,21 +291,52 @@ export class OsLoginServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'oslogin.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'oslogin.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-oslogin/src/v1beta/os_login_service_client.ts b/packages/google-cloud-oslogin/src/v1beta/os_login_service_client.ts index 83597da2ddb..3941b5d9f8c 100644 --- a/packages/google-cloud-oslogin/src/v1beta/os_login_service_client.ts +++ b/packages/google-cloud-oslogin/src/v1beta/os_login_service_client.ts @@ -27,6 +27,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta/os_login_service_client_config.json`. @@ -51,6 +52,8 @@ export class OsLoginServiceClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -108,8 +111,20 @@ export class OsLoginServiceClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof OsLoginServiceClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'oslogin.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -124,7 +139,7 @@ export class OsLoginServiceClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -149,10 +164,10 @@ export class OsLoginServiceClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -277,21 +292,52 @@ export class OsLoginServiceClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'oslogin.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'oslogin.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-oslogin/test/gapic_os_login_service_v1.ts b/packages/google-cloud-oslogin/test/gapic_os_login_service_v1.ts index aedeff6060c..a110cbe3c60 100644 --- a/packages/google-cloud-oslogin/test/gapic_os_login_service_v1.ts +++ b/packages/google-cloud-oslogin/test/gapic_os_login_service_v1.ts @@ -66,16 +66,62 @@ function stubSimpleCallWithCallback( describe('v1.OsLoginServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - osloginserviceModule.v1.OsLoginServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new osloginserviceModule.v1.OsLoginServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'oslogin.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - osloginserviceModule.v1.OsLoginServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new osloginserviceModule.v1.OsLoginServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + osloginserviceModule.v1.OsLoginServiceClient.servicePath; + assert.strictEqual(servicePath, 'oslogin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + osloginserviceModule.v1.OsLoginServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'oslogin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new osloginserviceModule.v1.OsLoginServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'oslogin.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new osloginserviceModule.v1.OsLoginServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'oslogin.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new osloginserviceModule.v1.OsLoginServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-oslogin/test/gapic_os_login_service_v1beta.ts b/packages/google-cloud-oslogin/test/gapic_os_login_service_v1beta.ts index 3ff02226c90..b34ecd52d4a 100644 --- a/packages/google-cloud-oslogin/test/gapic_os_login_service_v1beta.ts +++ b/packages/google-cloud-oslogin/test/gapic_os_login_service_v1beta.ts @@ -66,16 +66,62 @@ function stubSimpleCallWithCallback( describe('v1beta.OsLoginServiceClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - osloginserviceModule.v1beta.OsLoginServiceClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new osloginserviceModule.v1beta.OsLoginServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'oslogin.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - osloginserviceModule.v1beta.OsLoginServiceClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new osloginserviceModule.v1beta.OsLoginServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + osloginserviceModule.v1beta.OsLoginServiceClient.servicePath; + assert.strictEqual(servicePath, 'oslogin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + osloginserviceModule.v1beta.OsLoginServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'oslogin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new osloginserviceModule.v1beta.OsLoginServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'oslogin.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new osloginserviceModule.v1beta.OsLoginServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'oslogin.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new osloginserviceModule.v1beta.OsLoginServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts b/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts index db44c2062b0..bb12a7b67f4 100644 --- a/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts +++ b/packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts @@ -27,6 +27,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/phishing_protection_service_v1_beta1_client_config.json`. @@ -48,6 +49,8 @@ export class PhishingProtectionServiceV1Beta1Client { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -106,8 +109,20 @@ export class PhishingProtectionServiceV1Beta1Client { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof PhishingProtectionServiceV1Beta1Client; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'phishingprotection.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -122,7 +137,7 @@ export class PhishingProtectionServiceV1Beta1Client { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -147,10 +162,10 @@ export class PhishingProtectionServiceV1Beta1Client { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -263,21 +278,52 @@ export class PhishingProtectionServiceV1Beta1Client { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'phishingprotection.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'phishingprotection.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts b/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts index 6af0131c79d..f09371ae97c 100644 --- a/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts +++ b/packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts @@ -66,18 +66,67 @@ function stubSimpleCallWithCallback( describe('v1beta1.PhishingProtectionServiceV1Beta1Client', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - phishingprotectionservicev1beta1Module.v1beta1 - .PhishingProtectionServiceV1Beta1Client.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'phishingprotection.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - phishingprotectionservicev1beta1Module.v1beta1 - .PhishingProtectionServiceV1Beta1Client.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + phishingprotectionservicev1beta1Module.v1beta1 + .PhishingProtectionServiceV1Beta1Client.servicePath; + assert.strictEqual(servicePath, 'phishingprotection.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + phishingprotectionservicev1beta1Module.v1beta1 + .PhishingProtectionServiceV1Beta1Client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'phishingprotection.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + {universeDomain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'phishingprotection.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + {universe_domain: 'example.com'} + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'phishingprotection.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client( + {universe_domain: 'example.com', universeDomain: 'example.net'} + ); + }); }); it('has port', () => { diff --git a/packages/google-cloud-policysimulator/samples/generated/v1/simulator.list_replay_results.js b/packages/google-cloud-policysimulator/samples/generated/v1/simulator.list_replay_results.js index 328d2cd9d5d..0910432ca31 100644 --- a/packages/google-cloud-policysimulator/samples/generated/v1/simulator.list_replay_results.js +++ b/packages/google-cloud-policysimulator/samples/generated/v1/simulator.list_replay_results.js @@ -66,7 +66,7 @@ function main(parent) { }; // Run request - const iterable = await policysimulatorClient.listReplayResultsAsync(request); + const iterable = policysimulatorClient.listReplayResultsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-policysimulator/src/v1/simulator_client.ts b/packages/google-cloud-policysimulator/src/v1/simulator_client.ts index 1d968ee762a..2a95a9a2582 100644 --- a/packages/google-cloud-policysimulator/src/v1/simulator_client.ts +++ b/packages/google-cloud-policysimulator/src/v1/simulator_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/simulator_client_config.json`. @@ -63,6 +64,8 @@ export class SimulatorClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -121,8 +124,20 @@ export class SimulatorClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SimulatorClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'policysimulator.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -137,7 +152,7 @@ export class SimulatorClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -162,10 +177,10 @@ export class SimulatorClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -366,21 +381,52 @@ export class SimulatorClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policysimulator.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policysimulator.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-policysimulator/test/gapic_simulator_v1.ts b/packages/google-cloud-policysimulator/test/gapic_simulator_v1.ts index 8638ee813f8..1b3efb2e6be 100644 --- a/packages/google-cloud-policysimulator/test/gapic_simulator_v1.ts +++ b/packages/google-cloud-policysimulator/test/gapic_simulator_v1.ts @@ -161,14 +161,60 @@ function stubAsyncIterationCall( describe('v1.SimulatorClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = simulatorModule.v1.SimulatorClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new simulatorModule.v1.SimulatorClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'policysimulator.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = simulatorModule.v1.SimulatorClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new simulatorModule.v1.SimulatorClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = simulatorModule.v1.SimulatorClient.servicePath; + assert.strictEqual(servicePath, 'policysimulator.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = simulatorModule.v1.SimulatorClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'policysimulator.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new simulatorModule.v1.SimulatorClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policysimulator.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new simulatorModule.v1.SimulatorClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policysimulator.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new simulatorModule.v1.SimulatorClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-policytroubleshooter-iam/src/v3/policy_troubleshooter_client.ts b/packages/google-cloud-policytroubleshooter-iam/src/v3/policy_troubleshooter_client.ts index 037289a5813..fe8eff670d7 100644 --- a/packages/google-cloud-policytroubleshooter-iam/src/v3/policy_troubleshooter_client.ts +++ b/packages/google-cloud-policytroubleshooter-iam/src/v3/policy_troubleshooter_client.ts @@ -27,6 +27,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v3/policy_troubleshooter_client_config.json`. @@ -50,6 +51,8 @@ export class PolicyTroubleshooterClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -106,8 +109,20 @@ export class PolicyTroubleshooterClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof PolicyTroubleshooterClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'policytroubleshooter.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -122,7 +137,7 @@ export class PolicyTroubleshooterClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -147,10 +162,10 @@ export class PolicyTroubleshooterClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -254,21 +269,52 @@ export class PolicyTroubleshooterClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policytroubleshooter.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policytroubleshooter.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-policytroubleshooter-iam/src/v3beta/policy_troubleshooter_client.ts b/packages/google-cloud-policytroubleshooter-iam/src/v3beta/policy_troubleshooter_client.ts index be03883aea4..be0b7a6215a 100644 --- a/packages/google-cloud-policytroubleshooter-iam/src/v3beta/policy_troubleshooter_client.ts +++ b/packages/google-cloud-policytroubleshooter-iam/src/v3beta/policy_troubleshooter_client.ts @@ -27,6 +27,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v3beta/policy_troubleshooter_client_config.json`. @@ -50,6 +51,8 @@ export class PolicyTroubleshooterClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -106,8 +109,20 @@ export class PolicyTroubleshooterClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof PolicyTroubleshooterClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'policytroubleshooter.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -122,7 +137,7 @@ export class PolicyTroubleshooterClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -147,10 +162,10 @@ export class PolicyTroubleshooterClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -254,21 +269,52 @@ export class PolicyTroubleshooterClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policytroubleshooter.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policytroubleshooter.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3.ts b/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3.ts index 45805339c06..29d2d3d7b01 100644 --- a/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3.ts +++ b/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3.ts @@ -66,16 +66,66 @@ function stubSimpleCallWithCallback( describe('v3.PolicyTroubleshooterClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - policytroubleshooterModule.v3.PolicyTroubleshooterClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new policytroubleshooterModule.v3.PolicyTroubleshooterClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'policytroubleshooter.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - policytroubleshooterModule.v3.PolicyTroubleshooterClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new policytroubleshooterModule.v3.PolicyTroubleshooterClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + policytroubleshooterModule.v3.PolicyTroubleshooterClient.servicePath; + assert.strictEqual(servicePath, 'policytroubleshooter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + policytroubleshooterModule.v3.PolicyTroubleshooterClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'policytroubleshooter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new policytroubleshooterModule.v3.PolicyTroubleshooterClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policytroubleshooter.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new policytroubleshooterModule.v3.PolicyTroubleshooterClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policytroubleshooter.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new policytroubleshooterModule.v3.PolicyTroubleshooterClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3beta.ts b/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3beta.ts index 7f76f32615f..ee4fa881678 100644 --- a/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3beta.ts +++ b/packages/google-cloud-policytroubleshooter-iam/test/gapic_policy_troubleshooter_v3beta.ts @@ -66,18 +66,68 @@ function stubSimpleCallWithCallback( describe('v3beta.PolicyTroubleshooterClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - policytroubleshooterModule.v3beta.PolicyTroubleshooterClient - .servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new policytroubleshooterModule.v3beta.PolicyTroubleshooterClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'policytroubleshooter.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - policytroubleshooterModule.v3beta.PolicyTroubleshooterClient - .apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new policytroubleshooterModule.v3beta.PolicyTroubleshooterClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + policytroubleshooterModule.v3beta.PolicyTroubleshooterClient + .servicePath; + assert.strictEqual(servicePath, 'policytroubleshooter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + policytroubleshooterModule.v3beta.PolicyTroubleshooterClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'policytroubleshooter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new policytroubleshooterModule.v3beta.PolicyTroubleshooterClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policytroubleshooter.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new policytroubleshooterModule.v3beta.PolicyTroubleshooterClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policytroubleshooter.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new policytroubleshooterModule.v3beta.PolicyTroubleshooterClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts b/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts index ab21b437084..bcc1c26ff54 100644 --- a/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts +++ b/packages/google-cloud-policytroubleshooter/src/v1/iam_checker_client.ts @@ -27,6 +27,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/iam_checker_client_config.json`. @@ -50,6 +51,8 @@ export class IamCheckerClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -106,8 +109,20 @@ export class IamCheckerClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof IamCheckerClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'policytroubleshooter.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -122,7 +137,7 @@ export class IamCheckerClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -147,10 +162,10 @@ export class IamCheckerClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -253,21 +268,52 @@ export class IamCheckerClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policytroubleshooter.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'policytroubleshooter.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts b/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts index d602ae6b631..371e644adea 100644 --- a/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts +++ b/packages/google-cloud-policytroubleshooter/test/gapic_iam_checker_v1.ts @@ -66,14 +66,60 @@ function stubSimpleCallWithCallback( describe('v1.IamCheckerClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = iamcheckerModule.v1.IamCheckerClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new iamcheckerModule.v1.IamCheckerClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'policytroubleshooter.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = iamcheckerModule.v1.IamCheckerClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new iamcheckerModule.v1.IamCheckerClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = iamcheckerModule.v1.IamCheckerClient.servicePath; + assert.strictEqual(servicePath, 'policytroubleshooter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = iamcheckerModule.v1.IamCheckerClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'policytroubleshooter.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new iamcheckerModule.v1.IamCheckerClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policytroubleshooter.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new iamcheckerModule.v1.IamCheckerClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'policytroubleshooter.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new iamcheckerModule.v1.IamCheckerClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_catalogs.js b/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_catalogs.js index fcfcac4d2cf..87fe1df381d 100644 --- a/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_catalogs.js +++ b/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_catalogs.js @@ -63,7 +63,7 @@ function main(resource) { }; // Run request - const iterable = await privatecatalogClient.searchCatalogsAsync(request); + const iterable = privatecatalogClient.searchCatalogsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_products.js b/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_products.js index f76bcf6a753..886176b1255 100644 --- a/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_products.js +++ b/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_products.js @@ -65,7 +65,7 @@ function main(resource) { }; // Run request - const iterable = await privatecatalogClient.searchProductsAsync(request); + const iterable = privatecatalogClient.searchProductsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_versions.js b/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_versions.js index ffabc6e9267..14a55ce27f2 100644 --- a/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_versions.js +++ b/packages/google-cloud-privatecatalog/samples/generated/v1beta1/private_catalog.search_versions.js @@ -66,7 +66,7 @@ function main(resource, query) { }; // Run request - const iterable = await privatecatalogClient.searchVersionsAsync(request); + const iterable = privatecatalogClient.searchVersionsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-privatecatalog/src/v1beta1/private_catalog_client.ts b/packages/google-cloud-privatecatalog/src/v1beta1/private_catalog_client.ts index 4b794912cfc..2a3fcf2dde6 100644 --- a/packages/google-cloud-privatecatalog/src/v1beta1/private_catalog_client.ts +++ b/packages/google-cloud-privatecatalog/src/v1beta1/private_catalog_client.ts @@ -29,6 +29,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1beta1/private_catalog_client_config.json`. @@ -70,6 +71,8 @@ export class PrivateCatalogClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -127,8 +130,20 @@ export class PrivateCatalogClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof PrivateCatalogClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'cloudprivatecatalog.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -143,7 +158,7 @@ export class PrivateCatalogClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -168,10 +183,10 @@ export class PrivateCatalogClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -315,21 +330,52 @@ export class PrivateCatalogClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'cloudprivatecatalog.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'cloudprivatecatalog.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-privatecatalog/test/gapic_private_catalog_v1beta1.ts b/packages/google-cloud-privatecatalog/test/gapic_private_catalog_v1beta1.ts index 9cd748dbd31..8ba0d981953 100644 --- a/packages/google-cloud-privatecatalog/test/gapic_private_catalog_v1beta1.ts +++ b/packages/google-cloud-privatecatalog/test/gapic_private_catalog_v1beta1.ts @@ -129,16 +129,62 @@ function stubAsyncIterationCall( describe('v1beta1.PrivateCatalogClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - privatecatalogModule.v1beta1.PrivateCatalogClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new privatecatalogModule.v1beta1.PrivateCatalogClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'cloudprivatecatalog.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - privatecatalogModule.v1beta1.PrivateCatalogClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new privatecatalogModule.v1beta1.PrivateCatalogClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + privatecatalogModule.v1beta1.PrivateCatalogClient.servicePath; + assert.strictEqual(servicePath, 'cloudprivatecatalog.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + privatecatalogModule.v1beta1.PrivateCatalogClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'cloudprivatecatalog.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new privatecatalogModule.v1beta1.PrivateCatalogClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'cloudprivatecatalog.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new privatecatalogModule.v1beta1.PrivateCatalogClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'cloudprivatecatalog.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new privatecatalogModule.v1beta1.PrivateCatalogClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-rapidmigrationassessment/samples/generated/v1/rapid_migration_assessment.list_collectors.js b/packages/google-cloud-rapidmigrationassessment/samples/generated/v1/rapid_migration_assessment.list_collectors.js index b8d8d23d5f0..87b4f2f923e 100644 --- a/packages/google-cloud-rapidmigrationassessment/samples/generated/v1/rapid_migration_assessment.list_collectors.js +++ b/packages/google-cloud-rapidmigrationassessment/samples/generated/v1/rapid_migration_assessment.list_collectors.js @@ -63,7 +63,7 @@ function main(parent) { }; // Run request - const iterable = await rapidmigrationassessmentClient.listCollectorsAsync(request); + const iterable = rapidmigrationassessmentClient.listCollectorsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-rapidmigrationassessment/src/v1/rapid_migration_assessment_client.ts b/packages/google-cloud-rapidmigrationassessment/src/v1/rapid_migration_assessment_client.ts index 97b0bd7c289..eaf74bb6c81 100644 --- a/packages/google-cloud-rapidmigrationassessment/src/v1/rapid_migration_assessment_client.ts +++ b/packages/google-cloud-rapidmigrationassessment/src/v1/rapid_migration_assessment_client.ts @@ -33,6 +33,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/rapid_migration_assessment_client_config.json`. @@ -54,6 +55,8 @@ export class RapidMigrationAssessmentClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -114,8 +117,20 @@ export class RapidMigrationAssessmentClient { // Ensure that options include all the required fields. const staticMembers = this .constructor as typeof RapidMigrationAssessmentClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'rapidmigrationassessment.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -130,7 +145,7 @@ export class RapidMigrationAssessmentClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -155,10 +170,10 @@ export class RapidMigrationAssessmentClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } this.locationsClient = new this._gaxModule.LocationsClient( @@ -428,21 +443,52 @@ export class RapidMigrationAssessmentClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'rapidmigrationassessment.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'rapidmigrationassessment.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-rapidmigrationassessment/test/gapic_rapid_migration_assessment_v1.ts b/packages/google-cloud-rapidmigrationassessment/test/gapic_rapid_migration_assessment_v1.ts index 557c23254ac..aaefd5b3ca5 100644 --- a/packages/google-cloud-rapidmigrationassessment/test/gapic_rapid_migration_assessment_v1.ts +++ b/packages/google-cloud-rapidmigrationassessment/test/gapic_rapid_migration_assessment_v1.ts @@ -166,18 +166,77 @@ function stubAsyncIterationCall( describe('v1.RapidMigrationAssessmentClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient - .servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = + new rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual( + apiEndpoint, + 'rapidmigrationassessment.googleapis.com' + ); }); - it('has apiEndpoint', () => { - const apiEndpoint = - rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient - .apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = + new rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient + .servicePath; + assert.strictEqual( + servicePath, + 'rapidmigrationassessment.googleapis.com' + ); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient + .apiEndpoint; + assert.strictEqual( + apiEndpoint, + 'rapidmigrationassessment.googleapis.com' + ); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'rapidmigrationassessment.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'rapidmigrationassessment.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new rapidmigrationassessmentModule.v1.RapidMigrationAssessmentClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => {