~ubuntu-branches/ubuntu/saucy/keystone/saucy-proposed

« back to all changes in this revision

Viewing changes to keystone/logic/types/fault.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-08-23 10:18:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110823101822-enve6zceb3lqhuvj
Tags: upstream-1.0~d4~20110823.1078
ImportĀ upstreamĀ versionĀ 1.0~d4~20110823.1078

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2010-2011 OpenStack, LLC.
 
2
#
 
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
 
6
#
 
7
#    http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
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
 
12
# implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
 
 
16
import json
 
17
from lxml import etree
 
18
 
 
19
 
 
20
class IdentityFault(Exception):
 
21
    """Base Exception type for all auth exceptions"""
 
22
 
 
23
    def __init__(self, msg, details=None, code=500):
 
24
        self.args = (code, msg, details)
 
25
        self.code = code
 
26
        self.msg = msg
 
27
        self.details = details
 
28
        self.key = "IdentityFault"
 
29
 
 
30
    @property
 
31
    def message(self):
 
32
        return self.msg
 
33
 
 
34
    def to_xml(self):
 
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")
 
39
        msg.text = self.msg
 
40
        dom.append(msg)
 
41
        if self.details != None:
 
42
            desc = etree.Element("details")
 
43
            desc.text = self.details
 
44
            dom.append(desc)
 
45
        return etree.tostring(dom)
 
46
 
 
47
    def to_json(self):
 
48
        fault = {}
 
49
        fault["message"] = self.msg
 
50
        fault["code"] = str(self.code)
 
51
        if self.details != None:
 
52
            fault["details"] = self.details
 
53
        ret = {}
 
54
        ret[self.key] = fault
 
55
        return json.dumps(ret)
 
56
 
 
57
 
 
58
class ServiceUnavailableFault(IdentityFault):
 
59
    """The auth service is unavailable"""
 
60
 
 
61
    def __init__(self, msg, details=None, code=503):
 
62
        super(ServiceUnavailableFault, self).__init__(msg, details, code)
 
63
        self.key = "serviceUnavailable"
 
64
 
 
65
 
 
66
class BadRequestFault(IdentityFault):
 
67
    """Bad user request"""
 
68
 
 
69
    def __init__(self, msg, details=None, code=400):
 
70
        super(BadRequestFault, self).__init__(msg, details, code)
 
71
        self.key = "badRequest"
 
72
 
 
73
 
 
74
class UnauthorizedFault(IdentityFault):
 
75
    """User is unauthorized"""
 
76
 
 
77
    def __init__(self, msg, details=None, code=401):
 
78
        super(UnauthorizedFault, self).__init__(msg, details, code)
 
79
        self.key = "unauthorized"
 
80
 
 
81
 
 
82
class ForbiddenFault(IdentityFault):
 
83
    """The user is forbidden"""
 
84
 
 
85
    def __init__(self, msg, details=None, code=403):
 
86
        super(ForbiddenFault, self).__init__(msg, details, code)
 
87
        self.key = "forbidden"
 
88
 
 
89
 
 
90
class ItemNotFoundFault(IdentityFault):
 
91
    """The item is not found"""
 
92
 
 
93
    def __init__(self, msg, details=None, code=404):
 
94
        super(ItemNotFoundFault, self).__init__(msg, details, code)
 
95
        self.key = "itemNotFound"
 
96
 
 
97
 
 
98
class TenantDisabledFault(IdentityFault):
 
99
    """The tenant is disabled"""
 
100
 
 
101
    def __init__(self, msg, details=None, code=403):
 
102
        super(TenantDisabledFault, self).__init__(msg, details, code)
 
103
        self.key = "tenantDisabled"
 
104
 
 
105
 
 
106
class TenantConflictFault(IdentityFault):
 
107
    """The tenant already exists?"""
 
108
 
 
109
    def __init__(self, msg, details=None, code=409):
 
110
        super(TenantConflictFault, self).__init__(msg, details, code)
 
111
        self.key = "tenantConflict"
 
112
 
 
113
 
 
114
class OverlimitFault(IdentityFault):
 
115
    """A limit has been exceeded"""
 
116
 
 
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"
 
122
 
 
123
 
 
124
class UserConflictFault(IdentityFault):
 
125
    """The User already exists?"""
 
126
 
 
127
    def __init__(self, msg, details=None, code=409):
 
128
        super(UserConflictFault, self).__init__(msg, details, code)
 
129
        self.key = "userConflict"
 
130
 
 
131
 
 
132
class UserDisabledFault(IdentityFault):
 
133
    """The user is disabled"""
 
134
 
 
135
    def __init__(self, msg, details=None, code=403):
 
136
        super(UserDisabledFault, self).__init__(msg, details, code)
 
137
        self.key = "userDisabled"
 
138
 
 
139
 
 
140
class EmailConflictFault(IdentityFault):
 
141
    """The Email already exists?"""
 
142
 
 
143
    def __init__(self, msg, details=None, code=409):
 
144
        super(EmailConflictFault, self).__init__(msg, details, code)
 
145
        self.key = "emailConflict"
 
146
 
 
147
 
 
148
class RoleConflictFault(IdentityFault):
 
149
    """The User already exists?"""
 
150
 
 
151
    def __init__(self, msg, details=None, code=409):
 
152
        super(RoleConflictFault, self).__init__(msg, details, code)
 
153
        self.key = "roleConflict"
 
154
 
 
155
 
 
156
class ServiceConflictFault(IdentityFault):
 
157
    """The Service already exists?"""
 
158
 
 
159
    def __init__(self, msg, details=None, code=409):
 
160
        super(ServiceConflictFault, self).__init__(msg, details, code)
 
161
        self.key = "serviceConflict"