1
# Copyright (c) 2010-2011 OpenStack, LLC.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
17
from lxml import etree
20
class IdentityFault(Exception):
21
"""Base Exception type for all auth exceptions"""
23
def __init__(self, msg, details=None, code=500):
24
self.args = (code, msg, details)
27
self.details = details
28
self.key = "IdentityFault"
35
dom = etree.Element(self.key,
36
xmlns="http://docs.openstack.org/identity/api/v2.0")
37
dom.set("code", str(self.code))
38
msg = etree.Element("message")
41
if self.details != None:
42
desc = etree.Element("details")
43
desc.text = self.details
45
return etree.tostring(dom)
49
fault["message"] = self.msg
50
fault["code"] = str(self.code)
51
if self.details != None:
52
fault["details"] = self.details
55
return json.dumps(ret)
58
class ServiceUnavailableFault(IdentityFault):
59
"""The auth service is unavailable"""
61
def __init__(self, msg, details=None, code=503):
62
super(ServiceUnavailableFault, self).__init__(msg, details, code)
63
self.key = "serviceUnavailable"
66
class BadRequestFault(IdentityFault):
67
"""Bad user request"""
69
def __init__(self, msg, details=None, code=400):
70
super(BadRequestFault, self).__init__(msg, details, code)
71
self.key = "badRequest"
74
class UnauthorizedFault(IdentityFault):
75
"""User is unauthorized"""
77
def __init__(self, msg, details=None, code=401):
78
super(UnauthorizedFault, self).__init__(msg, details, code)
79
self.key = "unauthorized"
82
class ForbiddenFault(IdentityFault):
83
"""The user is forbidden"""
85
def __init__(self, msg, details=None, code=403):
86
super(ForbiddenFault, self).__init__(msg, details, code)
87
self.key = "forbidden"
90
class ItemNotFoundFault(IdentityFault):
91
"""The item is not found"""
93
def __init__(self, msg, details=None, code=404):
94
super(ItemNotFoundFault, self).__init__(msg, details, code)
95
self.key = "itemNotFound"
98
class TenantDisabledFault(IdentityFault):
99
"""The tenant is disabled"""
101
def __init__(self, msg, details=None, code=403):
102
super(TenantDisabledFault, self).__init__(msg, details, code)
103
self.key = "tenantDisabled"
106
class TenantConflictFault(IdentityFault):
107
"""The tenant already exists?"""
109
def __init__(self, msg, details=None, code=409):
110
super(TenantConflictFault, self).__init__(msg, details, code)
111
self.key = "tenantConflict"
114
class OverlimitFault(IdentityFault):
115
"""A limit has been exceeded"""
117
def __init__(self, msg, details=None, code=409, retry_at=None):
118
super(OverlimitFault, self).__init__(msg, details, code)
119
self.args = (code, msg, details, retry_at)
120
self.retry_at = retry_at
121
self.key = "overLimit"
124
class UserConflictFault(IdentityFault):
125
"""The User already exists?"""
127
def __init__(self, msg, details=None, code=409):
128
super(UserConflictFault, self).__init__(msg, details, code)
129
self.key = "userConflict"
132
class UserDisabledFault(IdentityFault):
133
"""The user is disabled"""
135
def __init__(self, msg, details=None, code=403):
136
super(UserDisabledFault, self).__init__(msg, details, code)
137
self.key = "userDisabled"
140
class EmailConflictFault(IdentityFault):
141
"""The Email already exists?"""
143
def __init__(self, msg, details=None, code=409):
144
super(EmailConflictFault, self).__init__(msg, details, code)
145
self.key = "emailConflict"
148
class RoleConflictFault(IdentityFault):
149
"""The User already exists?"""
151
def __init__(self, msg, details=None, code=409):
152
super(RoleConflictFault, self).__init__(msg, details, code)
153
self.key = "roleConflict"
156
class ServiceConflictFault(IdentityFault):
157
"""The Service already exists?"""
159
def __init__(self, msg, details=None, code=409):
160
super(ServiceConflictFault, self).__init__(msg, details, code)
161
self.key = "serviceConflict"