Code Duplication    Length = 87-87 lines in 2 locations

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):

gvm/protocols/gmpv208/gmpv208.py 1 location

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