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)  

json_home.py
Go to the documentation of this file.
1 # Copyright 2014 IBM Corp.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # 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, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14 
15 from oslo_serialization import jsonutils
16 
17 from keystone import exception
18 from keystone.i18n import _
19 
20 
21 def build_v3_resource_relation(resource_name):
22  return ('https://docs.openstack.org/api/openstack-identity/3/rel/%s' %
23  resource_name)
24 
25 
26 def build_v3_extension_resource_relation(extension_name, extension_version,
27  resource_name):
28  return (
29  'https://docs.openstack.org/api/openstack-identity/3/ext/%s/%s/rel/'
30  '%s' % (extension_name, extension_version, resource_name))
31 
32 
33 def build_v3_parameter_relation(parameter_name):
34  return ('https://docs.openstack.org/api/openstack-identity/3/param/%s' %
35  parameter_name)
36 
37 
38 def build_v3_extension_parameter_relation(extension_name, extension_version,
39  parameter_name):
40  return (
41  'https://docs.openstack.org/api/openstack-identity/3/ext/%s/%s/param/'
42  '%s' % (extension_name, extension_version, parameter_name))
43 
44 
45 class Parameters(object):
46  """Relationships for Common parameters."""
47 
48  DOMAIN_ID = build_v3_parameter_relation('domain_id')
49  ENDPOINT_ID = build_v3_parameter_relation('endpoint_id')
50  GROUP_ID = build_v3_parameter_relation('group_id')
51  POLICY_ID = build_v3_parameter_relation('policy_id')
52  PROJECT_ID = build_v3_parameter_relation('project_id')
53  REGION_ID = build_v3_parameter_relation('region_id')
54  ROLE_ID = build_v3_parameter_relation('role_id')
55  SERVICE_ID = build_v3_parameter_relation('service_id')
56  USER_ID = build_v3_parameter_relation('user_id')
57  TAG_VALUE = build_v3_parameter_relation('tag_value')
58  REGISTERED_LIMIT_ID = build_v3_parameter_relation('registered_limit_id')
59  LIMIT_ID = build_v3_parameter_relation('limit_id')
60  APPLICATION_CRED_ID = build_v3_parameter_relation(
61  'application_credential_id')
62  ACCESS_RULE_ID = build_v3_parameter_relation(
63  'access_rule_id')
64 
65 
66 class Status(object):
67  """Status values supported."""
68 
69  DEPRECATED = 'deprecated'
70  EXPERIMENTAL = 'experimental'
71  STABLE = 'stable'
72 
73  @classmethod
74  def update_resource_data(cls, resource_data, status):
75  if status is cls.STABLE:
76  # We currently do not add a status if the resource is stable, the
77  # absence of the status property can be taken as meaning that the
78  # resource is stable.
79  return
80  if status is cls.DEPRECATED or status is cls.EXPERIMENTAL:
81  resource_data['hints'] = {'status': status}
82  return
83 
84  raise exception.Error(message=_(
85  'Unexpected status requested for JSON Home response, %s') % status)
86 
87 
88 class JsonHomeResources(object):
89  """JSON Home resource data."""
90 
91  __resources = {}
92  __serialized_resource_data = None
93 
94  @classmethod
95  def _reset(cls):
96  # NOTE(morgan): this will reset all json home resource definitions.
97  # This is only used for testing.
98  cls.__resources.clear()
100 
101  @classmethod
102  def append_resource(cls, rel, data):
103  cls.__resources[rel] = data
104  cls.__serialized_resource_data = None
105 
106  @classmethod
107  def resources(cls):
108  # NOTE(morgan): We use a serialized form of the resource data to
109  # ensure that the raw data is not changed by processing, this method
110  # simply populates the serialized store if it is not already populated.
111  # Any changes to this class storage object will result in clearing
112  # the serialized data value.
113  if cls.__serialized_resource_data is None:
114  cls.__serialized_resource_data = jsonutils.dumps(cls.__resources)
115  return {'resources': jsonutils.loads(cls.__serialized_resource_data)}
116 
117 
118 def translate_urls(json_home, new_prefix):
119  """Given a JSON Home document, sticks new_prefix on each of the urls."""
120  for dummy_rel, resource in json_home['resources'].items():
121  if 'href' in resource:
122  resource['href'] = new_prefix + resource['href']
123  elif 'href-template' in resource:
124  resource['href-template'] = new_prefix + resource['href-template']
keystone.common.json_home.build_v3_resource_relation
def build_v3_resource_relation(resource_name)
Definition: json_home.py:21
keystone.common.json_home.Parameters
Definition: json_home.py:45
keystone.common.json_home.JsonHomeResources.append_resource
def append_resource(cls, rel, data)
Definition: json_home.py:102
keystone.common.json_home.Status.update_resource_data
def update_resource_data(cls, resource_data, status)
Definition: json_home.py:74
keystone.common.json_home.JsonHomeResources.resources
def resources(cls)
Definition: json_home.py:107
keystone.common.json_home.Status
Definition: json_home.py:66
keystone.common.json_home.build_v3_extension_resource_relation
def build_v3_extension_resource_relation(extension_name, extension_version, resource_name)
Definition: json_home.py:27
keystone.common.json_home.JsonHomeResources
Definition: json_home.py:88
keystone.exception.Error
Definition: exception.py:62
keystone.common.json_home.build_v3_parameter_relation
def build_v3_parameter_relation(parameter_name)
Definition: json_home.py:33
keystone.common.json_home.translate_urls
def translate_urls(json_home, new_prefix)
Definition: json_home.py:118
keystone.common.json_home.build_v3_extension_parameter_relation
def build_v3_extension_parameter_relation(extension_name, extension_version, parameter_name)
Definition: json_home.py:39
keystone.common.json_home.JsonHomeResources.__resources
dictionary __resources
Definition: json_home.py:91
keystone.common.json_home.Status.STABLE
string STABLE
Definition: json_home.py:71
keystone.common.json_home.Status.EXPERIMENTAL
string EXPERIMENTAL
Definition: json_home.py:70
keystone.i18n._
_
Definition: i18n.py:29
keystone.i18n
Definition: i18n.py:1
keystone.common.json_home.JsonHomeResources.__serialized_resource_data
__serialized_resource_data
Definition: json_home.py:92
keystone.common.json_home.JsonHomeResources._reset
def _reset(cls)
Definition: json_home.py:95
keystone.common.json_home.Status.DEPRECATED
string DEPRECATED
Definition: json_home.py:69