mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
supress secret from logs if it appears multiple times (#415)
This commit is contained in:
parent
07f53375de
commit
41aadfb60f
@ -148,9 +148,9 @@ describe('util', () => {
|
|||||||
silent: false
|
silent: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath}`
|
const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath} and ${action.accessToken} again!`
|
||||||
expect(suppressSensitiveInformation(string, action)).toBe(
|
expect(suppressSensitiveInformation(string, action)).toBe(
|
||||||
'This is an error message! It contains *** and *** and ***'
|
'This is an error message! It contains *** and *** and *** and *** again!'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
19
src/util.ts
19
src/util.ts
@ -1,6 +1,9 @@
|
|||||||
import {isDebug} from '@actions/core'
|
import {isDebug} from '@actions/core'
|
||||||
import {ActionInterface} from './constants'
|
import {ActionInterface} from './constants'
|
||||||
|
|
||||||
|
const replaceAll = (input: string, find: string, replace: string): string =>
|
||||||
|
input.split(find).join(replace)
|
||||||
|
|
||||||
/* Utility function that checks to see if a value is undefined or not. */
|
/* Utility function that checks to see if a value is undefined or not. */
|
||||||
export const isNullOrUndefined = (value: any): boolean =>
|
export const isNullOrUndefined = (value: any): boolean =>
|
||||||
typeof value === 'undefined' || value === null || value === ''
|
typeof value === 'undefined' || value === null || value === ''
|
||||||
@ -64,16 +67,14 @@ export const suppressSensitiveInformation = (
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.accessToken) {
|
const orderedByLength = ([
|
||||||
value = value.replace(action.accessToken, '***')
|
action.accessToken,
|
||||||
}
|
action.gitHubToken,
|
||||||
|
action.repositoryPath
|
||||||
|
].filter(Boolean) as string[]).sort((a, b) => b.length - a.length)
|
||||||
|
|
||||||
if (action.gitHubToken) {
|
for (const find of orderedByLength) {
|
||||||
value = value.replace(action.gitHubToken, '***')
|
value = replaceAll(value, find, '***')
|
||||||
}
|
|
||||||
|
|
||||||
if (action.repositoryPath) {
|
|
||||||
value = value.replace(action.repositoryPath, '***')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
Loading…
Reference in New Issue
Block a user