Skip to content

Commit

Permalink
feat: add universeDomain option to Connector (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon committed Apr 24, 2024
1 parent b7f1974 commit 651634d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ class CloudSQLInstanceMap extends Map {
interface ConnectorOptions {
auth?: GoogleAuth<AuthClient> | AuthClient;
sqlAdminAPIEndpoint?: string;
/**
* The Trusted Partner Cloud (TPC) Domain DNS of the service used to make requests.
* Defaults to `googleapis.com`.
*/
universeDomain?: string;
}

// The Connector class is the main public API to interact
Expand All @@ -163,6 +168,7 @@ export class Connector {
this.sqlAdminFetcher = new SQLAdminFetcher({
loginAuth: opts.auth,
sqlAdminAPIEndpoint: opts.sqlAdminAPIEndpoint,
universeDomain: opts.universeDomain,
});
}

Expand Down
8 changes: 7 additions & 1 deletion src/sqladmin-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ function cleanGaxiosConfig() {
export interface SQLAdminFetcherOptions {
loginAuth?: GoogleAuth<AuthClient> | AuthClient;
sqlAdminAPIEndpoint?: string;
universeDomain?: string;
}

export class SQLAdminFetcher {
private readonly client: sqladmin_v1beta4.Sqladmin;
private readonly auth: GoogleAuth<AuthClient>;

constructor({loginAuth, sqlAdminAPIEndpoint}: SQLAdminFetcherOptions = {}) {
constructor({
loginAuth,
sqlAdminAPIEndpoint,
universeDomain,
}: SQLAdminFetcherOptions = {}) {
let auth: GoogleAuth<AuthClient>;

if (loginAuth instanceof GoogleAuth) {
Expand All @@ -98,6 +103,7 @@ export class SQLAdminFetcher {
version: 'LIBRARY_SEMVER_VERSION',
},
],
universeDomain: universeDomain,
});

if (loginAuth instanceof GoogleAuth) {
Expand Down
20 changes: 20 additions & 0 deletions test/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,23 @@ t.test('Connector, custom sqlAdminAPIEndpoint', async t => {

t.same(actualsqlAdminAPIEndpoint, expectedsqlAdminAPIEndpoint);
});

t.test('Connector, custom universeDomain', async t => {
const expectedUniverseDomain = 'mydomain.com';
let actualUniverseDomain: string | undefined;
// mocks sql admin fetcher to check that the custom
// universeDomain is correctly passed into it
const {Connector} = t.mockRequire('../src/connector', {
'../src/sqladmin-fetcher': {
SQLAdminFetcher: class {
constructor({universeDomain}: SQLAdminFetcherOptions) {
actualUniverseDomain = universeDomain;
}
},
},
});

new Connector({universeDomain: expectedUniverseDomain});

t.same(actualUniverseDomain, expectedUniverseDomain);
});

0 comments on commit 651634d

Please sign in to comment.