Skip to content

Commit

Permalink
feat: adds universe_domain field to base external client (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeitzman committed May 17, 2023
1 parent 85f2c93 commit 7412d7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/auth/baseexternalclient.ts
Expand Up @@ -76,6 +76,7 @@ export interface BaseExternalAccountClientOptions {
client_secret?: string;
quota_project_id?: string;
workforce_pool_user_project?: string;
universe_domain?: string;
}

/**
Expand Down Expand Up @@ -137,9 +138,9 @@ export abstract class BaseExternalAccountClient extends AuthClient {
private readonly workforcePoolUserProject?: string;
public projectId: string | null;
public projectNumber: string | null;
public universeDomain?: string;
public readonly eagerRefreshThresholdMillis: number;
public readonly forceRefreshOnFailure: boolean;

/**
* Instantiate a BaseExternalAccountClient instance using the provided JSON
* object loaded from an external account credentials file.
Expand Down Expand Up @@ -205,6 +206,7 @@ export abstract class BaseExternalAccountClient extends AuthClient {
this.forceRefreshOnFailure = !!additionalOptions?.forceRefreshOnFailure;
this.projectId = null;
this.projectNumber = this.getProjectNumber(this.audience);
this.universeDomain = options.universe_domain;
}

/** The service account email to be impersonated, if available. */
Expand Down
20 changes: 20 additions & 0 deletions test/test.baseexternalclient.ts
Expand Up @@ -283,6 +283,26 @@ describe('BaseExternalAccountClient', () => {
});
});

describe('universeDomain', () => {
it('should be undefined if not set', () => {
const client = new TestExternalAccountClient(externalAccountOptions);

assert(client.universeDomain === undefined);
});

it('should be set if provided', () => {
const universeDomain = 'universe.domain.com';
const options: BaseExternalAccountClientOptions = Object.assign(
{},
externalAccountOptions
);
options.universe_domain = universeDomain;
const client = new TestExternalAccountClient(options);

assert.equal(client.universeDomain, universeDomain);
});
});

describe('getServiceAccountEmail()', () => {
it('should return the service account email when impersonation is used', () => {
const saEmail = 'service-1234@service-name.iam.gserviceaccount.com';
Expand Down

0 comments on commit 7412d7c

Please sign in to comment.