Skip to content
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
2 changes: 2 additions & 0 deletions src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ interface ConnectorOptions {
* Defaults to `googleapis.com`.
*/
universeDomain?: string;
userAgent?: string;
}

// The Connector class is the main public API to interact
Expand All @@ -164,6 +165,7 @@ export class Connector {
loginAuth: opts.auth,
sqlAdminAPIEndpoint: opts.sqlAdminAPIEndpoint,
universeDomain: opts.universeDomain,
userAgent: opts.userAgent,
});
this.localProxies = new Set();
this.sockets = new Set();
Expand Down
3 changes: 3 additions & 0 deletions src/sqladmin-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface SQLAdminFetcherOptions {
loginAuth?: GoogleAuth<AuthClient> | AuthClient;
sqlAdminAPIEndpoint?: string;
universeDomain?: string;
userAgent?: string;
}

export class SQLAdminFetcher {
Expand All @@ -92,6 +93,7 @@ export class SQLAdminFetcher {
loginAuth,
sqlAdminAPIEndpoint,
universeDomain,
userAgent,
}: SQLAdminFetcherOptions = {}) {
let auth: GoogleAuth<AuthClient>;

Expand All @@ -111,6 +113,7 @@ export class SQLAdminFetcher {
{
product: 'cloud-sql-nodejs-connector',
version: 'LIBRARY_SEMVER_VERSION',
comment: userAgent,
},
],
universeDomain: universeDomain,
Expand Down
20 changes: 20 additions & 0 deletions test/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,23 @@ t.test('Connector, custom universeDomain', async t => {

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

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

new Connector({userAgent: expectedUserAgent});

t.same(actualUserAgent, expectedUserAgent);
});
Loading