Skip to content

Commit bbb812a

Browse files
authored
Merge pull request #25 from getshifter/fix/hide-secret
fix: hide secret when use --verbose flags
2 parents ffe8d76 + c21b5ee commit bbb812a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/share/api/api.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ export class APIClientService {
3434
if (!this.debugMode) return
3535
const request = Object.assign({}, {
3636
url, path, body,
37-
})
37+
}) as any
38+
if (request.body && Object.keys(request.body).length > 0) {
39+
Object.keys(request.body).forEach(key => {
40+
if (!request.body[key]) return
41+
if (/Token/.test(key) && request.body[key]) request.body[key] = '=== SECRET ==='
42+
if (/password/.test(key.toLocaleLowerCase()) && request.body[key]) request.body[key] = '=== SECRET ==='
43+
})
44+
}
3845
console.log({
3946
request,
4047
})
@@ -49,6 +56,7 @@ export class APIClientService {
4956
const data = Object.assign({}, result.data) as any
5057
Object.keys(data).forEach(key => {
5158
if (/Token/.test(key) && data[key]) data[key] = '=== SECRET ==='
59+
if (/password/.test(key.toLocaleLowerCase()) && data[key]) data[key] = '=== SECRET ==='
5260
})
5361
return data
5462
})()
@@ -63,7 +71,7 @@ export class APIClientService {
6371

6472
protected async _post(path: string, body?: object, config?: AxiosRequestConfig) {
6573
const url = pathJoin(this.endpoint, path)
66-
this._recordAxiosRequest(url, path, config, body)
74+
this._recordAxiosRequest(url, path, config, {...body})
6775
const result = await axios.post(url, body, config)
6876
this._recordAxiosResponse(result)
6977
return result.data

0 commit comments

Comments
 (0)