Passed
Pull Request — master (#123)
by Juan José
01:49
created

gmp.xml._GmpCommandFactory.verify_agent_command()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
coding-style introduced by
Too many lines in module (1995/1000)
Loading history...
2
# Copyright (C) 2018 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
import defusedxml.lxml as secET
20
21
from lxml import etree
22
23
FILTER_NAMES = [
24
    'Agent',
25
    'Alert',
26
    'Asset',
27
    'Config',
28
    'Credential',
29
    'Filter',
30
    'Group',
31
    'Note',
32
    'Override',
33
    'Permission',
34
    'Port List',
35
    'Report',
36
    'Report Format',
37
    'Result',
38
    'Role',
39
    'Schedule',
40
    'SecInfo',
41
    'Tag',
42
    'Target',
43
    'Task',
44
    'User',
45
]
46
47
class XmlCommandElement:
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
48
49
    def __init__(self, element):
50
        self._element = element
51
52
    def add_element(self, name, text=None, attrs=None):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
53
        node = etree.SubElement(self._element, name, attrib=attrs)
0 ignored issues
show
Bug introduced by
The Module lxml.etree does not seem to have a member named SubElement.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
54
        node.text = text
55
        return XmlCommandElement(node)
56
57
    def set_attribute(self, name, value):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
58
        self._element.set(name, value)
59
60
    def set_attributes(self, attrs):
61
        """Set several attributes at once.
62
63
        Arguments:
64
            attrs (dict): Attributes to be set on the element
65
        """
66
        for key, value in attrs.items():
67
            self._element.set(key, value)
68
69
    def append_xml_str(self, xml_text):
70
        """Append a xml element in string format."""
71
        node = secET.fromstring(xml_text)
72
        self._element.append(node)
73
74
    def to_string(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
75
        return etree.tostring(self._element).decode('utf-8')
0 ignored issues
show
Bug introduced by
The Module lxml.etree does not seem to have a member named tostring.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
76
77
    def __str__(self):
78
        return self.to_string()
79
80
81
class XmlCommand(XmlCommandElement):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
82
83
    def __init__(self, name):
84
        super().__init__(etree.Element(name))
0 ignored issues
show
Bug introduced by
The Module lxml.etree does not seem to have a member named Element.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
85
86
87
class _GmpCommandFactory:
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
best-practice introduced by
Too many public methods (110/20)
Loading history...
88
89
    """Factory to create gmp - Greenbone Manangement Protocol - commands
90
    """
91
92
    def create_agent_command(self, installer, signature, name, comment='',
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
best-practice introduced by
Too many arguments (8/5)
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
93
                             copy='', howto_install='', howto_use=''):
94
95
        cmd = XmlCommand('create_agent')
96
        cmd.add_element('installer', installer)
97
        cmd.add_element('signature', signature)
98
        cmd.add_element('name', name)
99
100
        if comment:
101
            cmd.add_element('comment', comment)
102
103
        if copy:
104
            cmd.add_element('copy', copy)
105
106
        if howto_install:
107
            cmd.add_element('howto_install', howto_install)
108
109
        if howto_use:
110
            cmd.add_element('howto_use', howto_use)
111
112
        return cmd.to_string()
113
114
    def create_alert_command(self, name, condition, event, method, filter_id='',
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
best-practice introduced by
Too many arguments (8/5)
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
115
                             copy='', comment=''):
116
117
        cmd = XmlCommand('create_alert')
118
        cmd.add_element('name', name)
119
120
        if len(condition) > 1:
121
            conditions = cmd.add_element('condition', condition[0])
122
            for value, key in condition[1].items():
123
                _data = conditions.add_element('data', value)
124
                _data.add_element('name', key)
125
126
        elif condition[0] == "Always":
127
            conditions = cmd.add_element('condition', condition[0])
128
129
        if len(event) > 1:
130
            events = cmd.add_element('event', event[0])
131
            for value, key in event[1].items():
132
                _data = events.add_element('data', value)
133
                _data.add_element('name', key)
134
135
        if len(method) > 1:
136
            methods = cmd.add_element('method', method[0])
137
            for value, key in method[1].items():
138
                _data = methods.add_element('data', value)
139
                _data.add_element('name', key)
140
141
        if filter_id:
142
            cmd.add_element('filter', attrs={'id': filter_id})
143
144
        if copy:
145
            cmd.add_element('copy', copy)
146
147
        if comment:
148
            cmd.add_element('comment', comment)
149
150
        return cmd.to_string()
151
152
    def create_asset_command(self, name, asset_type, comment=''):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
153
        if asset_type not in ('host', 'os'):
154
            raise ValueError('create_asset requires asset_type to be either '
155
                             'host or os')
156
        cmd = XmlCommand('create_asset')
157
        asset = cmd.add_element('asset')
158
        asset.add_element('type', asset_type)
159
        asset.add_element('name', name)
160
161
        if comment:
162
            asset.add_element('comment', comment)
163
164
        return cmd.to_string()
165
166
    def create_authenticate_command(self, username, password):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
167
        """Generates string for authentification on gvmd
168
169
        Creates the gmp authentication xml string.
170
        Inserts the username and password into it.
171
172
        Keyword Arguments:
173
            username {str} -- Username for GVM User
174
            password {str} -- Password for GVM User
175
        """
176
        cmd = XmlCommand('authenticate')
177
178
        credentials = cmd.add_element('credentials')
179
        credentials.add_element('username', username)
180
        credentials.add_element('password', password)
181
182
        return cmd.to_string()
183
184
    def create_config_command(self, copy_id, name):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
185
        """Generates xml string for create config on gvmd."""
186
        cmd = XmlCommand('create_config')
187
        cmd.add_element('copy', copy_id)
188
        cmd.add_element('name', name)
189
190
        return cmd.to_string()
191
192 View Code Duplication
    def create_credential_command(self, name, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
193
        """Generates xml string for create credential on gvmd."""
194
        cmd = XmlCommand('create_credential')
195
        cmd.add_element('name', name)
196
197
        comment = kwargs.get('comment', '')
198
        if comment:
199
            cmd.add_element('comment', comment)
200
201
        copy = kwargs.get('copy', '')
202
        if copy:
203
            cmd.add_element('copy', copy)
204
205
        allow_insecure = kwargs.get('allow_insecure', '')
206
        if allow_insecure:
207
            cmd.add_element('allow_insecure', allow_insecure)
208
209
        certificate = kwargs.get('certificate', '')
210
        if certificate:
211
            cmd.add_element('certificate', certificate)
212
213
        key = kwargs.get('key', '')
214
        if key:
215
            phrase = key['phrase']
216
            private = key['private']
217
            if not phrase:
218
                raise ValueError('create_credential requires a phrase element')
219
            if not private:
220
                raise ValueError('create_credential requires a '
221
                                 'private element')
222
223
            _xmlkey = cmd.add_element('key')
224
            _xmlkey.add_element('phrase', phrase)
225
            _xmlkey.add_element('private', private)
226
227
        login = kwargs.get('login', '')
228
        if login:
229
            cmd.add_element('login', login)
230
231
        password = kwargs.get('password', '')
232
        if password:
233
            cmd.add_element('password', password)
234
235
        auth_algorithm = kwargs.get('auth_algorithm', '')
236
        if auth_algorithm:
237
            if auth_algorithm not in ('md5', 'sha1'):
238
                raise ValueError('create_credential requires auth_algorithm '
239
                                 'to be either md5 or sha1')
240
            cmd.add_element('auth_algorithm', auth_algorithm)
241
242
        community = kwargs.get('community', '')
243
        if community:
244
            cmd.add_element('community', community)
245
246
        privacy = kwargs.get('privacy', '')
247
        if privacy:
248
            algorithm = privacy.algorithm
249
            if algorithm not in ('aes', 'des'):
250
                raise ValueError('create_credential requires algorithm '
251
                                 'to be either aes or des')
252
            p_password = privacy.password
253
            _xmlprivacy = cmd.add_element('privacy')
254
            _xmlprivacy.add_element('algorithm', algorithm)
255
            _xmlprivacy.add_element('password', p_password)
256
257
        cred_type = kwargs.get('type', '')
258
        if cred_type:
259
            if cred_type not in ('cc', 'snmp', 'up', 'usk'):
260
                raise ValueError('create_credential requires type '
261
                                 'to be either cc, snmp, up or usk')
262
            cmd.add_element('type', cred_type)
263
264
        return cmd.to_string()
265
266
    def create_filter_command(self, name, make_unique, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
267
        """Generates xml string for create filter on gvmd."""
268
269
        cmd = XmlCommand('create_filter')
270
        _xmlname = cmd.add_element('name', name)
271
        if make_unique:
272
            _xmlname.add_element('make_unique', '1')
273
        else:
274
            _xmlname.add_element('make_unique', '0')
275
276
        comment = kwargs.get('comment', '')
277
        if comment:
278
            cmd.add_element('comment', comment)
279
280
        copy = kwargs.get('copy', '')
281
        if copy:
282
            cmd.add_element('copy', copy)
283
284
        term = kwargs.get('term', '')
285
        if term:
286
            cmd.add_element('term', term)
287
288
        filter_type = kwargs.get('type', '')
289
        if filter_type:
290
            if filter_type not in FILTER_NAMES:
291
                raise ValueError('create_filter requires type '
292
                                 'to be either cc, snmp, up or usk')
293
            cmd.add_element('type', filter_type)
294
295
        return cmd.to_string()
296
297
    def create_group_command(self, name, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
298
        """Generates xml string for create group on gvmd."""
299
300
        cmd = XmlCommand('create_group')
301
        cmd.add_element('name', name)
302
303
        comment = kwargs.get('comment', '')
304
        if comment:
305
            cmd.add_element('comment', comment)
306
307
        copy = kwargs.get('copy', '')
308
        if copy:
309
            cmd.add_element('copy', copy)
310
311
        special = kwargs.get('special', '')
312
        if special:
313
            _xmlspecial = cmd.add_element('specials')
314
            _xmlspecial.add_element('full')
315
316
        users = kwargs.get('users', '')
317
        if users:
318
            cmd.add_element('users', users)
319
320
        return cmd.to_string()
321
322
    def create_note_command(self, text, nvt_oid, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
323
        """Generates xml string for create note on gvmd."""
324
325
        cmd = XmlCommand('create_note')
326
        cmd.add_element('text', text)
327
        cmd.add_element('nvt', attrs={"oid": nvt_oid})
328
329
        active = kwargs.get('active', '')
330
        if active:
331
            cmd.add_element('active', active)
332
333
        comment = kwargs.get('comment', '')
334
        if comment:
335
            cmd.add_element('comment', comment)
336
337
        copy = kwargs.get('copy', '')
338
        if copy:
339
            cmd.add_element('copy', copy)
340
341
        hosts = kwargs.get('hosts', '')
342
        if hosts:
343
            cmd.add_element('hosts', hosts)
344
345
        port = kwargs.get('port', '')
346
        if port:
347
            cmd.add_element('port', port)
348
349
        result_id = kwargs.get('result_id', '')
350
        if result_id:
351
            cmd.add_element('result', attrs={'id': result_id})
352
353
        severity = kwargs.get('severity', '')
354
        if severity:
355
            cmd.add_element('severity', severity)
356
357
        task_id = kwargs.get('task_id', '')
358
        if task_id:
359
            cmd.add_element('task', attrs={'id': task_id})
360
361
        threat = kwargs.get('threat', '')
362
        if threat:
363
            cmd.add_element('threat', threat)
364
365
        return cmd.to_string()
366
367
    def create_override_command(self, text, nvt_oid, kwargs):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (17/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
368
        """Generates xml string for create override on gvmd."""
369
370
        cmd = XmlCommand('create_override')
371
        cmd.add_element('text', text)
372
        cmd.add_element('nvt', attrs={'oid': nvt_oid})
373
374
        active = kwargs.get('active', '')
375
        if active:
376
            cmd.add_element('active', active)
377
378
        comment = kwargs.get('comment', '')
379
        if comment:
380
            cmd.add_element('comment', comment)
381
382
        copy = kwargs.get('copy', '')
383
        if copy:
384
            cmd.add_element('copy', copy)
385
386
        hosts = kwargs.get('hosts', '')
387
        if hosts:
388
            cmd.add_element('hosts', hosts)
389
390
        port = kwargs.get('port', '')
391
        if port:
392
            cmd.add_element('port', port)
393
394
        result_id = kwargs.get('result_id', '')
395
        if result_id:
396
            cmd.add_element('result', attrs={'id': result_id})
397
398
        severity = kwargs.get('severity', '')
399
        if severity:
400
            cmd.add_element('severity', severity)
401
402
        new_severity = kwargs.get('new_severity', '')
403
        if new_severity:
404
            cmd.add_element('new_severity', new_severity)
405
406
        task_id = kwargs.get('task_id', '')
407
        if task_id:
408
            cmd.add_element('task', attrs={'id': task_id})
409
410
        threat = kwargs.get('threat', '')
411
        if threat:
412
            cmd.add_element('threat', threat)
413
414
        new_threat = kwargs.get('new_threat', '')
415
        if new_threat:
416
            cmd.add_element('new_threat', new_threat)
417
418
        return cmd.to_string()
419
420
    def create_permission_command(self, name, subject_id, type, kwargs):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
421
        # pretty(gmp.create_permission('get_version',
422
        # 'cc9cac5e-39a3-11e4-abae-406186ea4fc5', 'role'))
423
        # libs.gvm_connection.GMPError: Error in NAME
424
        # TODO: Research why!!
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
425
426
        if not name:
427
            raise ValueError('create_permission requires a name element')
428
        if not subject_id:
429
            raise ValueError('create_permission requires a subject_id element')
430
        if type not in ('user', 'group', 'role'):
431
            raise ValueError('create_permission requires type '
432
                             'to be either user, group or role')
433
434
        cmd = XmlCommand('create_permission')
435
        cmd.add_element('name', name)
436
        _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id})
437
        _xmlsubject.add_element('type', type)
438
439
        comment = kwargs.get('comment', '')
440
        if comment:
441
            cmd.add_element('comment', comment)
442
443
        copy = kwargs.get('copy', '')
444
        if copy:
445
            cmd.add_element('copy', copy)
446
447
        resource = kwargs.get('resource', '')
448
        if resource:
449
            resource_id = resource.id
450
            resource_type = resource.type
451
            _xmlresource = cmd.add_element('resource',
452
                                           attrs={'id': resource_id})
453
            _xmlresource.add_element('type', resource_type)
454
455
        return cmd.to_string()
456
457
    def create_port_list_command(self, name, port_range, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
458
        """Generates xml string for create port list on gvmd."""
459
        if not name:
460
            raise ValueError('create_port_list requires a name element')
461
        if not port_range:
462
            raise ValueError('create_port_list requires a port_range element')
463
464
        cmd = XmlCommand('create_port_list')
465
        cmd.add_element('name', name)
466
        cmd.add_element('port_range', port_range)
467
468
        comment = kwargs.get('comment', '')
469
        if comment:
470
            cmd.add_element('comment', comment)
471
472
        copy = kwargs.get('copy', '')
473
        if copy:
474
            cmd.add_element('copy', copy)
475
476
        return cmd.to_string()
477
478
    def create_port_range_command(self, port_list_id, start, end, type,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
best-practice introduced by
Too many arguments (6/5)
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
479
                                  comment=''):
480
        """Generates xml string for create port range on gvmd."""
481
482
        if not port_list_id:
483
            raise ValueError('create_port_range requires '
484
                             'a port_list_id element')
485
        if not type:
486
            raise ValueError('create_port_range requires a type element')
487
488
        cmd = XmlCommand('create_port_range')
489
        cmd.add_element('port_list', attrs={'id': port_list_id})
490
        cmd.add_element('start', start)
491
        cmd.add_element('end', end)
492
        cmd.add_element('type', type)
493
494
        if comment:
495
            cmd.add_element('comment', comment)
496
497
        return cmd.to_string()
498
499
    def create_report_command(self, report_xml_string, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
500
        """Generates xml string for create report on gvmd."""
501
502
        if not report_xml_string:
503
            raise ValueError('create_report requires a report')
504
505
        task_id = kwargs.get('task_id', '')
506
        task_name = kwargs.get('task_name', '')
507
508
        cmd = XmlCommand('create_report')
509
        comment = kwargs.get('comment', '')
510
        if task_id:
511
            cmd.add_element('task', attrs={'id': task_id})
512
        elif task_name:
513
            _xmltask = cmd.add_element('task')
514
            _xmltask.add_element('name', task_name)
515
            if comment:
516
                _xmltask.add_element('comment', comment)
517
        else:
518
            raise ValueError('create_report requires an id or name for a task')
519
520
        in_assets = kwargs.get('in_assets', '')
521
        if in_assets:
522
            cmd.add_element('in_assets', in_assets)
523
524
        cmd.append_xml_str(report_xml_string)
525
526
        return cmd.to_string()
527
528
    def create_role_command(self, name, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
529
        """Generates xml string for create role on gvmd."""
530
531
        if not name:
532
            raise ValueError('create_role requires a name element')
533
534
        cmd = XmlCommand('create_role')
535
        cmd.add_element('name', name)
536
537
        comment = kwargs.get('comment', '')
538
        if comment:
539
            cmd.add_element('comment', comment)
540
541
        copy = kwargs.get('copy', '')
542
        if copy:
543
            cmd.add_element('copy', copy)
544
545
        users = kwargs.get('users', '')
546
        if users:
547
            cmd.add_element('users', users)
548
549
        return cmd.to_string()
550
551
    def create_scanner_command(self, name, host, port, type, ca_pub,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
best-practice introduced by
Too many arguments (8/5)
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
552
                               credential_id, kwargs):
553
        """Generates xml string for create scanner on gvmd."""
554
        if not name:
555
            raise ValueError('create_scanner requires a name element')
556
        if not host:
557
            raise ValueError('create_scanner requires a host element')
558
        if not port:
559
            raise ValueError('create_scanner requires a port element')
560
        if not type:
561
            raise ValueError('create_scanner requires a type element')
562
        if not ca_pub:
563
            raise ValueError('create_scanner requires a ca_pub element')
564
        if not credential_id:
565
            raise ValueError('create_scanner requires a credential_id element')
566
567
        cmd = XmlCommand('create_scanner')
568
        cmd.add_element('name', name)
569
        cmd.add_element('host', host)
570
        cmd.add_element('port', port)
571
        cmd.add_element('type', type)
572
        cmd.add_element('ca_pub', ca_pub)
573
        cmd.add_element('credential', attrs={'id': str(credential_id)})
574
575
        comment = kwargs.get('comment', '')
576
        if comment:
577
            cmd.add_element('comment', comment)
578
579
        copy = kwargs.get('copy', '')
580
        if copy:
581
            cmd.add_element('copy', copy)
582
583
        return cmd.to_string()
584
585 View Code Duplication
    def create_schedule_command(self, name, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (19/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
586
        """Generates xml string for create schedule on gvmd."""
587
        if not name:
588
            raise ValueError('create_schedule requires a name element')
589
590
        cmd = XmlCommand('create_schedule')
591
        cmd.add_element('name', name)
592
593
        comment = kwargs.get('comment', '')
594
        if comment:
595
            cmd.add_element('comment', comment)
596
597
        copy = kwargs.get('copy', '')
598
        if copy:
599
            cmd.add_element('copy', copy)
600
601
        first_time = kwargs.get('first_time', '')
602
        if first_time:
603
            first_time_minute = first_time['minute']
604
            first_time_hour = first_time['hour']
605
            first_time_day_of_month = first_time['day_of_month']
606
            first_time_month = first_time['month']
607
            first_time_year = first_time['year']
608
609
            _xmlftime = cmd.add_element('first_time')
610
            _xmlftime.add_element('minute', first_time_minute)
611
            _xmlftime.add_element('hour', str(first_time_hour))
612
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
613
            _xmlftime.add_element('month', str(first_time_month))
614
            _xmlftime.add_element('year', str(first_time_year))
615
616
        duration = kwargs.get('duration', '')
617
        if len(duration) > 1:
618
            _xmlduration = cmd.add_element('duration', str(duration[0]))
619
            _xmlduration.add_element('unit', str(duration[1]))
620
621
        period = kwargs.get('period', '')
622
        if len(period) > 1:
623
            _xmlperiod = cmd.add_element('period', str(period[0]))
624
            _xmlperiod.add_element('unit', str(period[1]))
625
626
        timezone = kwargs.get('timezone', '')
627
        if timezone:
628
            cmd.add_element('timezone', str(timezone))
629
630
        return cmd.to_string()
631
632
    def create_tag_command(self, name, resource_id, resource_type, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
633
        """Generates xml string for create tag on gvmd."""
634
635
        cmd = XmlCommand('create_tag')
636
        cmd.add_element('name', name)
637
        _xmlresource = cmd.add_element('resource',
638
                                       attrs={'id': str(resource_id)})
639
        _xmlresource.add_element('type', resource_type)
640
641
        comment = kwargs.get('comment', '')
642
        if comment:
643
            cmd.add_element('comment', comment)
644
645
        copy = kwargs.get('copy', '')
646
        if copy:
647
            cmd.add_element('copy', copy)
648
649
        value = kwargs.get('value', '')
650
        if value:
651
            cmd.add_element('value', value)
652
653
        active = kwargs.get('active', '')
654
        if active:
655
            cmd.add_element('active', active)
656
657
        return cmd.to_string()
658
659
    def create_target_command(self, name, make_unique, kwargs):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (17/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
660
        """Generates xml string for create target on gvmd."""
661
        if not name:
662
            raise ValueError('create_target requires a name element')
663
664
        cmd = XmlCommand('create_target')
665
        _xmlname = cmd.add_element('name', name)
666
        if make_unique:
667
            _xmlname.add_element('make_unique', '1')
668
        else:
669
            _xmlname.add_element('make_unique', '0')
670
671
        if 'asset_hosts' in kwargs:
672
            hosts = kwargs.get('asset_hosts')
673
            filter = hosts['filter']
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in filter.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
674
            cmd.add_element('asset_hosts', attrs={'filter': str(filter)})
675
        elif 'hosts' in kwargs:
676
            hosts = kwargs.get('hosts')
677
            cmd.add_element('hosts', hosts)
678
        else:
679
            raise ValueError('create_target requires either a hosts or '
680
                             'an asset_hosts element')
681
682
        if 'comment' in kwargs:
683
            cmd.add_element('comment', kwargs.get('comment'))
684
685
        if 'copy' in kwargs:
686
            # NOTE: It seems that hosts/asset_hosts is silently ignored by the
687
            # server when copy is supplied. But for specification conformance
688
            # we raise the ValueError above and consider copy optional.
689
            cmd.add_element('copy', kwargs.get('copy'))
690
691
        if 'exclude_hosts' in kwargs:
692
            cmd.add_element('exclude_hosts', kwargs.get('exclude_hosts'))
693
694
        if 'ssh_credential' in kwargs:
695
            ssh_credential = kwargs.get('ssh_credential')
696
            if 'id' in ssh_credential:
697
                _xmlssh = cmd.add_element('ssh_credential', '',
698
                                          attrs={'id': ssh_credential['id']})
699
                if 'port' in ssh_credential:
700
                    _xmlssh.add_element('port', ssh_credential['port'])
701
            else:
702
                raise ValueError('ssh_credential requires an id attribute')
703
704
        if 'smb_credential' in kwargs:
705
            smb_credential = kwargs.get('smb_credential')
706
            if 'id' in smb_credential:
707
                cmd.add_element('smb_credential',
708
                                attrs={'id': smb_credential['id']})
709
            else:
710
                raise ValueError('smb_credential requires an id attribute')
711
712
        if 'esxi_credential' in kwargs:
713
            esxi_credential = kwargs.get('esxi_credential')
714
            if 'id' in esxi_credential:
715
                cmd.add_element('esxi_credential',
716
                                attrs={'id': esxi_credential['id']})
717
            else:
718
                raise ValueError('esxi_credential requires an id attribute')
719
720
        if 'snmp_credential' in kwargs:
721
            snmp_credential = kwargs.get('snmp_credential')
722
            if 'id' in snmp_credential:
723
                cmd.add_element('snmp_credential',
724
                                attrs={'id': snmp_credential['id']})
725
            else:
726
                raise ValueError('snmp_credential requires an id attribute')
727
728
        if 'alive_tests' in kwargs:
729
            # NOTE: As the alive_tests are referenced by their name and some
730
            # names contain ampersand ('&') characters it should be considered
731
            # replacing any characters special to XML in the variable with
732
            # their corresponding entities.
733
            cmd.add_element('alive_tests', kwargs.get('alive_tests'))
734
735
        if 'reverse_lookup_only' in kwargs:
736
            reverse_lookup_only = kwargs.get('reverse_lookup_only')
737
            if reverse_lookup_only:
738
                cmd.add_element('reverse_lookup_only', '1')
739
            else:
740
                cmd.add_element('reverse_lookup_only', '0')
741
742
        if 'reverse_lookup_unify' in kwargs:
743
            reverse_lookup_unify = kwargs.get('reverse_lookup_unify')
744
            if reverse_lookup_unify:
745
                cmd.add_element('reverse_lookup_unify', '1')
746
            else:
747
                cmd.add_element('reverse_lookup_unify', '0')
748
749
        if 'port_range' in kwargs:
750
            cmd.add_element('port_range', kwargs.get('port_range'))
751
752
        if 'port_list' in kwargs:
753
            port_list = kwargs.get('port_list')
754
            if 'id' in port_list:
755
                cmd.add_element('port_list',
756
                                attrs={'id': str(port_list['id'])})
757
            else:
758
                raise ValueError('port_list requires an id attribute')
759
760
        return cmd.to_string()
761
762
    def create_task_command(self, name, config_id, target_id, scanner_id,
0 ignored issues
show
best-practice introduced by
Too many arguments (7/5)
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
763
                            alert_ids=None, comment=''):
764
        """Generates xml string for create task on gvmd."""
765
766
        if alert_ids is None:
767
            alert_ids = []
768
        cmd = XmlCommand('create_task')
769
        cmd.add_element('name', name)
770
        cmd.add_element('comment', comment)
771
        cmd.add_element('config', attrs={'id': config_id})
772
        cmd.add_element('target', attrs={'id': target_id})
773
        cmd.add_element('scanner', attrs={'id': scanner_id})
774
775
        #if given the alert_id is wrapped and integrated suitably as xml
776
        if len(alert_ids) > 0:
0 ignored issues
show
Unused Code introduced by
Do not use len(SEQUENCE) as condition value
Loading history...
777
            if isinstance(alert_ids, str):
778
                #if a single id is given as a string wrap it into a list
779
                alert_ids = [alert_ids]
780
            if isinstance(alert_ids, list):
781
                #parse all given alert id's
782
                for alert in alert_ids:
783
                    cmd.add_element('alert', attrs={'id': str(alert)})
784
785
        return cmd.to_string()
786
787
    def create_user_command(self, name, password, copy='', hosts_allow='0',
0 ignored issues
show
best-practice introduced by
Too many arguments (9/5)
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
788
                            ifaces_allow='0', role_ids=(), hosts=None,
789
                            ifaces=None):
790
        """Generates xml string for create user on gvmd."""
791
        cmd = XmlCommand('create_user')
792
        cmd.add_element('name', name)
793
794
        if copy:
795
            cmd.add_element('copy', copy)
796
797
        if password:
798
            cmd.add_element('password', password)
799
800
        if hosts is not None:
801
            cmd.add_element('hosts', hosts, attrs={'allow': str(hosts_allow)})
802
803
        if ifaces is not None:
804
            cmd.add_element('ifaces', ifaces,
805
                            attrs={'allow': str(ifaces_allow)})
806
807
        if len(role_ids) > 0:
0 ignored issues
show
Unused Code introduced by
Do not use len(SEQUENCE) as condition value
Loading history...
808
            for role in role_ids:
809
                cmd.add_element('role', attrs={'allow': str(role)})
810
811
        return cmd.to_string()
812
813
    def modify_agent_command(self, agent_id, name='', comment=''):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
814
        """Generates xml string for modify agent on gvmd."""
815
        if not agent_id:
816
            raise ValueError('modify_agent requires an agent_id element')
817
818
        cmd = XmlCommand('modify_agent')
819
        cmd.set_attribute('agent_id', str(agent_id))
820
        if name:
821
            cmd.add_element('name', name)
822
        if comment:
823
            cmd.add_element('comment', comment)
824
825
        return cmd.to_string()
826
827
    def modify_alert_command(self, alert_id, kwargs):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (17/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
828
        """Generates xml string for modify alert on gvmd."""
829
830
        if not alert_id:
831
            raise ValueError('modify_alert requires an agent_id element')
832
833
        cmd = XmlCommand('modify_alert')
834
        cmd.set_attribute('alert_id', str(alert_id))
835
836
        name = kwargs.get('name', '')
837
        if name:
838
            cmd.add_element('name', name)
839
840
        comment = kwargs.get('comment', '')
841
        if comment:
842
            cmd.add_element('comment', comment)
843
844
        filter_id = kwargs.get('filter_id', '')
845
        if filter_id:
846
            cmd.add_element('filter', attrs={'id': filter_id})
847
848
        event = kwargs.get('event', '')
849
        if len(event) > 1:
850
            _xmlevent = cmd.add_element('event', event[0])
851
            for value, key in event[1].items():
852
                _xmldata = _xmlevent.add_element('data', value)
853
                _xmldata.add_element('name', key)
854
855
        condition = kwargs.get('condition', '')
856
        if len(condition) > 1:
857
            _xmlcond = cmd.add_element('condition', condition[0])
858
            for value, key in condition[1].items():
859
                _xmldata = _xmlcond.add_element('data', value)
860
                _xmldata.add_element('name', key)
861
862
        method = kwargs.get('method', '')
863
        if len(method) > 1:
864
            _xmlmethod = cmd.add_element('method', method[0])
865
            for value, key in method[1].items():
866
                _xmldata = _xmlmethod.add_element('data', value)
867
                _xmldata.add_element('name', key)
868
869
        return cmd.to_string()
870
871
    def modify_asset_command(self, asset_id, comment):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
872
        """Generates xml string for modify asset on gvmd."""
873
        cmd = XmlCommand('modify_asset')
874
        cmd.set_attribute('asset_id', asset_id)
875
        cmd.add_element('comment', comment)
876
        return cmd.to_string()
877
878
    def modify_auth_command(self, group_name, auth_conf_settings):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
879
        """Generates xml string for modify auth on gvmd."""
880
        if not group_name:
881
            raise ValueError('modify_auth requires a group element '
882
                             'with a name attribute')
883
        if not auth_conf_settings:
884
            raise ValueError('modify_auth requires '
885
                             'an auth_conf_settings element')
886
        cmd = XmlCommand('modify_auth')
887
        _xmlgroup = cmd.add_element('group', attrs={'name': str(group_name)})
888
889
        for key, value in auth_conf_settings.items():
890
            _xmlauthconf = _xmlgroup.add_element('auth_conf_setting')
891
            _xmlauthconf.add_element('key', key)
892
            _xmlauthconf.add_element('value', value)
893
894
        return cmd.to_string()
895
896
    def modify_config_command(self, selection, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
897
        """Generates xml string for modify config on gvmd."""
898
        if selection not in ('nvt_pref', 'sca_pref',
899
                             'family_selection', 'nvt_selection'):
900
            raise ValueError('selection must be one of nvt_pref, sca_pref, '
901
                             'family_selection or nvt_selection')
902
        config_id = kwargs.get('config_id')
903
904
        cmd = XmlCommand('modify_config')
905
        cmd.set_attribute('config_id', str(config_id))
906
907
        if selection in 'nvt_pref':
908
            nvt_oid = kwargs.get('nvt_oid')
909
            name = kwargs.get('name')
910
            value = kwargs.get('value')
911
            _xmlpref = cmd.add_element('preference')
912
            _xmlpref.add_element('nvt', attrs={'oid': nvt_oid})
913
            _xmlpref.add_element('name', name)
914
            _xmlpref.add_element('value', value)
915
916
        elif selection in 'nvt_selection':
917
            nvt_oid = kwargs.get('nvt_oid')
918
            family = kwargs.get('family')
919
            _xmlnvtsel = cmd.add_element('nvt_selection')
920
            _xmlnvtsel.add_element('family', family)
921
922
            if isinstance(nvt_oid, list):
923
                for nvt in nvt_oid:
924
                    _xmlnvtsel.add_element('nvt', attrs={'oid': nvt})
925
            else:
926
                _xmlnvtsel.add_element('nvt', attrs={'oid': nvt_oid})
927
928
        elif selection in 'family_selection':
929
            family = kwargs.get('family')
930
            _xmlfamsel = cmd.add_element('family_selection')
931
            _xmlfamsel.add_element('growing', '1')
932
            _xmlfamily = _xmlfamsel.add_element('family')
933
            _xmlfamily.add_element('name', family)
934
            _xmlfamily.add_element('all', '1')
935
            _xmlfamily.add_element('growing', '1')
936
        else:
937
            raise NotImplementedError
938
939
        return cmd.to_string()
940
941 View Code Duplication
    def modify_credential_command(self, credential_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
942
        """Generates xml string for modify credential on gvmd."""
943
        if not credential_id:
944
            raise ValueError('modify_credential requires '
945
                             'a credential_id attribute')
946
947
        cmd = XmlCommand('modify_credential')
948
        cmd.set_attribute('credential_id', credential_id)
949
950
        comment = kwargs.get('comment', '')
951
        if comment:
952
            cmd.add_element('comment', comment)
953
954
        name = kwargs.get('name', '')
955
        if name:
956
            cmd.add_element('name', name)
957
958
        allow_insecure = kwargs.get('allow_insecure', '')
959
        if allow_insecure:
960
            cmd.add_element('allow_insecure', allow_insecure)
961
962
        certificate = kwargs.get('certificate', '')
963
        if certificate:
964
            cmd.add_element('certificate', certificate)
965
966
        key = kwargs.get('key', '')
967
        if key:
968
            phrase = key['phrase']
969
            private = key['private']
970
            if not phrase:
971
                raise ValueError('modify_credential requires a phrase element')
972
            if not private:
973
                raise ValueError('modify_credential requires '
974
                                 'a private element')
975
            _xmlkey = cmd.add_element('key')
976
            _xmlkey.add_element('phrase', phrase)
977
            _xmlkey.add_element('private', private)
978
979
        login = kwargs.get('login', '')
980
        if login:
981
            cmd.add_element('login', login)
982
983
        password = kwargs.get('password', '')
984
        if password:
985
            cmd.add_element('password', password)
986
987
        auth_algorithm = kwargs.get('auth_algorithm', '')
988
        if auth_algorithm:
989
            if auth_algorithm not in ('md5', 'sha1'):
990
                raise ValueError('modify_credential requires auth_algorithm '
991
                                 'to be either md5 or sha1')
992
            cmd.add_element('auth_algorithm', auth_algorithm)
993
994
        community = kwargs.get('community', '')
995
        if community:
996
            cmd.add_element('community', community)
997
998
        privacy = kwargs.get('privacy', '')
999
        if privacy:
1000
            algorithm = privacy.algorithm
1001
            if algorithm not in ('aes', 'des'):
1002
                raise ValueError('modify_credential requires algorithm '
1003
                                 'to be either aes or des')
1004
            p_password = privacy.password
1005
            _xmlprivacy = cmd.add_element('privacy')
1006
            _xmlprivacy.add_element('algorithm', algorithm)
1007
            _xmlprivacy.add_element('password', p_password)
1008
1009
        cred_type = kwargs.get('type', '')
1010
        if cred_type:
1011
            if cred_type not in ('cc', 'snmp', 'up', 'usk'):
1012
                raise ValueError('modify_credential requires type '
1013
                                 'to be either cc, snmp, up or usk')
1014
            cmd.add_element('type', cred_type)
1015
1016
        return cmd.to_string()
1017
1018
    def modify_filter_command(self, filter_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1019
        """Generates xml string for modify filter on gvmd."""
1020
        if not filter_id:
1021
            raise ValueError('modify_filter requires a filter_id attribute')
1022
1023
        cmd = XmlCommand('modify_filter')
1024
        cmd.set_attribute('filter_id', filter_id)
1025
1026
        comment = kwargs.get('comment', '')
1027
        if comment:
1028
            cmd.add_element('comment', comment)
1029
1030
        name = kwargs.get('name', '')
1031
        if name:
1032
            cmd.add_element('name', name)
1033
1034
        copy = kwargs.get('copy', '')
1035
        if copy:
1036
            cmd.add_element('copy', copy)
1037
1038
        term = kwargs.get('term', '')
1039
        if term:
1040
            cmd.add_element('term', term)
1041
1042
        filter_type = kwargs.get('type', '')
1043
        if filter_type:
1044
            if filter_type not in ('cc', 'snmp', 'up', 'usk'):
1045
                raise ValueError('modify_filter requires type '
1046
                                 'to be either cc, snmp, up or usk')
1047
            cmd.add_element('type', filter_type)
1048
1049
        return cmd.to_string()
1050
1051 View Code Duplication
    def modify_group_command(self, group_id, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1052
        """Generates xml string for modify group on gvmd."""
1053
        if not group_id:
1054
            raise ValueError('modify_group requires a group_id attribute')
1055
1056
        cmd = XmlCommand('modify_group')
1057
        cmd.set_attribute('group_id', group_id)
1058
1059
        comment = kwargs.get('comment', '')
1060
        if comment:
1061
            cmd.add_element('comment', comment)
1062
1063
        name = kwargs.get('name', '')
1064
        if name:
1065
            cmd.add_element('name', name)
1066
1067
        users = kwargs.get('users', '')
1068
        if users:
1069
            cmd.add_element('users', users)
1070
1071
        return cmd.to_string()
1072
1073
    def modify_note_command(self, note_id, text, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1074
        """Generates xml string for modify note on gvmd."""
1075
        if not note_id:
1076
            raise ValueError('modify_note requires a note_id attribute')
1077
        if not text:
1078
            raise ValueError('modify_note requires a text element')
1079
1080
        cmd = XmlCommand('modify_note')
1081
        cmd.set_attribute('note_id', note_id)
1082
        cmd.add_element('text', text)
1083
1084
        active = kwargs.get('active', '')
1085
        if active:
1086
            cmd.add_element('active', active)
1087
1088
        hosts = kwargs.get('hosts', '')
1089
        if hosts:
1090
            cmd.add_element('hosts', hosts)
1091
1092
        port = kwargs.get('port', '')
1093
        if port:
1094
            cmd.add_element('port', port)
1095
1096
        result_id = kwargs.get('result_id', '')
1097
        if result_id:
1098
            cmd.add_element('result', attrs={'id': result_id})
1099
1100
        severity = kwargs.get('severity', '')
1101
        if severity:
1102
            cmd.add_element('severity', severity)
1103
1104
        task_id = kwargs.get('task_id', '')
1105
        if task_id:
1106
            cmd.add_element('task', attrs={'id': task_id})
1107
1108
        threat = kwargs.get('threat', '')
1109
        if threat:
1110
            cmd.add_element('threat', threat)
1111
1112
        return cmd.to_string()
1113
1114
    def modify_override_command(self, override_id, text, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1115
        """Generates xml string for modify override on gvmd."""
1116
        cmd = XmlCommand('modify_override')
1117
        cmd.set_attribute('override_id', override_id)
1118
        cmd.add_element('text', text)
1119
1120
        active = kwargs.get('active', '')
1121
        if active:
1122
            cmd.add_element('active', active)
1123
1124
        hosts = kwargs.get('hosts', '')
1125
        if hosts:
1126
            cmd.add_element('hosts', hosts)
1127
1128
        port = kwargs.get('port', '')
1129
        if port:
1130
            cmd.add_element('port', port)
1131
1132
        result_id = kwargs.get('result_id', '')
1133
        if result_id:
1134
            cmd.add_element('result', attrs={'id': result_id})
1135
1136
        severity = kwargs.get('severity', '')
1137
        if severity:
1138
            cmd.add_element('severity', severity)
1139
1140
        new_severity = kwargs.get('new_severity', '')
1141
        if new_severity:
1142
            cmd.add_element('new_severity', new_severity)
1143
1144
        task_id = kwargs.get('task_id', '')
1145
        if task_id:
1146
            cmd.add_element('task', attrs={'id': task_id})
1147
1148
        threat = kwargs.get('threat', '')
1149
        if threat:
1150
            cmd.add_element('threat', threat)
1151
1152
        new_threat = kwargs.get('new_threat', '')
1153
        if new_threat:
1154
            cmd.add_element('new_threat', new_threat)
1155
1156
        return cmd.to_string()
1157
1158
    def modify_permission_command(self, permission_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1159
        """Generates xml string for modify permission on gvmd."""
1160
        if not permission_id:
1161
            raise ValueError('modify_permission requires '
1162
                             'a permission_id element')
1163
1164
        cmd = XmlCommand('modify_permission')
1165
        cmd.set_attribute('permission_id', permission_id)
1166
1167
        comment = kwargs.get('comment', '')
1168
        if comment:
1169
            cmd.add_element('comment', comment)
1170
1171
        name = kwargs.get('name', '')
1172
        if name:
1173
            cmd.add_element('name', name)
1174
1175
        resource = kwargs.get('resource', '')
1176
        if resource:
1177
            resource_id = resource['id']
1178
            resource_type = resource['type']
1179
            _xmlresource = cmd.add_element('resource',
1180
                                           attrs={'id': resource_id})
1181
            _xmlresource.add_element('type', resource_type)
1182
1183
        subject = kwargs.get('subject', '')
1184
        if subject:
1185
            subject_id = subject['id']
1186
            subject_type = subject['type']
1187
            _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id})
1188
            _xmlsubject.add_element('type', subject_type)
1189
1190
        return cmd.to_string()
1191
1192
    def modify_port_list_command(self, port_list_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1193
        """Generates xml string for modify port list on gvmd."""
1194
        if not port_list_id:
1195
            raise ValueError('modify_port_list requires '
1196
                             'a port_list_id attribute')
1197
        cmd = XmlCommand('modify_port_list')
1198
        cmd.set_attribute('port_list_id', port_list_id)
1199
1200
        comment = kwargs.get('comment', '')
1201
        if comment:
1202
            cmd.add_element('comment', comment)
1203
1204
        name = kwargs.get('name', '')
1205
        if name:
1206
            cmd.add_element('name', name)
1207
1208
        return cmd.to_string()
1209
1210
    def modify_report_command(self, report_id, comment):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1211
        """Generates xml string for modify report on gvmd."""
1212
        cmd = XmlCommand('modify_report')
1213
        cmd.set_attribute('report_id', report_id)
1214
        cmd.add_element('comment', comment)
1215
        return cmd.to_string()
1216
1217
    def modify_report_format_command(self, report_format_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1218
        """Generates xml string for modify report format on gvmd."""
1219
        if len(kwargs) < 1:
1220
            raise Exception('modify_report_format: Missing parameter')
1221
1222
        cmd = XmlCommand('modify_report_format')
1223
        cmd.set_attribute('report_format_id', report_format_id)
1224
1225
        active = kwargs.get('active', '')
1226
        if active:
1227
            cmd.add_element('active', active)
1228
1229
        name = kwargs.get('name', '')
1230
        if name:
1231
            cmd.add_element('name', name)
1232
1233
        summary = kwargs.get('summary', '')
1234
        if summary:
1235
            cmd.add_element('summary', summary)
1236
1237
        param = kwargs.get('param', '')
1238
        if param:
1239
            p_name = param[0]
1240
            p_value = param[1]
1241
            _xmlparam = cmd.add_element('param')
1242
            _xmlparam.add_element('name', p_name)
1243
            _xmlparam.add_element('value', p_value)
1244
1245
        return cmd.to_string()
1246
1247 View Code Duplication
    def modify_role_command(self, role_id, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1248
        """Generates xml string for modify role on gvmd."""
1249
        if not role_id:
1250
            raise ValueError('modify_role requires a role_id element')
1251
1252
        cmd = XmlCommand('modify_role')
1253
        cmd.set_attribute('role_id', role_id)
1254
1255
        comment = kwargs.get('comment', '')
1256
        if comment:
1257
            cmd.add_element('comment', comment)
1258
1259
        name = kwargs.get('name', '')
1260
        if name:
1261
            cmd.add_element('name', name)
1262
1263
        users = kwargs.get('users', '')
1264
        if users:
1265
            cmd.add_element('users', users)
1266
1267
        return cmd.to_string()
1268
1269
    def modify_scanner_command(self, scanner_id, host, port, scanner_type,
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1270
                               kwargs):
1271
        """Generates xml string for modify scanner on gvmd."""
1272
        if not scanner_id:
1273
            raise ValueError('modify_scanner requires a scanner_id element')
1274
        if not host:
1275
            raise ValueError('modify_scanner requires a host element')
1276
        if not port:
1277
            raise ValueError('modify_scanner requires a port element')
1278
        if not scanner_type:
1279
            raise ValueError('modify_scanner requires a type element')
1280
1281
        cmd = XmlCommand('modify_scanner')
1282
        cmd.set_attribute('scanner_id', scanner_id)
1283
        cmd.add_element('host', host)
1284
        cmd.add_element('port', port)
1285
        cmd.add_element('type', scanner_type)
1286
1287
        comment = kwargs.get('comment', '')
1288
        if comment:
1289
            cmd.add_element('comment', comment)
1290
1291
        name = kwargs.get('name', '')
1292
        if name:
1293
            cmd.add_element('name', name)
1294
1295
        ca_pub = kwargs.get('ca_pub', '')
1296
        if ca_pub:
1297
            cmd.add_element('ca_pub', ca_pub)
1298
1299
        credential_id = kwargs.get('credential_id', '')
1300
        if credential_id:
1301
            cmd.add_element('credential', attrs={'id': str(credential_id)})
1302
1303
        return cmd.to_string()
1304
1305 View Code Duplication
    def modify_schedule_command(self, schedule_id, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (19/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1306
        """Generates xml string for modify schedule on gvmd."""
1307
        if not schedule_id:
1308
            raise ValueError('modify_schedule requires a schedule_id element')
1309
1310
        cmd = XmlCommand('modify_schedule')
1311
        cmd.set_attribute('schedule_id', schedule_id)
1312
        comment = kwargs.get('comment', '')
1313
        if comment:
1314
            cmd.add_element('comment', comment)
1315
1316
        name = kwargs.get('name', '')
1317
        if name:
1318
            cmd.add_element('name', name)
1319
1320
        first_time = kwargs.get('first_time', '')
1321
        if first_time:
1322
            first_time_minute = first_time['minute']
1323
            first_time_hour = first_time['hour']
1324
            first_time_day_of_month = first_time['day_of_month']
1325
            first_time_month = first_time['month']
1326
            first_time_year = first_time['year']
1327
1328
            _xmlftime = cmd.add_element('first_time')
1329
            _xmlftime.add_element('minute', str(first_time_minute))
1330
            _xmlftime.add_element('hour', str(first_time_hour))
1331
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
1332
            _xmlftime.add_element('month', str(first_time_month))
1333
            _xmlftime.add_element('year', str(first_time_year))
1334
1335
        duration = kwargs.get('duration', '')
1336
        if len(duration) > 1:
1337
            _xmlduration = cmd.add_element('duration', str(duration[0]))
1338
            _xmlduration.add_element('unit', str(duration[1]))
1339
1340
        period = kwargs.get('period', '')
1341
        if len(period) > 1:
1342
            _xmlperiod = cmd.add_element('period', str(period[0]))
1343
            _xmlperiod.add_element('unit', str(period[1]))
1344
1345
        timezone = kwargs.get('timezone', '')
1346
        if timezone:
1347
            cmd.add_element('timezone', str(timezone))
1348
1349
        return cmd.to_string()
1350
1351
    def modify_setting_command(self, setting_id, name, value):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1352
        """Generates xml string for modify setting format on gvmd."""
1353
        cmd = XmlCommand('modify_setting')
1354
        cmd.set_attribute('setting_id', setting_id)
1355
        cmd.add_element('name', name)
1356
        cmd.add_element('value', value)
1357
1358
        return cmd.to_string()
1359
1360
    def modify_tag_command(self, tag_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1361
        """Generates xml string for modify tag on gvmd."""
1362
        if not tag_id:
1363
            raise ValueError('modify_tag requires a tag_id element')
1364
1365
        cmd = XmlCommand('modify_tag')
1366
        cmd.set_attribute('tag_id', str(tag_id))
1367
1368
        comment = kwargs.get('comment', '')
1369
        if comment:
1370
            cmd.add_element('comment', comment)
1371
1372
        name = kwargs.get('name', '')
1373
        if name:
1374
            cmd.add_element('name', name)
1375
1376
        value = kwargs.get('value', '')
1377
        if value:
1378
            cmd.add_element('value', value)
1379
1380
        active = kwargs.get('active', '')
1381
        if active:
1382
            cmd.add_element('active', value)
1383
1384
        resource = kwargs.get('resource', '')
1385
        if resource:
1386
            resource_id = resource['id']
1387
            resource_type = resource['type']
1388
            _xmlresource = cmd.add_element('resource',
1389
                                           attrs={'resource_id': resource_id})
1390
            _xmlresource.add_element('type', resource_type)
1391
1392
        return cmd.to_string()
1393
1394
    def modify_target_command(self, target_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1395
        """Generates xml string for modify target on gvmd."""
1396
        if not target_id:
1397
            raise ValueError('modify_target requires a target_id element')
1398
1399
        cmd = XmlCommand('modify_target')
1400
        cmd.set_attribute('target_id', target_id)
1401
1402
        comment = kwargs.get('comment', '')
1403
        if comment:
1404
            cmd.add_element('comment', comment)
1405
1406
        name = kwargs.get('name', '')
1407
        if name:
1408
            cmd.add_element('name', name)
1409
1410
        hosts = kwargs.get('hosts', '')
1411
        if hosts:
1412
            cmd.add_element('hosts', hosts)
1413
1414
        copy = kwargs.get('copy', '')
1415
        if copy:
1416
            cmd.add_element('copy', copy)
1417
1418
        exclude_hosts = kwargs.get('exclude_hosts', '')
1419
        if exclude_hosts:
1420
            cmd.add_element('exclude_hosts', exclude_hosts)
1421
1422
        alive_tests = kwargs.get('alive_tests', '')
1423
        if alive_tests:
1424
            cmd.add_element('alive_tests', alive_tests)
1425
1426
        reverse_lookup_only = kwargs.get('reverse_lookup_only', '')
1427
        if reverse_lookup_only:
1428
            cmd.add_element('reverse_lookup_only', reverse_lookup_only)
1429
1430
        reverse_lookup_unify = kwargs.get('reverse_lookup_unify', '')
1431
        if reverse_lookup_unify:
1432
            cmd.add_element('reverse_lookup_unify', reverse_lookup_unify)
1433
1434
        port_range = kwargs.get('port_range', '')
1435
        if port_range:
1436
            cmd.add_element('port_range', port_range)
1437
1438
        port_list = kwargs.get('port_list', '')
1439
        if port_list:
1440
            cmd.add_element('port_list', attrs={'id': str(port_list)})
1441
1442
        return cmd.to_string()
1443
1444
    def modify_task_command(self, task_id, kwargs):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1445
        """Generates xml string for modify task on gvmd."""
1446
        if not task_id:
1447
            raise ValueError('modify_task requires a task_id element')
1448
1449
        cmd = XmlCommand('modify_task')
1450
        cmd.set_attribute('task_id', task_id)
1451
1452
        name = kwargs.get('name', '')
1453
        if name:
1454
            cmd.add_element('name', name)
1455
1456
        comment = kwargs.get('comment', '')
1457
        if comment:
1458
            cmd.add_element('comment', comment)
1459
1460
        target_id = kwargs.get('target_id', '')
1461
        if target_id:
1462
            cmd.add_element('target', attrs={'id': target_id})
1463
1464
        scanner = kwargs.get('scanner', '')
1465
        if scanner:
1466
            cmd.add_element('scanner', attrs={'id': scanner})
1467
1468
        schedule_periods = kwargs.get('schedule_periods', '')
1469
        if schedule_periods:
1470
            cmd.add_element('schedule_periods', str(schedule_periods))
1471
1472
        schedule = kwargs.get('schedule', '')
1473
        if schedule:
1474
            cmd.add_element('schedule', attrs={'id': str(schedule)})
1475
1476
        alert = kwargs.get('alert', '')
1477
        if alert:
1478
            cmd.add_element('alert', attrs={'id': str(alert)})
1479
1480
        observers = kwargs.get('observers', '')
1481
        if observers:
1482
            cmd.add_element('observers', str(observers))
1483
1484
        preferences = kwargs.get('preferences', '')
1485
        if preferences:
1486
            _xmlprefs = cmd.add_element('preferences')
1487
            for n in range(len(preferences["scanner_name"])):
0 ignored issues
show
Coding Style Naming introduced by
The name n does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1488
                preferences_scanner_name = preferences["scanner_name"][n]
1489
                preferences_value = preferences["value"][n]
1490
                _xmlpref = _xmlprefs.add_element('preference')
1491
                _xmlpref.add_element('scanner_name', preferences_scanner_name)
1492
                _xmlpref.add_element('value', preferences_value)
1493
1494
        file = kwargs.get('file', '')
1495
        if file:
1496
            file_name = file['name']
1497
            file_action = file['action']
1498
            if file_action != "update" and file_action != "remove":
1499
                raise ValueError('action can only be "update" or "remove"!')
1500
            cmd.add_element('file', attrs={'name': file_name,
1501
                                           'action': file_action})
1502
1503
        return cmd.to_string()
1504
1505
    def modify_user_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1506
        """Generates xml string for modify user on gvmd."""
1507
        user_id = kwargs.get('user_id', '')
1508
        name = kwargs.get('name', '')
1509
1510
        if not user_id and not name:
1511
            raise ValueError('modify_user requires '
1512
                             'either a user_id or a name element')
1513
1514
        cmd = XmlCommand('modify_user')
1515
        cmd.set_attribute('user_id', str(user_id))
1516
1517
        new_name = kwargs.get('new_name', '')
1518
        if new_name:
1519
            cmd.add_element('new_name', new_name)
1520
1521
        password = kwargs.get('password', '')
1522
        if password:
1523
            cmd.add_element('password', password)
1524
1525
        role_ids = kwargs.get('role_ids', '')
1526
        if len(role_ids) > 0:
0 ignored issues
show
Unused Code introduced by
Do not use len(SEQUENCE) as condition value
Loading history...
1527
            for role in role_ids:
1528
                cmd.add_element('role', attrs={'id': str(role)})
1529
1530
        hosts = kwargs.get('hosts', '')
1531
        hosts_allow = kwargs.get('hosts_allow', '')
1532
        if hosts or hosts_allow:
1533
            cmd.add_element('hosts', hosts, attrs={'allow': str(hosts_allow)})
1534
1535
        ifaces = kwargs.get('ifaces', '')
1536
        ifaces_allow = kwargs.get('ifaces_allow', '')
1537
        if ifaces or ifaces_allow:
1538
            cmd.add_element('ifaces', ifaces,
1539
                            attrs={'allow': str(ifaces_allow)})
1540
1541
        sources = kwargs.get('sources', '')
1542
        if sources:
1543
            cmd.add_element('sources', sources)
1544
1545
        return cmd.to_string()
1546
1547
    def delete_agent_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1548
        """Generates xml string for delete agent on gvmd"""
1549
        cmd = XmlCommand('delete_agent')
1550
        for key, value in kwargs.items():
1551
            cmd.set_attribute(key, value)
1552
1553
        return cmd.to_string()
1554
1555
    def delete_alert_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1556
        """Generates xml string for delete alert on gvmd"""
1557
        cmd = XmlCommand('delete_alert')
1558
        for key, value in kwargs.items():
1559
            cmd.set_attribute(key, value)
1560
1561
        return cmd.to_string()
1562
1563
    def delete_asset_command(self, asset_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1564
        """Generates xml string for delete asset on gvmd"""
1565
        cmd = XmlCommand('delete_asset')
1566
        cmd.set_attribute('asset_id', asset_id)
1567
        cmd.set_attribute('ultimate', ultimate)
1568
1569
        return cmd.to_string()
1570
1571
    def delete_config_command(self, config_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1572
        """Generates xml string for delete config on gvmd"""
1573
        cmd = XmlCommand('delete_config')
1574
        cmd.set_attribute('config_id', config_id)
1575
        cmd.set_attribute('ultimate', ultimate)
1576
1577
        return cmd.to_string()
1578
1579
    def delete_credential_command(self, credential_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1580
        """Generates xml string for delete credential on gvmd"""
1581
        cmd = XmlCommand('delete_credential')
1582
        cmd.set_attribute('credential_id', credential_id)
1583
        cmd.set_attribute('ultimate', ultimate)
1584
        return cmd.to_string()
1585
1586
    def delete_filter_command(self, filter_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1587
        """Generates xml string for delete filter on gvmd"""
1588
        cmd = XmlCommand('delete_filter')
1589
        cmd.set_attribute('filter_id', filter_id)
1590
        cmd.set_attribute('ultimate', ultimate)
1591
1592
        return cmd.to_string()
1593
1594
    def delete_group_command(self, group_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1595
        """Generates xml string for delete group on gvmd"""
1596
        cmd = XmlCommand('delete_group')
1597
        cmd.set_attribute('group_id', group_id)
1598
        cmd.set_attribute('ultimate', ultimate)
1599
1600
        return cmd.to_string()
1601
1602
    def delete_note_command(self, note_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1603
        """Generates xml string for delete note on gvmd"""
1604
        cmd = XmlCommand('delete_note')
1605
        cmd.set_attribute('note_id', note_id)
1606
        cmd.set_attribute('ultimate', ultimate)
1607
1608
        return cmd.to_string()
1609
1610
    def delete_override_command(self, override_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1611
        """Generates xml string for delete override on gvmd"""
1612
        cmd = XmlCommand('delete_override')
1613
        cmd.set_attribute('override_id', override_id)
1614
        cmd.set_attribute('ultimate', ultimate)
1615
1616
        return cmd.to_string()
1617
1618
    def delete_permission_command(self, permission_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1619
        """Generates xml string for delete permission on gvmd"""
1620
        cmd = XmlCommand('delete_permission')
1621
        cmd.set_attribute('permission_id', permission_id)
1622
        cmd.set_attribute('ultimate', ultimate)
1623
1624
        return cmd.to_string()
1625
1626
    def delete_port_list_command(self, port_list_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1627
        """Generates xml string for delete port on gvmd"""
1628
        cmd = XmlCommand('delete_port_list')
1629
        cmd.set_attribute('port_list_id', port_list_id)
1630
        cmd.set_attribute('ultimate', ultimate)
1631
1632
        return cmd.to_string()
1633
1634
    def delete_port_range_command(self, port_range_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1635
        """Generates xml string for delete port on gvmd"""
1636
        cmd = XmlCommand('delete_port_range')
1637
        cmd.set_attribute('port_range_id', port_range_id)
1638
1639
        return cmd.to_string()
1640
1641
    def delete_report_command(self, report_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1642
        """Generates xml string for delete report on gvmd"""
1643
        cmd = XmlCommand('delete_report')
1644
        cmd.set_attribute('report_id', report_id)
1645
1646
        return cmd.to_string()
1647
1648
    def delete_report_format_command(self, report_format_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1649
        """Generates xml string for delete report on gvmd"""
1650
        cmd = XmlCommand('delete_report_format')
1651
        cmd.set_attribute('report_format_id', report_format_id)
1652
        cmd.set_attribute('ultimate', ultimate)
1653
1654
        return cmd.to_string()
1655
1656
    def delete_role_command(self, role_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1657
        """Generates xml string for delete role on gvmd"""
1658
        cmd = XmlCommand('delete_role')
1659
        cmd.set_attribute('role_id', role_id)
1660
        cmd.set_attribute('ultimate', ultimate)
1661
1662
        return cmd.to_string()
1663
1664
    def delete_scanner_command(self, scanner_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1665
        """Generates xml string for delete scanner on gvmd"""
1666
        cmd = XmlCommand('delete_scanner')
1667
        cmd.set_attribute('scanner_id', scanner_id)
1668
        cmd.set_attribute('ultimate', ultimate)
1669
1670
        return cmd.to_string()
1671
1672
    def delete_schedule_command(self, schedule_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1673
        """Generates xml string for delete schedule on gvmd"""
1674
        # if self.ask_yes_or_no('Are you sure to delete this schedule? '):
1675
        cmd = XmlCommand('delete_schedule')
1676
        cmd.set_attribute('schedule_id', schedule_id)
1677
        cmd.set_attribute('ultimate', ultimate)
1678
1679
        return cmd.to_string()
1680
1681
    def delete_tag_command(self, tag_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1682
        """Generates xml string for delete tag on gvmd"""
1683
        cmd = XmlCommand('delete_tag')
1684
        cmd.set_attribute('tag_id', tag_id)
1685
        cmd.set_attribute('ultimate', ultimate)
1686
1687
        return cmd.to_string()
1688
1689
    def delete_target_command(self, target_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1690
        """Generates xml string for delete target on gvmd"""
1691
        cmd = XmlCommand('delete_target')
1692
        cmd.set_attribute('target_id', target_id)
1693
        cmd.set_attribute('ultimate', ultimate)
1694
1695
        return cmd.to_string()
1696
1697
    def delete_task_command(self, task_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1698
        """Generates xml string for delete task on gvmd"""
1699
        cmd = XmlCommand('delete_task')
1700
        cmd.set_attribute('task_id', task_id)
1701
        cmd.set_attribute('ultimate', ultimate)
1702
1703
        return cmd.to_string()
1704
1705
    def delete_user_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1706
        """Generates xml string for delete user on gvmd"""
1707
        cmd = XmlCommand('delete_user')
1708
1709
        user_id = kwargs.get('user_id', '')
1710
        if user_id:
1711
            cmd.set_attribute('user_id', user_id)
1712
1713
        name = kwargs.get('name', '')
1714
        if name:
1715
            cmd.set_attribute('name', name)
1716
1717
        inheritor_id = kwargs.get('inheritor_id', '')
1718
        if inheritor_id:
1719
            cmd.set_attribute('inheritor_id', inheritor_id)
1720
1721
        inheritor_name = kwargs.get('inheritor_name', '')
1722
        if inheritor_name:
1723
            cmd.set_attribute('inheritor_name', inheritor_name)
1724
1725
        return cmd.to_string()
1726
1727
    def describe_auth_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1728
        """Generates xml string for describe auth on gvmd"""
1729
        cmd = XmlCommand('describe_auth')
1730
        return cmd.to_string()
1731
1732
    def empty_trashcan_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1733
        """Generates xml string for empty trashcan on gvmd"""
1734
        cmd = XmlCommand('empty_trashcan')
1735
        return cmd.to_string()
1736
1737
    def get_agents_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1738
        """Generates xml string for get agents on gvmd."""
1739
        cmd = XmlCommand('get_agents')
1740
        cmd.set_attributes(kwargs)
1741
        return cmd.to_string()
1742
1743
    def get_aggregates_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1744
        """Generates xml string for get aggregates on gvmd."""
1745
        cmd = XmlCommand('get_aggregates')
1746
        cmd.set_attributes(kwargs)
1747
        return cmd.to_string()
1748
1749
    def get_alerts_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1750
        """Generates xml string for get alerts on gvmd."""
1751
        cmd = XmlCommand('get_alerts')
1752
        cmd.set_attributes(kwargs)
1753
        return cmd.to_string()
1754
1755
    def get_assets_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1756
        """Generates xml string for get assets on gvmd."""
1757
        cmd = XmlCommand('get_assets')
1758
        cmd.set_attributes(kwargs)
1759
        return cmd.to_string()
1760
1761
    def get_credentials_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1762
        """Generates xml string for get credentials on gvmd."""
1763
        cmd = XmlCommand('get_credentials')
1764
        cmd.set_attributes(kwargs)
1765
        return cmd.to_string()
1766
1767
    def get_configs_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1768
        """Generates xml string for get configs on gvmd."""
1769
        cmd = XmlCommand('get_configs')
1770
        cmd.set_attributes(kwargs)
1771
        return cmd.to_string()
1772
1773
    def get_feeds_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1774
        """Generates xml string for get feeds on gvmd."""
1775
        cmd = XmlCommand('get_feeds')
1776
        cmd.set_attributes(kwargs)
1777
        return cmd.to_string()
1778
1779
    def get_filters_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1780
        """Generates xml string for get filters on gvmd."""
1781
        cmd = XmlCommand('get_filters')
1782
        cmd.set_attributes(kwargs)
1783
        return cmd.to_string()
1784
1785
    def get_groups_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1786
        """Generates xml string for get groups on gvmd."""
1787
        cmd = XmlCommand('get_groups')
1788
        cmd.set_attributes(kwargs)
1789
        return cmd.to_string()
1790
1791
    def get_info_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1792
        """Generates xml string for get info on gvmd."""
1793
        cmd = XmlCommand('get_info')
1794
        cmd.set_attributes(kwargs)
1795
        return cmd.to_string()
1796
1797
    def get_notes_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1798
        """Generates xml string for get notes on gvmd."""
1799
        cmd = XmlCommand('get_notes')
1800
        cmd.set_attributes(kwargs)
1801
        return cmd.to_string()
1802
1803
    def get_nvts_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1804
        """Generates xml string for get nvts on gvmd."""
1805
        cmd = XmlCommand('get_nvts')
1806
        cmd.set_attributes(kwargs)
1807
        return cmd.to_string()
1808
1809
    def get_nvt_families_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1810
        """Generates xml string for get nvt on gvmd."""
1811
        cmd = XmlCommand('get_nvt_families')
1812
        cmd.set_attributes(kwargs)
1813
        return cmd.to_string()
1814
1815
    def get_overrides_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1816
        """Generates xml string for get overrides on gvmd."""
1817
        cmd = XmlCommand('get_overrides')
1818
        cmd.set_attributes(kwargs)
1819
        return cmd.to_string()
1820
1821
    def get_permissions_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1822
        """Generates xml string for get permissions on gvmd."""
1823
        cmd = XmlCommand('get_permissions')
1824
        cmd.set_attributes(kwargs)
1825
        return cmd.to_string()
1826
1827
    def get_port_lists_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1828
        """Generates xml string for get port on gvmd."""
1829
        cmd = XmlCommand('get_port_lists')
1830
        cmd.set_attributes(kwargs)
1831
        return cmd.to_string()
1832
1833
    def get_preferences_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1834
        """Generates xml string for get preferences on gvmd."""
1835
        cmd = XmlCommand('get_preferences')
1836
        cmd.set_attributes(kwargs)
1837
        return cmd.to_string()
1838
1839
    def get_reports_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1840
        """Generates xml string for get reports on gvmd."""
1841
        cmd = XmlCommand('get_reports')
1842
        cmd.set_attributes(kwargs)
1843
        return cmd.to_string()
1844
1845
    def get_report_formats_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1846
        """Generates xml string for get report on gvmd."""
1847
        cmd = XmlCommand('get_report_formats')
1848
        cmd.set_attributes(kwargs)
1849
        return cmd.to_string()
1850
1851
    def get_results_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1852
        """Generates xml string for get results on gvmd."""
1853
        cmd = XmlCommand('get_results')
1854
        cmd.set_attributes(kwargs)
1855
        return cmd.to_string()
1856
1857
    def get_roles_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1858
        """Generates xml string for get roles on gvmd."""
1859
        cmd = XmlCommand('get_roles')
1860
        cmd.set_attributes(kwargs)
1861
        return cmd.to_string()
1862
1863
    def get_scanners_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1864
        """Generates xml string for get scanners on gvmd."""
1865
        cmd = XmlCommand('get_scanners')
1866
        cmd.set_attributes(kwargs)
1867
        return cmd.to_string()
1868
1869
    def get_schedules_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1870
        """Generates xml string for get schedules on gvmd."""
1871
        cmd = XmlCommand('get_schedules')
1872
        cmd.set_attributes(kwargs)
1873
        return cmd.to_string()
1874
1875
    def get_settings_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1876
        """Generates xml string for get settings on gvmd."""
1877
        cmd = XmlCommand('get_settings')
1878
        cmd.set_attributes(kwargs)
1879
        return cmd.to_string()
1880
1881
    def get_system_reports_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1882
        """Generates xml string for get system on gvmd."""
1883
        cmd = XmlCommand('get_system')
1884
        cmd.set_attributes(kwargs)
1885
        return cmd.to_string()
1886
1887
    def get_tags_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1888
        """Generates xml string for get tags on gvmd."""
1889
        cmd = XmlCommand('get_tags')
1890
        cmd.set_attributes(kwargs)
1891
        return cmd.to_string()
1892
1893
    def get_targets_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1894
        """Generates xml string for get targets on gvmd."""
1895
        cmd = XmlCommand('get_targets')
1896
        cmd.set_attributes(kwargs)
1897
        return cmd.to_string()
1898
1899
    def get_tasks_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1900
        """Generates xml string for get tasks on gvmd."""
1901
        cmd = XmlCommand('get_tasks')
1902
        cmd.set_attributes(kwargs)
1903
        return cmd.to_string()
1904
1905
    def get_users_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1906
        """Generates xml string for get users on gvmd."""
1907
        cmd = XmlCommand('get_users')
1908
        cmd.set_attributes(kwargs)
1909
        return cmd.to_string()
1910
1911
    def get_version_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1912
        """Generates xml string for get version on gvmd."""
1913
        cmd = XmlCommand('get_version')
1914
        return cmd.to_string()
1915
1916
    def help_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1917
        """Generates xml string for help on gvmd."""
1918
        cmd = XmlCommand('help')
1919
        cmd.set_attributes(kwargs)
1920
        return cmd.to_string()
1921
1922
    def move_task_command(self, task_id, slave_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1923
        """Generates xml string for move task on gvmd."""
1924
        cmd = XmlCommand('move_task')
1925
        cmd.set_attribute('task_id', task_id)
1926
        cmd.set_attribute('slave_id', slave_id)
1927
        return cmd.to_string()
1928
1929
    def restore_command(self, entity_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1930
        """Generates xml string for restore on gvmd."""
1931
        cmd = XmlCommand('restore')
1932
        cmd.set_attribute('id', entity_id)
1933
        return cmd.to_string()
1934
1935
    def resume_task_command(self, task_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1936
        """Generates xml string for resume task on gvmd."""
1937
        cmd = XmlCommand('resume_task')
1938
        cmd.set_attribute('task_id', task_id)
1939
        return cmd.to_string()
1940
1941
    def start_task_command(self, task_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1942
        """Generates xml string for start task on gvmd."""
1943
        cmd = XmlCommand('start_task')
1944
        cmd.set_attribute('task_id', task_id)
1945
        return cmd.to_string()
1946
1947
    def stop_task_command(self, task_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1948
        """Generates xml string for stop task on gvmd."""
1949
        cmd = XmlCommand('stop_task')
1950
        cmd.set_attribute('task_id', task_id)
1951
        return cmd.to_string()
1952
1953
    def sync_cert_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1954
        """Generates xml string for sync cert on gvmd."""
1955
        cmd = XmlCommand('sync_cert')
1956
        return cmd.to_string()
1957
1958
    def sync_config_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1959
        """Generates xml string for sync config on gvmd."""
1960
        cmd = XmlCommand('sync_config')
1961
        return cmd.to_string()
1962
1963
    def sync_feed_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1964
        """Generates xml string for sync feed on gvmd."""
1965
        cmd = XmlCommand('sync_feed')
1966
        return cmd.to_string()
1967
1968
    def sync_scap_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1969
        """Generates xml string for sync scap on gvmd."""
1970
        cmd = XmlCommand('sync_scap')
1971
        return cmd.to_string()
1972
1973
    def test_alert_command(self, alert_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1974
        """Generates xml string for test alert on gvmd."""
1975
        cmd = XmlCommand('test_alert')
1976
        cmd.set_attribute('alert_id', alert_id)
1977
        return cmd.to_string()
1978
1979
    def verify_agent_command(self, agent_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1980
        """Generates xml string for verify agent on gvmd."""
1981
        cmd = XmlCommand('verify_agent')
1982
        cmd.set_attribute('agent_id', agent_id)
1983
        return cmd.to_string()
1984
1985
    def verify_report_format_command(self, report_format_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1986
        """Generates xml string for verify report format on gvmd."""
1987
        cmd = XmlCommand('verify_report_format')
1988
        cmd.set_attribute('report_format_id', report_format_id)
1989
        return cmd.to_string()
1990
1991
    def verify_scanner_command(self, scanner_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1992
        """Generates xml string for verify scanner on gvmd."""
1993
        cmd = XmlCommand('verify_scanner')
1994
        cmd.set_attribute('scanner_id', scanner_id)
1995
        return cmd.to_string()
1996