keystone  18.0.0
About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Victoria" series (maintained release).
  Fossies Dox: keystone-18.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)
Go to the documentation of this file.
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 #
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12 """Request body validating middleware for OpenStack Identity resources."""
14 from keystone.common.validation import validators
17 def lazy_validate(request_body_schema, resource_to_validate):
18  """A non-decorator way to validate a request, to be used inline.
20  :param request_body_schema: a schema to validate the resource reference
21  :param resource_to_validate: dictionary to validate
22  :raises keystone.exception.ValidationError: if `resource_to_validate` is
23  None. (see wrapper method below).
24  :raises TypeError: at decoration time when the expected resource to
25  validate isn't found in the decorated method's
26  signature
28  """
29  schema_validator = validators.SchemaValidator(request_body_schema)
30  schema_validator.validate(resource_to_validate)
33 def nullable(property_schema):
34  """Clone a property schema into one that is nullable.
36  :param dict property_schema: schema to clone into a nullable schema
37  :returns: a new dict schema
38  """
39  # TODO(dstanek): deal with the case where type is already a list; we don't
40  # do that yet so I'm not wasting time on it
41  new_schema = property_schema.copy()
42  new_schema['type'] = [property_schema['type'], 'null']
43  # NOTE(kmalloc): If enum is specified (such as our boolean case) ensure we
44  # add null to the enum as well so that null can be passed/validated as
45  # expected. Without adding to the enum, null will not validate as enum is
46  # explicitly listing valid values. According to the JSON Schema
47  # specification, the values must be unique in the enum array.
48  if 'enum' in new_schema and None not in new_schema['enum']:
49  # In the enum the 'null' is NoneType
50  new_schema['enum'].append(None)
51  return new_schema
def nullable(property_schema)
def lazy_validate(request_body_schema, resource_to_validate)