Skip to content

Commit 5d28cda

Browse files
feat: add several fields to manage state of database encryption update (#1243)
* feat: add several fields to manage state of database encryption update PiperOrigin-RevId: 619289281 Source-Link: googleapis/googleapis@3a7c334 Source-Link: googleapis/googleapis-gen@6a8c733 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNmE4YzczMzA2MmQ4MzNkMTFjNTI0NWVkYTUwZjUxMDhlMGU1NTMyNCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 1aa0fbf commit 5d28cda

File tree

4 files changed

+88
-10
lines changed

4 files changed

+88
-10
lines changed

src/v1/datastore_admin_client.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,15 @@ export class DatastoreAdminClient {
167167
'Please set either universe_domain or universeDomain, but not both.'
168168
);
169169
}
170+
const universeDomainEnvVar =
171+
typeof process === 'object' && typeof process.env === 'object'
172+
? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
173+
: undefined;
170174
this._universeDomain =
171-
opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com';
175+
opts?.universeDomain ??
176+
opts?.universe_domain ??
177+
universeDomainEnvVar ??
178+
'googleapis.com';
172179
this._servicePath = 'datastore.' + this._universeDomain;
173180
const servicePath =
174181
opts?.servicePath || opts?.apiEndpoint || this._servicePath;
@@ -220,7 +227,7 @@ export class DatastoreAdminClient {
220227

221228
// Determine the client header string.
222229
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
223-
if (typeof process !== 'undefined' && 'versions' in process) {
230+
if (typeof process === 'object' && 'versions' in process) {
224231
clientHeader.push(`gl-node/${process.versions.node}`);
225232
} else {
226233
clientHeader.push(`gl-web/${this._gaxModule.version}`);
@@ -423,7 +430,7 @@ export class DatastoreAdminClient {
423430
*/
424431
static get servicePath() {
425432
if (
426-
typeof process !== undefined &&
433+
typeof process === 'object' &&
427434
typeof process.emitWarning === 'function'
428435
) {
429436
process.emitWarning(
@@ -441,7 +448,7 @@ export class DatastoreAdminClient {
441448
*/
442449
static get apiEndpoint() {
443450
if (
444-
typeof process !== undefined &&
451+
typeof process === 'object' &&
445452
typeof process.emitWarning === 'function'
446453
) {
447454
process.emitWarning(

src/v1/datastore_client.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,15 @@ export class DatastoreClient {
124124
'Please set either universe_domain or universeDomain, but not both.'
125125
);
126126
}
127+
const universeDomainEnvVar =
128+
typeof process === 'object' && typeof process.env === 'object'
129+
? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
130+
: undefined;
127131
this._universeDomain =
128-
opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com';
132+
opts?.universeDomain ??
133+
opts?.universe_domain ??
134+
universeDomainEnvVar ??
135+
'googleapis.com';
129136
this._servicePath = 'datastore.' + this._universeDomain;
130137
const servicePath =
131138
opts?.servicePath || opts?.apiEndpoint || this._servicePath;
@@ -177,7 +184,7 @@ export class DatastoreClient {
177184

178185
// Determine the client header string.
179186
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
180-
if (typeof process !== 'undefined' && 'versions' in process) {
187+
if (typeof process === 'object' && 'versions' in process) {
181188
clientHeader.push(`gl-node/${process.versions.node}`);
182189
} else {
183190
clientHeader.push(`gl-web/${this._gaxModule.version}`);
@@ -323,7 +330,7 @@ export class DatastoreClient {
323330
*/
324331
static get servicePath() {
325332
if (
326-
typeof process !== undefined &&
333+
typeof process === 'object' &&
327334
typeof process.emitWarning === 'function'
328335
) {
329336
process.emitWarning(
@@ -341,7 +348,7 @@ export class DatastoreClient {
341348
*/
342349
static get apiEndpoint() {
343350
if (
344-
typeof process !== undefined &&
351+
typeof process === 'object' &&
345352
typeof process.emitWarning === 'function'
346353
) {
347354
process.emitWarning(

test/gapic_datastore_admin_v1.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('v1.DatastoreAdminClient', () => {
174174
});
175175

176176
if (
177-
typeof process !== 'undefined' &&
177+
typeof process === 'object' &&
178178
typeof process.emitWarning === 'function'
179179
) {
180180
it('throws DeprecationWarning if static servicePath is used', () => {
@@ -210,6 +210,38 @@ describe('v1.DatastoreAdminClient', () => {
210210
const servicePath = client.apiEndpoint;
211211
assert.strictEqual(servicePath, 'datastore.example.com');
212212
});
213+
214+
if (typeof process === 'object' && 'env' in process) {
215+
describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => {
216+
it('sets apiEndpoint from environment variable', () => {
217+
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
218+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
219+
const client = new datastoreadminModule.v1.DatastoreAdminClient();
220+
const servicePath = client.apiEndpoint;
221+
assert.strictEqual(servicePath, 'datastore.example.com');
222+
if (saved) {
223+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
224+
} else {
225+
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
226+
}
227+
});
228+
229+
it('value configured in code has priority over environment variable', () => {
230+
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
231+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
232+
const client = new datastoreadminModule.v1.DatastoreAdminClient({
233+
universeDomain: 'configured.example.com',
234+
});
235+
const servicePath = client.apiEndpoint;
236+
assert.strictEqual(servicePath, 'datastore.configured.example.com');
237+
if (saved) {
238+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
239+
} else {
240+
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
241+
}
242+
});
243+
});
244+
}
213245
it('does not allow setting both universeDomain and universe_domain', () => {
214246
assert.throws(() => {
215247
new datastoreadminModule.v1.DatastoreAdminClient({

test/gapic_datastore_v1.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('v1.DatastoreClient', () => {
102102
});
103103

104104
if (
105-
typeof process !== 'undefined' &&
105+
typeof process === 'object' &&
106106
typeof process.emitWarning === 'function'
107107
) {
108108
it('throws DeprecationWarning if static servicePath is used', () => {
@@ -136,6 +136,38 @@ describe('v1.DatastoreClient', () => {
136136
const servicePath = client.apiEndpoint;
137137
assert.strictEqual(servicePath, 'datastore.example.com');
138138
});
139+
140+
if (typeof process === 'object' && 'env' in process) {
141+
describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => {
142+
it('sets apiEndpoint from environment variable', () => {
143+
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
144+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
145+
const client = new datastoreModule.v1.DatastoreClient();
146+
const servicePath = client.apiEndpoint;
147+
assert.strictEqual(servicePath, 'datastore.example.com');
148+
if (saved) {
149+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
150+
} else {
151+
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
152+
}
153+
});
154+
155+
it('value configured in code has priority over environment variable', () => {
156+
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
157+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
158+
const client = new datastoreModule.v1.DatastoreClient({
159+
universeDomain: 'configured.example.com',
160+
});
161+
const servicePath = client.apiEndpoint;
162+
assert.strictEqual(servicePath, 'datastore.configured.example.com');
163+
if (saved) {
164+
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
165+
} else {
166+
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
167+
}
168+
});
169+
});
170+
}
139171
it('does not allow setting both universeDomain and universe_domain', () => {
140172
assert.throws(() => {
141173
new datastoreModule.v1.DatastoreClient({

0 commit comments

Comments
 (0)