Skip to content

Commit

Permalink
Change: fetch trash resources concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell committed Jan 4, 2024
1 parent e8965eb commit 53292ba
Showing 1 changed file with 171 additions and 100 deletions.
271 changes: 171 additions & 100 deletions src/gmp/commands/trashcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,107 +66,178 @@ class Trashcan extends HttpCommand {
}

get() {
const alerts = this.httpGet({cmd: 'get_trash_alerts'});
const configs = this.httpGet({cmd: 'get_trash_configs'});
const credentials = this.httpGet({cmd: 'get_trash_credentials'});
const filters = this.httpGet({cmd: 'get_trash_filters'});
const groups = this.httpGet({cmd: 'get_trash_groups'});
const notes = this.httpGet({cmd: 'get_trash_notes'});
const overrides = this.httpGet({cmd: 'get_trash_overrides'});
const permissions = this.httpGet({cmd: 'get_trash_permissions'});
const port_lists = this.httpGet({cmd: 'get_trash_port_lists'});
const report_formats = this.httpGet({cmd: 'get_trash_report_formats'});
const roles = this.httpGet({cmd: 'get_trash_roles'});
const scanners = this.httpGet({cmd: 'get_trash_scanners'});
const schedules = this.httpGet({cmd: 'get_trash_schedules'});
const tags = this.httpGet({cmd: 'get_trash_tags'});
const targets = this.httpGet({cmd: 'get_trash_targets'});
const rest = this.httpGet({cmd: 'get_trash'});
return Promise.all([targets, rest]).then(([response_targets, response]) => {
const targets_data = response_targets.data.get_trash;
const trash_data = response.data.get_trash;
const data = {};
if (isDefined(trash_data.get_alerts_response)) {
data.alert_list = map(trash_data.get_alerts_response.alert, model =>
Alert.fromElement(model),
);
}
if (isDefined(trash_data.get_configs_response)) {
data.config_list = map(trash_data.get_configs_response.config, model =>
Scanconfig.fromElement(model),
);
}
if (isDefined(trash_data.get_credentials_response)) {
data.credential_list = map(
trash_data.get_credentials_response.credential,
model => Credential.fromElement(model),
);
}
if (isDefined(trash_data.get_filters_response)) {
data.filter_list = map(trash_data.get_filters_response.filter, model =>
Filter.fromElement(model),
);
}
if (isDefined(trash_data.get_groups_response)) {
data.group_list = map(trash_data.get_groups_response.group, model =>
Group.fromElement(model),
);
}
if (isDefined(trash_data.get_notes_response)) {
data.note_list = map(trash_data.get_notes_response.note, model =>
Note.fromElement(model),
);
}
if (isDefined(trash_data.get_overrides_response)) {
data.override_list = map(
trash_data.get_overrides_response.override,
model => Override.fromElement(model),
);
}
if (isDefined(trash_data.get_permissions_response)) {
data.permission_list = map(
trash_data.get_permissions_response.permission,
model => Permission.fromElement(model),
);
}
if (isDefined(trash_data.get_port_lists_response)) {
data.port_list_list = map(
trash_data.get_port_lists_response.port_list,
model => PortList.fromElement(model),
);
}
if (isDefined(trash_data.get_report_formats_response)) {
data.report_format_list = map(
trash_data.get_report_formats_response.report_format,
model => ReportFormat.fromElement(model),
);
}
if (isDefined(trash_data.get_roles_response)) {
data.role_list = map(trash_data.get_roles_response.role, model =>
Role.fromElement(model),
);
}
if (isDefined(trash_data.get_scanners_response)) {
data.scanner_list = map(
trash_data.get_scanners_response.scanner,
model => Scanner.fromElement(model),
);
}
if (isDefined(trash_data.get_schedules_response)) {
data.schedule_list = map(
trash_data.get_schedules_response.schedule,
model => Schedule.fromElement(model),
);
}
if (isDefined(trash_data.get_tags_response)) {
data.tag_list = map(trash_data.get_tags_response.tag, model =>
Tag.fromElement(model),
);
}
if (isDefined(targets_data.get_targets_response)) {
data.target_list = map(
targets_data.get_targets_response.target,
model => Target.fromElement(model),
);
}
if (isDefined(trash_data.get_tasks_response)) {
data.task_list = map(trash_data.get_tasks_response.task, model =>
Task.fromElement(model),
);
}
if (isDefined(trash_data.get_tickets_response)) {
data.ticket_list = map(trash_data.get_tickets_response.ticket, model =>
Ticket.fromElement(model),
);
}
return response.setData(data);
});
const tasks = this.httpGet({cmd: 'get_trash_tasks'});
const tickets = this.httpGet({cmd: 'get_trash_tickets'});
return Promise.all([

Check warning on line 86 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L69-L86

Added lines #L69 - L86 were not covered by tests
alerts,
configs,
credentials,
filters,
groups,
notes,
overrides,
permissions,
port_lists,
report_formats,
roles,
scanners,
schedules,
tags,
targets,
tasks,
tickets,
]).then(
([
response_alerts,
response_configs,
response_credentials,
response_filters,
response_groups,
response_notes,
response_overrides,
response_permissions,
response_port_lists,
response_report_formats,
response_roles,
response_scanners,
response_schedules,
response_tags,
response_targets,
response_tasks,
response_tickets,
]) => {
const alerts_data = response_alerts.data.get_trash;
const configs_data = response_configs.data.get_trash;
const credentials_data = response_credentials.data.get_trash;
const filters_data = response_filters.data.get_trash;
const groups_data = response_groups.data.get_trash;
const notes_data = response_notes.data.get_trash;
const overrides_data = response_overrides.data.get_trash;
const permissions_data = response_permissions.data.get_trash;
const port_lists_data = response_port_lists.data.get_trash;
const report_formats_data = response_report_formats.data.get_trash;
const roles_data = response_roles.data.get_trash;
const scanners_data = response_scanners.data.get_trash;
const schedules_data = response_schedules.data.get_trash;
const tags_data = response_tags.data.get_trash;
const targets_data = response_targets.data.get_trash;
const tasks_data = response_tasks.data.get_trash;
const tickets_data = response_tickets.data.get_trash;
const data = {};

Check warning on line 141 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L123-L141

Added lines #L123 - L141 were not covered by tests
if (isDefined(alerts_data.get_alerts_response)) {
data.alert_list = map(alerts_data.get_alerts_response.alert, model =>
Alert.fromElement(model),

Check warning on line 144 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L143-L144

Added lines #L143 - L144 were not covered by tests
);
}
if (isDefined(configs_data.get_configs_response)) {
data.config_list = map(

Check warning on line 148 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L148

Added line #L148 was not covered by tests
configs_data.get_configs_response.config,
model => Scanconfig.fromElement(model),

Check warning on line 150 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L150

Added line #L150 was not covered by tests
);
}
if (isDefined(credentials_data.get_credentials_response)) {
data.credential_list = map(

Check warning on line 154 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L154

Added line #L154 was not covered by tests
credentials_data.get_credentials_response.credential,
model => Credential.fromElement(model),

Check warning on line 156 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L156

Added line #L156 was not covered by tests
);
}
if (isDefined(filters_data.get_filters_response)) {
data.filter_list = map(

Check warning on line 160 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L160

Added line #L160 was not covered by tests
filters_data.get_filters_response.filter,
model => Filter.fromElement(model),

Check warning on line 162 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L162

Added line #L162 was not covered by tests
);
}
if (isDefined(groups_data.get_groups_response)) {
data.group_list = map(groups_data.get_groups_response.group, model =>
Group.fromElement(model),

Check warning on line 167 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L166-L167

Added lines #L166 - L167 were not covered by tests
);
}
if (isDefined(notes_data.get_notes_response)) {
data.note_list = map(notes_data.get_notes_response.note, model =>
Note.fromElement(model),

Check warning on line 172 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L171-L172

Added lines #L171 - L172 were not covered by tests
);
}
if (isDefined(overrides_data.get_overrides_response)) {
data.override_list = map(

Check warning on line 176 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L176

Added line #L176 was not covered by tests
overrides_data.get_overrides_response.override,
model => Override.fromElement(model),

Check warning on line 178 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L178

Added line #L178 was not covered by tests
);
}
if (isDefined(permissions_data.get_permissions_response)) {
data.permission_list = map(

Check warning on line 182 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L182

Added line #L182 was not covered by tests
permissions_data.get_permissions_response.permission,
model => Permission.fromElement(model),

Check warning on line 184 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L184

Added line #L184 was not covered by tests
);
}
if (isDefined(port_lists_data.get_port_lists_response)) {
data.port_list_list = map(

Check warning on line 188 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L188

Added line #L188 was not covered by tests
port_lists_data.get_port_lists_response.port_list,
model => PortList.fromElement(model),

Check warning on line 190 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L190

Added line #L190 was not covered by tests
);
}
if (isDefined(report_formats_data.get_report_formats_response)) {
data.report_format_list = map(

Check warning on line 194 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L194

Added line #L194 was not covered by tests
report_formats_data.get_report_formats_response.report_format,
model => ReportFormat.fromElement(model),

Check warning on line 196 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L196

Added line #L196 was not covered by tests
);
}
if (isDefined(roles_data.get_roles_response)) {
data.role_list = map(roles_data.get_roles_response.role, model =>
Role.fromElement(model),

Check warning on line 201 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L200-L201

Added lines #L200 - L201 were not covered by tests
);
}
if (isDefined(scanners_data.get_scanners_response)) {
data.scanner_list = map(

Check warning on line 205 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L205

Added line #L205 was not covered by tests
scanners_data.get_scanners_response.scanner,
model => Scanner.fromElement(model),

Check warning on line 207 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L207

Added line #L207 was not covered by tests
);
}
if (isDefined(schedules_data.get_schedules_response)) {
data.schedule_list = map(

Check warning on line 211 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L211

Added line #L211 was not covered by tests
schedules_data.get_schedules_response.schedule,
model => Schedule.fromElement(model),

Check warning on line 213 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L213

Added line #L213 was not covered by tests
);
}
if (isDefined(tags_data.get_tags_response)) {
data.tag_list = map(tags_data.get_tags_response.tag, model =>
Tag.fromElement(model),

Check warning on line 218 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L217-L218

Added lines #L217 - L218 were not covered by tests
);
}
if (isDefined(targets_data.get_targets_response)) {
data.target_list = map(

Check warning on line 222 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L222

Added line #L222 was not covered by tests
targets_data.get_targets_response.target,
model => Target.fromElement(model),

Check warning on line 224 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L224

Added line #L224 was not covered by tests
);
}
if (isDefined(tasks_data.get_tasks_response)) {
data.task_list = map(tasks_data.get_tasks_response.task, model =>
Task.fromElement(model),

Check warning on line 229 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L228-L229

Added lines #L228 - L229 were not covered by tests
);
}
if (isDefined(tickets_data.get_tickets_response)) {
data.ticket_list = map(

Check warning on line 233 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L233

Added line #L233 was not covered by tests
tickets_data.get_tickets_response.ticket,
model => Ticket.fromElement(model),

Check warning on line 235 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L235

Added line #L235 was not covered by tests
);
}
return response_targets.setData(data);

Check warning on line 238 in src/gmp/commands/trashcan.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/trashcan.js#L238

Added line #L238 was not covered by tests
},
);
}
}

Expand Down

0 comments on commit 53292ba

Please sign in to comment.