-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathbuildUserAgentString.ts
More file actions
39 lines (31 loc) · 1.06 KB
/
buildUserAgentString.ts
File metadata and controls
39 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os from 'os';
import packageVersion from '../version';
import detectAgent from './agentDetector';
const productName = 'NodejsDatabricksSqlConnector';
function getNodeVersion(): string {
return `Node.js ${process.versions.node}`;
}
function getOperatingSystemVersion(): string {
return `${os.type()} ${os.release()}`;
}
function redactInternalToken(userAgentEntry: string): string {
const internalTokenPrefixes = ['dkea', 'dskea', 'dapi', 'dsapi', 'dose'];
for (const prefix of internalTokenPrefixes) {
if (userAgentEntry.startsWith(prefix)) {
return '<REDACTED>';
}
}
return userAgentEntry;
}
export default function buildUserAgentString(userAgentEntry?: string): string {
if (userAgentEntry) {
userAgentEntry = redactInternalToken(userAgentEntry);
}
const extra = [userAgentEntry, getNodeVersion(), getOperatingSystemVersion()].filter(Boolean);
let ua = `${productName}/${packageVersion} (${extra.join('; ')})`;
const agentProduct = detectAgent();
if (agentProduct) {
ua += ` agent/${agentProduct}`;
}
return ua;
}