mask machine logs

master
Tudor Stanciu 2023-03-05 02:08:03 +02:00
parent 6f341415f0
commit 06de0a7636
3 changed files with 13 additions and 7 deletions

View File

@ -63,7 +63,7 @@ const Machine = ({
}) => {
const [open, setOpen] = React.useState(false);
const classes = useRowStyles();
const { mask } = useSensitiveInfo();
const { mask, maskElements } = useSensitiveInfo();
const topActions = useMemo(
() => actions.filter(a => a.top === true),
@ -122,7 +122,7 @@ const Machine = ({
<TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
<Collapse in={open} timeout="auto" unmountOnExit>
<MachineLog logs={logs} />
<MachineLog logs={maskElements(logs)} />
</Collapse>
</TableCell>
</TableRow>

View File

@ -37,7 +37,13 @@ const useSensitiveInfo = () => {
return obfuscate(text, "#");
};
return { enabled, onSensitiveInfoEnabled, mask };
const maskElements = list => {
if (!enabled) return list;
const maskedList = list.map(z => obfuscate(z, "#"));
return maskedList;
};
return { enabled, onSensitiveInfoEnabled, mask, maskElements };
};
const SensitiveInfoProvider = ({ children }) => {

View File

@ -9,16 +9,16 @@ const obfuscateForChars = (text, placeholder = "*") => {
const obfuscate = (text, placeholder = "*") => {
if (text.length <= 2) return text;
if (text.length <= 4) {
if (text.length <= 5) {
return obfuscateForChars(text);
}
const firstTwoChars = text.substring(0, 2);
const lastTwoChars = text.substring(text.length - 2);
const lastChar = text.substring(text.length - 1);
const middleChars = text
.substring(2, text.length - 2)
.substring(2, text.length - 1)
.replace(/[a-zA-Z0-9]/g, placeholder);
return firstTwoChars + middleChars + lastTwoChars;
return firstTwoChars + middleChars + lastChar;
};
export { obfuscate };