Skip to content

Commit 2c90828

Browse files
committed
add backward compatibility
1 parent cfbbd6f commit 2c90828

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/DBSQLClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
166166
LogLevel.warn,
167167
'Warning: The "clientId" option is deprecated. Please use "userAgentEntry" instead.',
168168
);
169+
if (!options.userAgentEntry) {
170+
options.userAgentEntry = deprecatedClientId;
171+
}
169172
}
170173

171174
this.authProvider = this.createAuthProvider(options, authProvider);

lib/utils/buildUserAgentString.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,21 @@ function getOperatingSystemVersion(): string {
1111
return `${os.type()} ${os.release()}`;
1212
}
1313

14+
function redactInternalToken(userAgentEntry: string): string {
15+
const internalTokenPrefixes = ['dkea', 'dskea', 'dapi', 'dsapi', 'dose'];
16+
for (const prefix of internalTokenPrefixes) {
17+
if (userAgentEntry.startsWith(prefix)) {
18+
return '<REDACTED>';
19+
}
20+
}
21+
return userAgentEntry;
22+
}
23+
1424
export default function buildUserAgentString(userAgentEntry?: string): string {
25+
if (userAgentEntry) {
26+
userAgentEntry = redactInternalToken(userAgentEntry);
27+
}
28+
1529
const extra = [userAgentEntry, getNodeVersion(), getOperatingSystemVersion()].filter(Boolean);
1630
return `${productName}/${packageVersion} (${extra.join('; ')})`;
1731
}

tests/unit/utils/utils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ describe('buildUserAgentString', () => {
5656
const ua = buildUserAgentString();
5757
checkUserAgentString(ua);
5858
});
59+
60+
it('should redact internal token in userAgentEntry', () => {
61+
const userAgentEntry = 'dkea-internal-token';
62+
const userAgentString = buildUserAgentString(userAgentEntry);
63+
expect(userAgentString).to.include('<REDACTED>');
64+
});
5965
});
6066

6167
describe('formatProgress', () => {

0 commit comments

Comments
 (0)