mask machine logs
parent
6f341415f0
commit
06de0a7636
|
@ -63,7 +63,7 @@ const Machine = ({
|
||||||
}) => {
|
}) => {
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
const classes = useRowStyles();
|
const classes = useRowStyles();
|
||||||
const { mask } = useSensitiveInfo();
|
const { mask, maskElements } = useSensitiveInfo();
|
||||||
|
|
||||||
const topActions = useMemo(
|
const topActions = useMemo(
|
||||||
() => actions.filter(a => a.top === true),
|
() => actions.filter(a => a.top === true),
|
||||||
|
@ -122,7 +122,7 @@ const Machine = ({
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
|
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
|
||||||
<Collapse in={open} timeout="auto" unmountOnExit>
|
<Collapse in={open} timeout="auto" unmountOnExit>
|
||||||
<MachineLog logs={logs} />
|
<MachineLog logs={maskElements(logs)} />
|
||||||
</Collapse>
|
</Collapse>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
|
@ -37,7 +37,13 @@ const useSensitiveInfo = () => {
|
||||||
return obfuscate(text, "#");
|
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 }) => {
|
const SensitiveInfoProvider = ({ children }) => {
|
||||||
|
|
|
@ -9,16 +9,16 @@ const obfuscateForChars = (text, placeholder = "*") => {
|
||||||
|
|
||||||
const obfuscate = (text, placeholder = "*") => {
|
const obfuscate = (text, placeholder = "*") => {
|
||||||
if (text.length <= 2) return text;
|
if (text.length <= 2) return text;
|
||||||
if (text.length <= 4) {
|
if (text.length <= 5) {
|
||||||
return obfuscateForChars(text);
|
return obfuscateForChars(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstTwoChars = text.substring(0, 2);
|
const firstTwoChars = text.substring(0, 2);
|
||||||
const lastTwoChars = text.substring(text.length - 2);
|
const lastChar = text.substring(text.length - 1);
|
||||||
const middleChars = text
|
const middleChars = text
|
||||||
.substring(2, text.length - 2)
|
.substring(2, text.length - 1)
|
||||||
.replace(/[a-zA-Z0-9]/g, placeholder);
|
.replace(/[a-zA-Z0-9]/g, placeholder);
|
||||||
return firstTwoChars + middleChars + lastTwoChars;
|
return firstTwoChars + middleChars + lastChar;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { obfuscate };
|
export { obfuscate };
|
||||||
|
|
Loading…
Reference in New Issue