@@ -104,28 +104,81 @@ export interface BigtableOptions extends gax.GoogleAuthOptions { |
104 | 104 | } |
105 | 105 |
|
106 | 106 | /** |
107 | | - * Retrieves the domain to be used for the service path. |
| 107 | + * Retrieves the universe domain, if configured. |
108 | 108 | * |
109 | | - * This function retrieves the domain from gax.ClientOptions passed in or via an environment variable. |
110 | | - * It defaults to 'googleapis.com' if none has been set. |
111 | | - * @param {string} [prefix] The prefix for the domain. |
112 | | - * @param {gax.ClientOptions} [opts] The gax client options |
113 | | - * @returns {string} The universe domain. |
| 109 | + * This function checks for a universe domain in the following order: |
| 110 | + * 1. The `universeDomain` property within the provided options. |
| 111 | + * 2. The `universeDomain` or `universe_domain` property within the `opts` object. |
| 112 | + * 3. The `GOOGLE_CLOUD_UNIVERSE_DOMAIN` environment variable. |
| 113 | + * |
| 114 | + * If a universe domain is found in any of these locations, it is returned. |
| 115 | + * Otherwise, the function returns `undefined`. |
| 116 | + * |
| 117 | + * @param {BigtableOptions} options - The Bigtable client options. |
| 118 | + * @param {gax.ClientOptions} [gaxOpts] - Optional gax client options. |
| 119 | + * @returns {string | undefined} The universe domain, or `undefined` if not found. |
114 | 120 | */ |
115 | | -function getDomain(prefix: string, opts?: gax.ClientOptions) { |
| 121 | +function getUniverseDomainOnly( |
| 122 | + options: BigtableOptions, |
| 123 | + gaxOpts?: gax.ClientOptions, |
| 124 | +): string | undefined { |
116 | 125 | // From https://github.com/googleapis/nodejs-bigtable/blob/589540475b0b2a055018a1cb6e475800fdd46a37/src/v2/bigtable_client.ts#L120-L128. |
117 | 126 | // This code for universe domain was taken from the Gapic Layer. |
118 | 127 | // It is reused here to build the service path. |
119 | 128 | const universeDomainEnvVar = |
120 | 129 | typeof process === 'object' && typeof process.env === 'object' |
121 | 130 | ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] |
122 | 131 | : undefined; |
123 | | - return `${prefix}.${ |
124 | | - opts?.universeDomain ?? |
125 | | - opts?.universe_domain ?? |
126 | | - universeDomainEnvVar ?? |
127 | | - 'googleapis.com' |
128 | | - }`; |
| 132 | + return ( |
| 133 | + gaxOpts?.universeDomain ?? |
| 134 | + gaxOpts?.universe_domain ?? |
| 135 | + options?.universeDomain ?? |
| 136 | + universeDomainEnvVar |
| 137 | + ); |
| 138 | +} |
| 139 | + |
| 140 | +/** |
| 141 | + * Retrieves the universe domain options from the provided options. |
| 142 | + * |
| 143 | + * This function examines the provided BigtableOptions and an optional |
| 144 | + * gax.ClientOptions object to determine the universe domain to be used. |
| 145 | + * It prioritizes the `universeDomain` property in the options, then checks |
| 146 | + * for `universeDomain` or `universe_domain` in the gax options, and finally |
| 147 | + * falls back to the `GOOGLE_CLOUD_UNIVERSE_DOMAIN` environment variable. |
| 148 | + * If a universe domain is found, it returns an object containing the |
| 149 | + * `universeDomain` property; otherwise, it returns `null`. |
| 150 | + * |
| 151 | + * @param {BigtableOptions} options - The Bigtable client options. |
| 152 | + * @param {gax.ClientOptions} [gaxOpts] - Optional gax client options. |
| 153 | + * @returns {{universeDomain: string} | null} An object containing the `universeDomain` property if found, |
| 154 | + * otherwise `null`. |
| 155 | + */ |
| 156 | +function getUniverseDomainOptions( |
| 157 | + options: BigtableOptions, |
| 158 | + gaxOpts?: gax.ClientOptions, |
| 159 | +): {universeDomain: string} | null { |
| 160 | + const universeDomainOnly = getUniverseDomainOnly(options, gaxOpts); |
| 161 | + return universeDomainOnly ? {universeDomain: universeDomainOnly} : null; |
| 162 | +} |
| 163 | + |
| 164 | +/** |
| 165 | + * Retrieves the domain to be used for the service path. |
| 166 | + * |
| 167 | + * This function retrieves the domain from gax.ClientOptions passed in or via an environment variable. |
| 168 | + * It defaults to 'googleapis.com' if none has been set. |
| 169 | + * @param {string} [prefix] The prefix for the domain. |
| 170 | + * @param {BigtableOptions} [options] The options passed into the Bigtable client. |
| 171 | + * @param {gax.ClientOptions} [gaxOpts] The gax client options. |
| 172 | + * @returns {string} The universe domain. |
| 173 | + */ |
| 174 | +function getDomain( |
| 175 | + prefix: string, |
| 176 | + options: BigtableOptions, |
| 177 | + gaxOpts?: gax.ClientOptions, |
| 178 | +): string { |
| 179 | + const universeDomainOnly = getUniverseDomainOnly(options, gaxOpts); |
| 180 | + const suffix = universeDomainOnly ? universeDomainOnly : 'googleapis.com'; |
| 181 | + return `${prefix}.${suffix}`; |
129 | 182 | } |
130 | 183 |
|
131 | 184 | /** |
@@ -467,10 +520,11 @@ export class Bigtable { |
467 | 520 | const dataOptions = Object.assign( |
468 | 521 | {}, |
469 | 522 | baseOptions, |
| 523 | + getUniverseDomainOptions(options, options.BigtableClient), |
470 | 524 | { |
471 | 525 | servicePath: |
472 | 526 | customEndpointBaseUrl || |
473 | | - getDomain('bigtable', options.BigtableClient), |
| 527 | + getDomain('bigtable', options, options.BigtableClient), |
474 | 528 | 'grpc.callInvocationTransformer': grpcGcp.gcpCallInvocationTransformer, |
475 | 529 | 'grpc.channelFactoryOverride': grpcGcp.gcpChannelFactoryOverride, |
476 | 530 | 'grpc.gcpApiConfig': grpcGcp.createGcpApiConfig({ |
@@ -488,20 +542,26 @@ export class Bigtable { |
488 | 542 | const adminOptions = Object.assign( |
489 | 543 | {}, |
490 | 544 | baseOptions, |
| 545 | + getUniverseDomainOptions(options, options.BigtableTableAdminClient), |
491 | 546 | { |
492 | 547 | servicePath: |
493 | 548 | customEndpointBaseUrl || |
494 | | - getDomain('bigtableadmin', options.BigtableClient), |
| 549 | + getDomain('bigtableadmin', options, options.BigtableTableAdminClient), |
495 | 550 | }, |
496 | 551 | options, |
497 | 552 | ); |
498 | 553 | const instanceAdminOptions = Object.assign( |
499 | 554 | {}, |
500 | 555 | baseOptions, |
| 556 | + getUniverseDomainOptions(options, options.BigtableInstanceAdminClient), |
501 | 557 | { |
502 | 558 | servicePath: |
503 | 559 | customEndpointBaseUrl || |
504 | | - getDomain('bigtableadmin', options.BigtableClient), |
| 560 | + getDomain( |
| 561 | + 'bigtableadmin', |
| 562 | + options, |
| 563 | + options.BigtableInstanceAdminClient, |
| 564 | + ), |
505 | 565 | }, |
506 | 566 | options, |
507 | 567 | ); |
|