barbican  12.0.0
About: OpenStack Barbican is the OpenStack Key Manager service. It provides secure storage, provisioning and management of secret data.
The "Wallaby" series (latest release).
  Fossies Dox: barbican-12.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

exception.py
Go to the documentation of this file.
1 # Copyright (c) 2013-2014 Rackspace, Inc.
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 """
17 Barbican exception subclasses
18 """
19 
20 from barbican import i18n as u
21 
22 _FATAL_EXCEPTION_FORMAT_ERRORS = False
23 
24 
25 class BarbicanException(Exception):
26  """Base Barbican Exception
27 
28  To correctly use this class, inherit from it and define
29  a 'message' property. That message will get printf'd
30  with the keyword arguments provided to the constructor.
31  """
32  message = u._("An unknown exception occurred")
33 
34  def __init__(self, message_arg=None, *args, **kwargs):
35  if not message_arg:
36  message_arg = self.messagemessage
37  try:
38  self.messagemessage = message_arg % kwargs
39  except Exception as e:
40  if _FATAL_EXCEPTION_FORMAT_ERRORS:
41  raise e
42  else:
43  # at least get the core message out if something happened
44  pass
45  super(BarbicanException, self).__init__(self.messagemessage)
46 
47 
49  """Base Barbican Exception to handle HTTP responses
50 
51  To correctly use this class, inherit from it and define the following
52  properties:
53 
54  - message: The message that will be displayed in the server log.
55  - client_message: The message that will actually be outputted to the
56  client.
57  - status_code: The HTTP status code that should be returned.
58  The default status code is 500.
59  """
60  client_message = u._("failure seen - please contact site administrator.")
61  status_code = 500
62 
63  def __init__(self, message_arg=None, client_message=None, *args, **kwargs):
64  if not client_message:
65  client_message = self.client_messageclient_message
66  try:
67  self.client_messageclient_message = client_message % kwargs
68  except Exception as e:
69  if _FATAL_EXCEPTION_FORMAT_ERRORS:
70  raise e
71  else:
72  # at least get the core message out if something happened
73  pass
74  super(BarbicanHTTPException, self).__init__(
75  message_arg, self.client_messageclient_message, *args, **kwargs)
76 
77 
79  message = u._("Missing required argument.")
80 
81 
83  message = u._("Missing required metadata field for %(required)s")
84  client_message = message
85  status_code = 400
86 
87 
89  message = u._("Invalid Metadata. Keys and Values must be Strings.")
90  client_message = message
91  status_code = 400
92 
93 
95  message = u._("Invalid Key. Key must be URL safe.")
96  client_message = message
97  status_code = 400
98 
99 
101  message = u._("Invalid subject DN: %(subject_dn)s")
102  client_message = message
103  status_code = 400
104 
105 
107  message = u._("Invalid container: %(reason)s")
108  client_message = message
109  status_code = 400
110 
111 
113  message = u._("Invalid extensions data.")
114  client_message = message
115  status_code = 400
116 
117 
119  message = u._("Invalid CMC Data")
120  client_message = message
121  status_code = 400
122 
123 
125  message = u._("Invalid PKCS10 Data: %(reason)s")
126  client_message = message
127  status_code = 400
128 
129 
131  message = u._("Invalid Certificate Request Type")
132  client_message = message
133  status_code = 400
134 
135 
137  message = u._("Extensions are not yet supported. "
138  "Specify a valid profile instead.")
139  client_message = message
140  status_code = 400
141 
142 
144  message = u._("Full CMC Requests are not yet supported.")
145  client_message = message
146  status_code = 400
147 
148 
150  message = u._("An object with the specified identifier was not found.")
151 
152 
154  message = u._("A defined SQL constraint check failed: %(error)s")
155 
156 
158  message = u._("Operation is not supported.")
159 
160 
162  message = u._("Data supplied was not valid.")
163 
164 
166  message = u._("No data supplied to process.")
167  client_message = message
168  status_code = 400
169 
170 
172  message = u._("The request returned a 413 Request Entity Too Large. This "
173  "generally means that rate limiting or a quota threshold "
174  "was breached.")
175  client_message = u._("Provided information too large to process")
176  status_code = 413
177 
178  def __init__(self, *args, **kwargs):
179  super(LimitExceeded, self).__init__(*args, **kwargs)
180  self.retry_afterretry_after = (int(kwargs['retry']) if kwargs.get('retry')
181  else None)
182 
183 
185  status_code = 400
186 
187  def __init__(self, *args, **kwargs):
188  self.invalid_propertyinvalid_property = kwargs.get('property')
189  self.messagemessagemessage = u._("Failed to validate JSON information: ")
190  self.client_messageclient_messageclient_message = u._("Provided object does not match "
191  "schema '{schema}': "
192  "{reason}. Invalid property: "
193  "'{property}'").format(*args, **kwargs)
194  self.messagemessagemessage = self.messagemessagemessage + self.client_messageclient_messageclient_message
195  super(InvalidObject, self).__init__(*args, **kwargs)
196 
197 
199  status_code = 400
200  message = u._("Error while attempting to decode payload.")
201  client_message = u._("Unable to decode request data.")
202 
203 
205  message = u._("No support for value set on field '%(field)s' on "
206  "schema '%(schema)s': %(reason)s")
207  client_message = u._("Provided field value is not supported")
208  status_code = 400
209 
210  def __init__(self, *args, **kwargs):
211  super(UnsupportedField, self).__init__(*args, **kwargs)
212  self.invalid_fieldinvalid_field = kwargs.get('field')
213 
214 
216  message = u._("Feature not implemented for value set on field "
217  "'%(field)s' on " "schema '%(schema)s': %(reason)s")
218 
219  def __init__(self, *args, **kwargs):
220  super(FeatureNotImplemented, self).__init__(*args, **kwargs)
221  self.invalid_fieldinvalid_field = kwargs.get('field')
222 
223 
225  message = u._("Container %(container_id)s does not exist for stored "
226  "key certificate generation.")
227 
228 
230  message = u._("Container %(container_id)s does not reference a private "
231  "key needed for stored key certificate generation.")
232 
233 
235  message = u._("Provided Transport key %(transport_key_id)s "
236  "could not be found")
237  client_message = u._("Provided transport key was not found.")
238  status_code = 400
239 
240 
242  message = u._("Invalid CA_ID: %(ca_id)s")
243  client_message = u._("The ca_id provided in the request is invalid")
244  status_code = 400
245 
246 
248  message = u._("CA specified by ca_id %(ca_id)s not defined for project: "
249  "%(project_id)s")
250  client_message = u._("The ca_id provided in the request is not defined "
251  "for this project")
252  status_code = 403
253 
254 
256  message = u._("Quota reached for project %(external_project_id)s. Only "
257  "%(quota)s %(resource_type)s are allowed.")
258  client_message = u._("Creation not allowed because a quota has "
259  "been reached")
260  status_code = 403
261 
262  def __init__(self, *args, **kwargs):
263  super(QuotaReached, self).__init__(*args, **kwargs)
264  self.external_project_idexternal_project_id = kwargs.get('external_project_id')
265  self.quotaquota = kwargs.get('quota')
266  self.resource_typeresource_type = kwargs.get('resource_type')
267 
268 
270  message = u._("Invalid Parent CA: %(parent_ca_ref)s")
271  client_message = message
272  status_code = 400
273 
274 
276  message = u._("Plugin does not support generation of subordinate CAs")
277  client_message = message
278  status_code = 400
279 
280 
282  message = u._("Errors in creating subordinate CA: %(name)")
283  client_message = message
284 
285 
287  message = u._("Only subordinate CAs can be deleted.")
288  status_code = 403
289 
290 
292  message = u._("Subordinate CA is not owned by this project")
293  client_message = message
294  status_code = 403
295 
296 
298  message = u._("A new project preferred CA must be set "
299  "before this one can be deleted.")
300  status_code = 409
301 
302 
304  message = u._("Errors returned by CA when attempting to "
305  "create subordinate CA: %(reason)s")
306  client_message = message
307  status_code = 400
308 
309 
311  message = u._("Errors returned by CA when attempting to create "
312  "subordinate CA: %(reason)s")
313  client_message = message
314 
315 
317  message = u._("Errors returned by CA when attempting to delete "
318  "subordinate CA: %(reason)s")
319  client_message = message
320 
321 
323  message = u._("There was an error with the PKCS#11 library.")
324 
325 
327  message = u._("More than one key found for label")
328 
329 
331  message = u._("General exception")
332 
333 
335  message = u._("No key handle was found")
336 
337 
339  message = u._("No token was found in slot %(slot_id)s")
340 
341 
343  """Raised when a preferred plugin is missing in service configuration."""
344  def __init__(self, store_name):
345  super(MultipleStorePreferredPluginMissing, self).__init__(
346  u._("Preferred Secret Store plugin '{store_name}' is not "
347  "currently set in service configuration. This is probably a "
348  "server misconfiguration.").format(
349  store_name=store_name)
350  )
351  self.store_namestore_name = store_name
352 
353 
355  """Raised when a used plugin is missing in service configuration."""
356  def __init__(self, store_name):
357  super(MultipleStorePluginStillInUse, self).__init__(
358  u._("Secret Store plugin '{store_name}' is still in use and can "
359  "not be removed. Its missing in service configuration. This is"
360  " probably a server misconfiguration.").format(
361  store_name=store_name)
362  )
363  self.store_namestore_name = store_name
364 
365 
367  """Raised when a plugin lookup suffix is missing during config read."""
368  def __init__(self):
369  msg = u._("Plugin lookup property 'stores_lookup_suffix' is not "
370  "defined in service configuration")
371  super(MultipleSecretStoreLookupFailed, self).__init__(msg)
372 
373 
375  """Raised when a global default for only one plugin is not set to True."""
376  def __init__(self, occurrence):
377  msg = None
378  if occurrence > 1:
379  msg = u._("There are {count} plugins with global default as "
380  "True in service configuration. Only one plugin can have"
381  " this as True").format(count=occurrence)
382  else:
383  msg = u._("There is no plugin defined with global default as True."
384  " One of plugin must be identified as global default")
385 
386  super(MultipleStoreIncorrectGlobalDefault, self).__init__(msg)
387 
388 
390  """Raised when a store plugin value is missing in service configuration."""
391  def __init__(self, section_name):
392  super(MultipleStorePluginValueMissing, self).__init__(
393  u._("In section '{0}', secret_store_plugin value is missing"
394  ).format(section_name)
395  )
396  self.section_namesection_name = section_name
def __init__(self, message_arg=None, *args, **kwargs)
Definition: exception.py:34
def __init__(self, message_arg=None, client_message=None, *args, **kwargs)
Definition: exception.py:63
def __init__(self, *args, **kwargs)
Definition: exception.py:187
def __init__(self, *args, **kwargs)
Definition: exception.py:178
def __init__(self, *args, **kwargs)
Definition: exception.py:262
def __init__(self, *args, **kwargs)
Definition: exception.py:210