Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add several fields to manage state of database encryption update #1243

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/v1/datastore_admin_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,15 @@ export class DatastoreAdminClient {
'Please set either universe_domain or universeDomain, but not both.'
);
}
const universeDomainEnvVar =
typeof process === 'object' && typeof process.env === 'object'
? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
: undefined;
this._universeDomain =
opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com';
opts?.universeDomain ??
opts?.universe_domain ??
universeDomainEnvVar ??
'googleapis.com';
this._servicePath = 'datastore.' + this._universeDomain;
const servicePath =
opts?.servicePath || opts?.apiEndpoint || this._servicePath;
Expand Down Expand Up @@ -220,7 +227,7 @@ export class DatastoreAdminClient {

// Determine the client header string.
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
if (typeof process !== 'undefined' && 'versions' in process) {
if (typeof process === 'object' && 'versions' in process) {
clientHeader.push(`gl-node/${process.versions.node}`);
} else {
clientHeader.push(`gl-web/${this._gaxModule.version}`);
Expand Down Expand Up @@ -423,7 +430,7 @@ export class DatastoreAdminClient {
*/
static get servicePath() {
if (
typeof process !== undefined &&
typeof process === 'object' &&
typeof process.emitWarning === 'function'
) {
process.emitWarning(
Expand All @@ -441,7 +448,7 @@ export class DatastoreAdminClient {
*/
static get apiEndpoint() {
if (
typeof process !== undefined &&
typeof process === 'object' &&
typeof process.emitWarning === 'function'
) {
process.emitWarning(
Expand Down
15 changes: 11 additions & 4 deletions src/v1/datastore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@ export class DatastoreClient {
'Please set either universe_domain or universeDomain, but not both.'
);
}
const universeDomainEnvVar =
typeof process === 'object' && typeof process.env === 'object'
? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
: undefined;
this._universeDomain =
opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com';
opts?.universeDomain ??
opts?.universe_domain ??
universeDomainEnvVar ??
'googleapis.com';
this._servicePath = 'datastore.' + this._universeDomain;
const servicePath =
opts?.servicePath || opts?.apiEndpoint || this._servicePath;
Expand Down Expand Up @@ -177,7 +184,7 @@ export class DatastoreClient {

// Determine the client header string.
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
if (typeof process !== 'undefined' && 'versions' in process) {
if (typeof process === 'object' && 'versions' in process) {
clientHeader.push(`gl-node/${process.versions.node}`);
} else {
clientHeader.push(`gl-web/${this._gaxModule.version}`);
Expand Down Expand Up @@ -323,7 +330,7 @@ export class DatastoreClient {
*/
static get servicePath() {
if (
typeof process !== undefined &&
typeof process === 'object' &&
typeof process.emitWarning === 'function'
) {
process.emitWarning(
Expand All @@ -341,7 +348,7 @@ export class DatastoreClient {
*/
static get apiEndpoint() {
if (
typeof process !== undefined &&
typeof process === 'object' &&
typeof process.emitWarning === 'function'
) {
process.emitWarning(
Expand Down
34 changes: 33 additions & 1 deletion test/gapic_datastore_admin_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('v1.DatastoreAdminClient', () => {
});

if (
typeof process !== 'undefined' &&
typeof process === 'object' &&
typeof process.emitWarning === 'function'
) {
it('throws DeprecationWarning if static servicePath is used', () => {
Expand Down Expand Up @@ -210,6 +210,38 @@ describe('v1.DatastoreAdminClient', () => {
const servicePath = client.apiEndpoint;
assert.strictEqual(servicePath, 'datastore.example.com');
});

if (typeof process === 'object' && 'env' in process) {
describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => {
it('sets apiEndpoint from environment variable', () => {
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
const client = new datastoreadminModule.v1.DatastoreAdminClient();
const servicePath = client.apiEndpoint;
assert.strictEqual(servicePath, 'datastore.example.com');
if (saved) {
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
} else {
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
}
});

it('value configured in code has priority over environment variable', () => {
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
const client = new datastoreadminModule.v1.DatastoreAdminClient({
universeDomain: 'configured.example.com',
});
const servicePath = client.apiEndpoint;
assert.strictEqual(servicePath, 'datastore.configured.example.com');
if (saved) {
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
} else {
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
}
});
});
}
it('does not allow setting both universeDomain and universe_domain', () => {
assert.throws(() => {
new datastoreadminModule.v1.DatastoreAdminClient({
Expand Down
34 changes: 33 additions & 1 deletion test/gapic_datastore_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('v1.DatastoreClient', () => {
});

if (
typeof process !== 'undefined' &&
typeof process === 'object' &&
typeof process.emitWarning === 'function'
) {
it('throws DeprecationWarning if static servicePath is used', () => {
Expand Down Expand Up @@ -136,6 +136,38 @@ describe('v1.DatastoreClient', () => {
const servicePath = client.apiEndpoint;
assert.strictEqual(servicePath, 'datastore.example.com');
});

if (typeof process === 'object' && 'env' in process) {
describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => {
it('sets apiEndpoint from environment variable', () => {
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
const client = new datastoreModule.v1.DatastoreClient();
const servicePath = client.apiEndpoint;
assert.strictEqual(servicePath, 'datastore.example.com');
if (saved) {
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
} else {
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
}
});

it('value configured in code has priority over environment variable', () => {
const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com';
const client = new datastoreModule.v1.DatastoreClient({
universeDomain: 'configured.example.com',
});
const servicePath = client.apiEndpoint;
assert.strictEqual(servicePath, 'datastore.configured.example.com');
if (saved) {
process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved;
} else {
delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'];
}
});
});
}
it('does not allow setting both universeDomain and universe_domain', () => {
assert.throws(() => {
new datastoreModule.v1.DatastoreClient({
Expand Down
Loading