Skip to content

Commit

Permalink
Merge pull request #1495 from sarahd93/explicit_compliance_gsa8
Browse files Browse the repository at this point in the history
Explicit Compliance
  • Loading branch information
swaterkamp committed Jul 31, 2019
2 parents bc10b35 + 4787a67 commit f67e2fe
Show file tree
Hide file tree
Showing 61 changed files with 8,324 additions and 139 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]

### Added
- Added Explicit Compliance [#1495](https://github.com/greenbone/gsa/pull/1495)
- added tasktrendgroup component for tasks filter dialog [#1511](https://github.com/greenbone/gsa/pull/1511)
- Added HorizontalSep component for horizontal lists. [#1494](https://github.com/greenbone/gsa/pull/1494)
- added BooleanFilterGroup and changed notes filter dialog [#1493](https://github.com/greenbone/gsa/pull/1493)
Expand Down
4 changes: 4 additions & 0 deletions gsa/src/gmp/capabilities/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {map} from '../utils/array';
import {pluralizeType} from '../utils/entitytype';

const types = {
audit: 'task',
audits: 'task',
host: 'asset',
hosts: 'asset',
os: 'asset',
Expand All @@ -43,6 +45,8 @@ const types = {
certbunds: 'info',
secinfo: 'info',
secinfos: 'info',
policy: 'config',
policies: 'config',
portlist: 'port_list',
portlists: 'port_list',
reportformat: 'report_format',
Expand Down
2 changes: 2 additions & 0 deletions gsa/src/gmp/commands/__tests__/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe('TaskCommand tests', () => {
source_iface: undefined,
task_id: 'task1',
target_id: 0,
usage_type: 'scan',
},
});

Expand Down Expand Up @@ -287,6 +288,7 @@ describe('TaskCommand tests', () => {
source_iface: 'eth0',
task_id: 'task1',
target_id: 't1',
usage_type: 'scan',
},
});

Expand Down
219 changes: 219 additions & 0 deletions gsa/src/gmp/commands/audits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import logger from '../log';

import registerCommand from '../command';

import {NO_VALUE} from '../parser';

import Audit, {HOSTS_ORDERING_SEQUENTIAL} from '../models/audit';

import EntitiesCommand from './entities';
import EntityCommand from './entity';

const log = logger.getLogger('gmp.commands.audits');

export class AuditCommand extends EntityCommand {
constructor(http) {
super(http, 'task', Audit);
}

start({id}) {
log.debug('Starting audit...');

return this.httpPost({
cmd: 'start_task',
id,
})
.then(() => {
log.debug('Started audit');
return this.get({id});
})
.catch(err => {
log.error('An error occurred while starting the audit', id, err);
throw err;
});
}

stop({id}) {
log.debug('Stopping audit');

return this.httpPost({
cmd: 'stop_task',
id,
})
.then(() => {
log.debug('Stopped audit');
return this.get({id});
})
.catch(err => {
log.error('An error occurred while stopping the audit', id, err);
throw err;
});
}

resume({id}) {
return this.httpPost({
cmd: 'resume_task',
id,
})
.then(() => {
log.debug('Resumed audit');
return this.get({id});
})
.catch(err => {
log.error('An error occurred while resuming the audit', id, err);
throw err;
});
}

create(args) {
const {
addTag,
alertIds = [],
alterable,
applyOverrides,
autoDelete,
autoDeleteData,
comment = '',
policyId,
hostsOrdering,
inAssets,
maxChecks,
maxHosts,
minQod,
name,
scannerType,
scannerId,
scheduleId,
schedulePeriods,
sourceIface,
tagId,
targetId,
} = args;

const data = {
cmd: 'create_task',
add_tag: addTag,
'alert_ids:': alertIds,
alterable,
apply_overrides: applyOverrides,
auto_delete: autoDelete,
auto_delete_data: autoDeleteData,
comment,
config_id: policyId,
hosts_ordering: hostsOrdering,
in_assets: inAssets,
max_checks: maxChecks,
max_hosts: maxHosts,
min_qod: minQod,
name,
scanner_id: scannerId,
scanner_type: scannerType,
schedule_id: scheduleId,
schedule_periods: schedulePeriods,
source_iface: sourceIface,
tag_id: tagId,
target_id: targetId,
usage_type: 'audit',
};
log.debug('Creating audit', args, data);
return this.action(data);
}

save(args) {
const {
alertIds = [],
alterable,
autoDelete,
autoDeleteData,
applyOverrides,
comment = '',
policyId = NO_VALUE,
hostsOrdering = HOSTS_ORDERING_SEQUENTIAL,
id,
inAssets,
maxChecks,
maxHosts,
minQod,
name,
scannerId = NO_VALUE,
scannerType,
scheduleId = NO_VALUE,
schedulePeriods,
targetId = NO_VALUE,
sourceIface,
} = args;
const data = {
alterable,
'alert_ids:': alertIds,
apply_overrides: applyOverrides,
auto_delete: autoDelete,
auto_delete_data: autoDeleteData,
comment,
config_id: policyId,
cmd: 'save_task',
hosts_ordering: hostsOrdering,
in_assets: inAssets,
max_checks: maxChecks,
max_hosts: maxHosts,
min_qod: minQod,
name,
scanner_id: scannerId,
scanner_type: scannerType,
schedule_id: scheduleId,
schedule_periods: schedulePeriods,
source_iface: sourceIface,
target_id: targetId,
task_id: id,
usage_type: 'audit',
};
log.debug('Saving audit', args, data);
return this.action(data);
}

getElementFromRoot(root) {
return root.get_task.get_tasks_response.task;
}
}

class AuditsCommand extends EntitiesCommand {
constructor(http) {
super(http, 'task', Audit);
}

getEntitiesResponse(root) {
return root.get_tasks.get_tasks_response;
}

get(params, options) {
params = {...params, usage_type: 'audit'};
return this.httpGet(params, options).then(response => {
const {entities, filter, counts} = this.getCollectionListFromRoot(
response.data,
);
return response.set(entities, {filter, counts});
});
}
}

registerCommand('audit', AuditCommand);
registerCommand('audits', AuditsCommand);

// vim: set ts=2 sw=2 tw=80:
12 changes: 12 additions & 0 deletions gsa/src/gmp/commands/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class PermissionCommand extends EntityCommand {
resourceType,
subjectType,
}) {
if (resourceType === 'policy') {
resourceType = 'config';
} else if (resourceType === 'audit') {
resourceType = 'task';
}

const data = {
cmd: 'create_permission',
comment,
Expand Down Expand Up @@ -109,6 +115,12 @@ class PermissionsCommand extends EntitiesCommand {
includeRelated,
related = [],
}) {
if (entityType === 'policy') {
entityType = 'config';
} else if (entityType === 'audit') {
entityType = 'task';
}

const data = {
cmd: 'create_permissions',
comment,
Expand Down
Loading

0 comments on commit f67e2fe

Please sign in to comment.