MCPcopy Create free account
hub / github.com/Y80/bmm / redactDbConnectionUrl

Function redactDbConnectionUrl

scripts/utils.mjs:32–70  ·  view source on GitHub ↗
(connectionUrl = '')

Source from the content-addressed store, hash-verified

30}
31
32export function redactDbConnectionUrl(connectionUrl = '') {
33 if (!connectionUrl || connectionUrl.startsWith('file:') || connectionUrl === ':memory:') {
34 return connectionUrl
35 }
36
37 try {
38 const url = new URL(connectionUrl)
39 const sensitiveKeys = new Set([
40 'access_token',
41 'api_key',
42 'apikey',
43 'auth_token',
44 'authtoken',
45 'key',
46 'password',
47 'passwd',
48 'pwd',
49 'secret',
50 'token',
51 ])
52
53 if (url.username) {
54 url.username = '***'
55 }
56 if (url.password) {
57 url.password = '***'
58 }
59
60 for (const key of [...url.searchParams.keys()]) {
61 if (sensitiveKeys.has(key.toLowerCase())) {
62 url.searchParams.set(key, '***')
63 }
64 }
65
66 return url.toString()
67 } catch {
68 return connectionUrl.replace(/\/\/([^/@:]+)(?::[^/@]*)?@/, '//***:***@')
69 }
70}
71
72// 加载环境变量
73export async function loadEnv(options = {}) {

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected