ui: make unsafeItemSelected() a pure function

This commit is contained in:
Mike Salvatore 2021-02-25 19:47:21 -05:00
parent ff28509d0d
commit 8f32c48964
1 changed files with 16 additions and 16 deletions

View File

@ -18,6 +18,19 @@ const CONFIG_URL = '/api/configuration/island';
export const API_PBA_LINUX = '/api/fileUpload/PBAlinux';
export const API_PBA_WINDOWS = '/api/fileUpload/PBAwindows';
function unsafeItemSelected(options, selectedOptions) {
let item_safety = new Map();
options.forEach(i => item_safety[i.enum[0]] = i.safe);
for (let selected of selectedOptions) {
if (!item_safety[selected]) {
return true;
}
}
return false;
}
class ConfigurePageComponent extends AuthComponent {
constructor(props) {
@ -122,39 +135,26 @@ class ConfigurePageComponent extends AuthComponent {
}
unsafeExploiterSelected(config) {
return this.unsafeItemSelected(
return unsafeItemSelected(
this.state.schema.definitions.exploiter_classes.anyOf,
config.basic.exploiters.exploiter_classes
);
}
unsafePostBreachActionSelected(config) {
return this.unsafeItemSelected(
return unsafeItemSelected(
this.state.schema.definitions.post_breach_actions.anyOf,
config.monkey.post_breach.post_breach_actions
);
}
unsafeSystemInfoCollectorSelected(config) {
return this.unsafeItemSelected(
return unsafeItemSelected(
this.state.schema.definitions.system_info_collector_classes.anyOf,
config.monkey.system_info.system_info_collector_classes
);
}
unsafeItemSelected(options, selectedOptions) {
let item_safety = new Map();
options.forEach(i => item_safety[i.enum[0]] = i.safe);
for (let selected of selectedOptions) {
if (!item_safety[selected]) {
return true;
}
}
return false;
}
matrixSubmit = () => {
// Submit attack matrix
this.authFetch(ATTACK_URL,