Code Duplication    Length = 87-87 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 113-199 (lines=87) @@
110
    return isinstance(value, (list, tuple))
111
112
113
def _check_event(
114
    event: AlertEvent, condition: AlertCondition, method: AlertMethod
115
):
116
    if event == AlertEvent.TASK_RUN_STATUS_CHANGED:
117
        if not condition:
118
            raise RequiredArgument(
119
                "condition is required for event {}".format(event.name)
120
            )
121
122
        if not method:
123
            raise RequiredArgument(
124
                "method is required for event {}".format(event.name)
125
            )
126
127
        if condition not in (
128
            AlertCondition.ALWAYS,
129
            AlertCondition.FILTER_COUNT_CHANGED,
130
            AlertCondition.FILTER_COUNT_AT_LEAST,
131
            AlertCondition.SEVERITY_AT_LEAST,
132
            AlertCondition.SEVERITY_CHANGED,
133
        ):
134
            raise InvalidArgument(
135
                "Invalid condition {} for event {}".format(
136
                    condition.name, event.name
137
                )
138
            )
139
    elif event in (
140
        AlertEvent.NEW_SECINFO_ARRIVED,
141
        AlertEvent.UPDATED_SECINFO_ARRIVED,
142
    ):
143
        if not condition:
144
            raise RequiredArgument(
145
                "condition is required for event {}".format(event.name)
146
            )
147
148
        if not method:
149
            raise RequiredArgument(
150
                "method is required for event {}".format(event.name)
151
            )
152
153
        if condition != AlertCondition.ALWAYS:
154
            raise InvalidArgument(
155
                "Invalid condition {} for event {}".format(
156
                    condition.name, event.name
157
                )
158
            )
159
        if method not in (
160
            AlertMethod.SCP,
161
            AlertMethod.SEND,
162
            AlertMethod.SMB,
163
            AlertMethod.SNMP,
164
            AlertMethod.SYSLOG,
165
            AlertMethod.EMAIL,
166
        ):
167
            raise InvalidArgument(
168
                "Invalid method {} for event {}".format(method.name, event.name)
169
            )
170
    elif event in (
171
        AlertEvent.TICKET_RECEIVED,
172
        AlertEvent.OWNED_TICKET_CHANGED,
173
        AlertEvent.ASSIGNED_TICKET_CHANGED,
174
    ):
175
        if not condition:
176
            raise RequiredArgument(
177
                "condition is required for event {}".format(event.name)
178
            )
179
180
        if not method:
181
            raise RequiredArgument(
182
                "method is required for event {}".format(event.name)
183
            )
184
        if condition != AlertCondition.ALWAYS:
185
            raise InvalidArgument(
186
                "Invalid condition {} for event {}".format(
187
                    condition.name, event.name
188
                )
189
            )
190
        if method not in (
191
            AlertMethod.EMAIL,
192
            AlertMethod.START_TASK,
193
            AlertMethod.SYSLOG,
194
        ):
195
            raise InvalidArgument(
196
                "Invalid method {} for event {}".format(method.name, event.name)
197
            )
198
    elif event is not None:
199
        raise InvalidArgument('Invalid event "{}"'.format(event.name))
200
201
202
class GmpV208Mixin(GvmProtocol):

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 54-140 (lines=87) @@
51
_EMPTY_POLICY_ID = '085569ce-73ed-11df-83c3-002264764cea'
52
53
54
def _check_event(
55
    event: AlertEvent, condition: AlertCondition, method: AlertMethod
56
):
57
    if event == AlertEvent.TASK_RUN_STATUS_CHANGED:
58
        if not condition:
59
            raise RequiredArgument(
60
                "condition is required for event {}".format(event.name)
61
            )
62
63
        if not method:
64
            raise RequiredArgument(
65
                "method is required for event {}".format(event.name)
66
            )
67
68
        if condition not in (
69
            AlertCondition.ALWAYS,
70
            AlertCondition.FILTER_COUNT_CHANGED,
71
            AlertCondition.FILTER_COUNT_AT_LEAST,
72
            AlertCondition.SEVERITY_AT_LEAST,
73
            AlertCondition.SEVERITY_CHANGED,
74
        ):
75
            raise InvalidArgument(
76
                "Invalid condition {} for event {}".format(
77
                    condition.name, event.name
78
                )
79
            )
80
    elif event in (
81
        AlertEvent.NEW_SECINFO_ARRIVED,
82
        AlertEvent.UPDATED_SECINFO_ARRIVED,
83
    ):
84
        if not condition:
85
            raise RequiredArgument(
86
                "condition is required for event {}".format(event.name)
87
            )
88
89
        if not method:
90
            raise RequiredArgument(
91
                "method is required for event {}".format(event.name)
92
            )
93
94
        if condition != AlertCondition.ALWAYS:
95
            raise InvalidArgument(
96
                "Invalid condition {} for event {}".format(
97
                    condition.name, event.name
98
                )
99
            )
100
        if method not in (
101
            AlertMethod.SCP,
102
            AlertMethod.SEND,
103
            AlertMethod.SMB,
104
            AlertMethod.SNMP,
105
            AlertMethod.SYSLOG,
106
            AlertMethod.EMAIL,
107
        ):
108
            raise InvalidArgument(
109
                "Invalid method {} for event {}".format(method.name, event.name)
110
            )
111
    elif event in (
112
        AlertEvent.TICKET_RECEIVED,
113
        AlertEvent.OWNED_TICKET_CHANGED,
114
        AlertEvent.ASSIGNED_TICKET_CHANGED,
115
    ):
116
        if not condition:
117
            raise RequiredArgument(
118
                "condition is required for event {}".format(event.name)
119
            )
120
121
        if not method:
122
            raise RequiredArgument(
123
                "method is required for event {}".format(event.name)
124
            )
125
        if condition != AlertCondition.ALWAYS:
126
            raise InvalidArgument(
127
                "Invalid condition {} for event {}".format(
128
                    condition.name, event.name
129
                )
130
            )
131
        if method not in (
132
            AlertMethod.EMAIL,
133
            AlertMethod.START_TASK,
134
            AlertMethod.SYSLOG,
135
        ):
136
            raise InvalidArgument(
137
                "Invalid method {} for event {}".format(method.name, event.name)
138
            )
139
    elif event is not None:
140
        raise InvalidArgument('Invalid event "{}"'.format(event.name))
141
142
143
class GmpV9Mixin(GvmProtocol):