aboutsummaryrefslogtreecommitdiffstats
path: root/keystone-moon/keystone/contrib/moon/exception.py
blob: 3108b7c274c37904e9700a5759e6ea71fe11ea8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
# This software is distributed under the terms and conditions of the 'Apache-2.0'
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.

from keystone.common import dependency
from keystone.exception import Error
from keystone.i18n import _, _LW


class MoonErrorMetaClass(type):

    def __init__(cls, name, bases, dct):
        super(MoonErrorMetaClass, cls).__init__(name, bases, dct)
        cls.hierarchy += "/"+str(name)


@dependency.requires('moonlog_api')
class MoonError(Error):
    __metaclass__ = MoonErrorMetaClass
    hierarchy = ""
    message_format = _("There is an error requesting the Moon platform.")
    code = 400
    title = 'Moon Error'
    logger = "ERROR"

    def __del__(self):
        message = "{} ({})".format(self.hierarchy, self.message_format)
        if self.logger == "ERROR":
            self.moonlog_api.error(message)
        elif self.logger == "WARNING":
            self.moonlog_api.warning(message)
        elif self.logger == "CRITICAL":
            self.moonlog_api.critical(message)
        elif self.logger == "AUTHZ":
            self.moonlog_api.authz(self.hierarchy)
            self.moonlog_api.error(message)
        else:
            self.moonlog_api.info(message)


# Exceptions for Tenant


class TenantException(MoonError):
    message_format = _("There is an error requesting this tenant.")
    code = 400
    title = 'Tenant Error'
    logger = "ERROR"


class TenantListEmpty(TenantException):
    message_format = _("The tenant list mapping is empty, you must set the mapping first.")
    code = 400
    title = 'Tenant List Empty Error'
    logger = "WARNING"


class TenantIDNotFound(TenantException):
    message_format = _("The tenant UUID was not found.")
    code = 400
    title = 'Tenant UUID Not Found Error'


class AddedTenantNameExist(TenantException):
    message_format = _("The tenant name exists already.")
    code = 400
    title = 'Added Tenant Name Exist'

# Exceptions for IntraExtension


class IntraExtensionException(MoonError):
    message_format = _("There is an error requesting this IntraExtension.")
    code = 400
    title = 'Extension Error'


class IntraExtensionUnMapped(IntraExtensionException):
    message_format = _("The Extension is not mapped to a tenant.")
    code = 400
    title = 'Extension UUID Not Found Error'
    logger = "WARNING"


class IntraExtensionNotFound(IntraExtensionException):
    message_format = _("The Extension for that tenant is unknown.")
    code = 400
    title = 'Extension UUID Not Found Error'
    logger = "WARNING"


class IntraExtensionCreationError(IntraExtensionException):
    message_format = _("The arguments for the creation of this Extension were malformed.")
    code = 400
    title = 'Intra Extension Creation Error'


# Authz exceptions


class AuthzException(MoonError):
    message_format = _("There is an error requesting this Authz IntraExtension.")
    code = 400
    title = 'Authz Exception'
    logger = "AUTHZ"


class AuthzPerimeter(AuthzException):
    code = 400
    title = 'Perimeter Exception'


class AuthzScope(AuthzException):
    code = 400
    title = 'Scope Exception'


class AuthzMetadata(AuthzException):
    code = 400
    title = 'Metadata Exception'


class AuthzAssignment(AuthzException):
    code = 400
    title = 'Assignment Exception'


class AuthzMetaRule(AuthzException):
    code = 400
    title = 'Aggregation Algorithm Exception'


class AuthzRule(AuthzException):
    code = 400
    title = 'Rule Exception'


class SubjectUnknown(AuthzPerimeter):
    message_format = _("The given subject is unknown.")
    code = 400
    title = 'Subject Unknown'
    logger = "ERROR"


class ObjectUnknown(AuthzPerimeter):
    message_format = _("The given object is unknown.")
    code = 400
    title = 'Object Unknown'
    logger = "ERROR"


class ActionUnknown(AuthzPerimeter):
    message_format = _("The given action is unknown.")
    code = 400
    title = 'Action Unknown'
    logger = "ERROR"


class SubjectCategoryUnknown(AuthzMetadata):
    message_format = _("The given subject category is unknown.")
    code = 400
    title = 'Subject Category Unknown'
    logger = "ERROR"


class ObjectCategoryUnknown(AuthzMetadata):
    message_format = _("The given object category is unknown.")
    code = 400
    title = 'Object Category Unknown'
    logger = "ERROR"


class ActionCategoryUnknown(AuthzMetadata):
    message_format = _("The given action category is unknown.")
    code = 400
    title = 'Action Category Unknown'
    logger = "ERROR"


class SubjectScopeUnknown(AuthzScope):
    message_format = _("The given subject scope is unknown.")
    code = 400
    title = 'Subject Scope Unknown'
    logger = "ERROR"


class ObjectScopeUnknown(AuthzScope):
    message_format = _("The given object scope is unknown.")
    code = 400
    title = 'Object Scope Unknown'
    logger = "ERROR"


class ActionScopeUnknown(AuthzScope):
    message_format = _("The given action scope is unknown.")
    code = 400
    title = 'Action Scope Unknown'
    logger = "ERROR"


class SubjectAssignmentOutOfScope(AuthzScope):
    message_format = _("The given subject scope value is out of scope.")
    code = 400
    title = 'Subject Assignment Out Of Scope'
    logger = "WARNING"


class ActionAssignmentOutOfScope(AuthzScope):
    message_format = _("The given action scope value is out of scope.")
    code = 400
    title = 'Action Assignment Out Of Scope'
    logger = "WARNING"


class ObjectAssignmentOutOfScope(AuthzScope):
    message_format = _("The given object scope value is out of scope.")
    code = 400
    title = 'Object Assignment Out Of Scope'
    logger = "WARNING"


class SubjectAssignmentUnknown(AuthzAssignment):
    message_format = _("The given subject assignment value is unknown.")
    code = 400
    title = 'Subject Assignment Unknown'
    logger = "ERROR"


class ObjectAssignmentUnknown(AuthzAssignment):
    message_format = _("The given object assignment value is unknown.")
    code = 400
    title = 'Object Assignment Unknown'
    logger = "ERROR"


class ActionAssignmentUnknown(AuthzAssignment):
    message_format = _("The given action assignment value is unknown.")
    code = 400
    title = 'Action Assignment Unknown'
    logger = "ERROR"


class AggregationAlgorithmNotExisting(AuthzMetadata):
    message_format = _("The given aggregation algorithm is not exsiting.")
    code = 400
    title = 'Aggregation Algorithm Not Existing'
    logger = "ERROR"


class AggregationAlgorithmOutOfScope(AuthzMetadata):
    message_format = _("The given aggregation algorithm is out of scope.")
    code = 400
    title = 'Aggregation Algorithm Out Of Scope'
    logger = "ERROR"


class SubMetaRuleOutOfScope(AuthzMetadata):
    message_format = _("The given sub meta rule is out of scope.")
    code = 400
    title = 'Sub Meta Rule Out Of Scope'
    logger = "ERROR"


class RuleOKNotExisting(AuthzRule):
    message_format = _("The positive rule for that request doen't exist.")
    code = 400
    title = 'Rule OK Not Existing'
    logger = "ERROR"


class RuleKOExisting(AuthzRule):
    message_format = _("The request match a negative rule.")
    code = 400
    title = 'Rule KO Existing'
    logger = "ERROR"


class RuleUnknown(AuthzRule):
    message_format = _("The rule for that request doesn't exist.")
    code = 400
    title = 'Rule Unknown'
    logger = "ERROR"


# Admin exceptions


class AdminException(MoonError):
    message_format = _("There is an authorization error requesting this IntraExtension.")
    code = 403
    title = 'Admin Exception'
    logger = "AUTHZ"


class AdminPerimeter(AuthzException):
    title = 'Perimeter Exception'


class AdminScope(AuthzException):
    title = 'Scope Exception'


class AdminMetadata(AuthzException):
    title = 'Metadata Exception'


class AdminAssignment(AuthzException):
    title = 'Assignment Exception'


class AdminRule(AuthzException):
    title = 'Rule Exception'

class AdminMetaRule(AuthzException):
    title = 'MetaRule Exception'


class SubjectReadNotAuthorized(AdminPerimeter):
    title = 'Subject Read Not Authorized'


class SubjectAddNotAuthorized(AdminPerimeter):
    title = 'Subject Add Not Authorized'


class SubjectDelNotAuthorized(AdminPerimeter):
    title = 'Subject Del Not Authorized'


class ObjectReadNotAuthorized(AdminPerimeter):
    title = 'Object Read Not Authorized'


class ObjectAddNotAuthorized(AdminPerimeter):
    title = 'Object Add Not Authorized'


class ObjectDelNotAuthorized(AdminPerimeter):
    title = 'Object Del Not Authorized'


class ActionReadNotAuthorized(AdminPerimeter):
    title = 'Action Read Not Authorized'


class ActionAddNotAuthorized(AdminPerimeter):
    title = 'Action Add Not Authorized'


class ActionDelNotAuthorized(AdminPerimeter):
    title = 'Action Del Not Authorized'


class SubjectScopeReadNotAuthorized(AuthzException):
    title = 'Subject Scope Read Not Authorized'


class SubjectScopeAddNotAuthorized(AuthzException):
    title = 'Subject Scope Add Not Authorized'


class SubjectScopeDelNotAuthorized(AuthzException):
    title = 'Subject Scope Del Not Authorized'


class ObjectScopeReadNotAuthorized(AuthzException):
    title = 'Object Scope Read Not Authorized'


class ObjectScopeAddNotAuthorized(AuthzException):
    title = 'Object Scope Add Not Authorized'


class ObjectScopeDelNotAuthorized(AuthzException):
    title = 'Object Scope Del Not Authorized'


class ActionScopeReadNotAuthorized(AuthzException):
    title = 'Action Scope Read Not Authorized'


class ActionScopeAddNotAuthorized(AuthzException):
    title = 'Action Scope Add Not Authorized'


class ActionScopeDelNotAuthorized(AuthzException):
    title = 'Action Scope Del Not Authorized'


class SubjectCategoryReadNotAuthorized(AdminMetadata):
    title = 'Subject Category Read Not Authorized'
    logger = "AUTHZ"


class SubjectCategoryAddNotAuthorized(AdminMetadata):
    title = 'Subject Category Add Not Authorized'


class SubjectCategoryDelNotAuthorized(AdminMetadata):
    title = 'Subject Category Del Not Authorized'


class ObjectCategoryReadNotAuthorized(AdminMetadata):
    title = 'Object Category Read Not Authorized'


class ObjectCategoryAddNotAuthorized(AdminMetadata):
    title = 'Object Category Add Not Authorized'


class ObjectCategoryDelNotAuthorized(AdminMetadata):
    title = 'Object Category Del Not Authorized'


class ActionCategoryReadNotAuthorized(AdminMetadata):
    title = 'Action Category Read Not Authorized'


class ActionCategoryAddNotAuthorized(AdminMetadata):
    title = 'Action Category Add Not Authorized'


class ActionCategoryDelNotAuthorized(AdminMetadata):
    title = 'Action Category Del Not Authorized'


class SubjectAssignmentReadNotAuthorized(AdminAssignment):
    title = 'Subject Assignment Read Not Authorized'


class SubjectAssignmentAddNotAuthorized(AdminAssignment):
    title = 'Subject Assignment Add Not Authorized'


class SubjectAssignmentDelNotAuthorized(AdminAssignment):
    title = 'Subject Assignment Del Not Authorized'


class ObjectAssignmentReadNotAuthorized(AdminAssignment):
    title = 'Object Assignment Read Not Authorized'


class ObjectAssignmentAddNotAuthorized(AdminAssignment):
    title = 'Object Assignment Add Not Authorized'


class ObjectAssignmentDelNotAuthorized(AdminAssignment):
    title = 'Object Assignment Del Not Authorized'


class ActionAssignmentReadNotAuthorized(AdminAssignment):
    title = 'Action Assignment Read Not Authorized'


class ActionAssignmentAddNotAuthorized(AdminAssignment):
    title = 'Action Assignment Add Not Authorized'


class ActionAssignmentDelNotAuthorized(AdminAssignment):
    title = 'Action Assignment Del Not Authorized'


class RuleReadNotAuthorized(AdminRule):
    title = 'Rule Read Not Authorized'


class RuleAddNotAuthorized(AdminRule):
    title = 'Rule Add Not Authorized'


class RuleDelNotAuthorized(AdminRule):
    title = 'Rule Del Not Authorized'


class MetaRuleReadNotAuthorized(AdminRule):
    title = 'MetaRule Read Not Authorized'


class MetaRuleAddNotAuthorized(AdminRule):
    title = 'MetaRule Add Not Authorized'


class MetaRuleDelNotAuthorized(AdminRule):
    title = 'MetaRule Del Not Authorized'