Package list python-castellan / 712e857
Use keystoneauth1 instead of keystoneclient The keystoneclient session has been deprecated in favour of keystoneauth1. To make this cleaner a few unnecessary usages of keystoneclient are cleaned up. Change-Id: I8bfcff53165a18f94c600797dd8105d64d948e7a Jamie Lennox 5 years ago
3 changed file(s) with 40 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
2121 from cryptography.hazmat import backends
2222 from cryptography.hazmat.primitives import serialization
2323 from cryptography import x509 as cryptography_x509
24 from keystoneclient.auth import identity
25 from keystoneclient import session
24 from keystoneauth1 import identity
25 from keystoneauth1 import loading
26 from keystoneauth1 import session
2627 from oslo_config import cfg
2728 from oslo_log import log as logging
2829 from oslo_utils import excutils
8485 self._base_url = None
8586 self.conf = configuration
8687 self.conf.register_opts(barbican_opts, group=BARBICAN_OPT_GROUP)
87 session.Session.register_conf_options(self.conf, BARBICAN_OPT_GROUP)
88 loading.register_session_conf_options(self.conf, BARBICAN_OPT_GROUP)
8889
8990 def _get_barbican_client(self, context):
9091 """Creates a client to connect to the Barbican service.
129130 auth_url = self.conf.barbican.auth_endpoint
130131
131132 if context.__class__.__name__ is 'KeystonePassword':
132 return identity.v3.Password(
133 return identity.V3Password(
133134 auth_url=auth_url,
134135 username=context.username,
135136 password=context.password,
145146 project_domain_name=context.project_domain_name,
146147 reauthenticate=context.reauthenticate)
147148 elif context.__class__.__name__ is 'KeystoneToken':
148 return identity.v3.Token(
149 return identity.V3Token(
149150 auth_url=auth_url,
150151 token=context.token,
151152 trust_id=context.trust_id,
159160 # this will be kept for oslo.context compatibility until
160161 # projects begin to use utils.credential_factory
161162 elif context.__class__.__name__ is 'RequestContext':
162 return identity.v3.Token(
163 return identity.V3Token(
163164 auth_url=auth_url,
164165 token=context.auth_token,
165166 project_id=context.tenant)
2020 import abc
2121 import uuid
2222
23 from keystoneclient.auth.identity import v3
24 from keystoneclient import session
25 from keystoneclient.v3 import client
23 from keystoneauth1 import identity
24 from keystoneauth1 import session
2625 from oslo_config import cfg
2726 from oslo_context import context
2827 from oslotest import base
112111 user_domain_name = CONF.identity.user_domain_name
113112 project_domain_name = CONF.identity.project_domain_name
114113
115 auth = v3.Password(auth_url=auth_url,
116 username=username,
117 password=password,
118 project_name=project_name,
119 user_domain_name=user_domain_name,
120 project_domain_name=project_domain_name)
114 auth = identity.V3Password(auth_url=auth_url,
115 username=username,
116 password=password,
117 project_name=project_name,
118 user_domain_name=user_domain_name,
119 project_domain_name=project_domain_name)
121120 sess = session.Session(auth=auth)
122 keystone_client = client.Client(session=sess)
123121
124 project_list = keystone_client.projects.list(name=project_name)
125
126 ctxt = context.RequestContext(
127 auth_token=auth.auth_ref.auth_token,
128 tenant=project_list[0].id)
129
130 return ctxt
122 return context.RequestContext(auth_token=auth.get_token(sess),
123 tenant=auth.get_project_id(sess))
131124
132125
133126 class BarbicanKeyManagerKSPasswordTestCase(BarbicanKeyManagerTestCase,
160153 user_domain_name = CONF.identity.user_domain_name
161154 project_domain_name = CONF.identity.project_domain_name
162155
163 auth = v3.Password(auth_url=auth_url,
164 username=username,
165 password=password,
166 project_name=project_name,
167 user_domain_name=user_domain_name,
168 project_domain_name=project_domain_name)
169 sess = session.Session(auth=auth)
170 keystone_client = client.Client(session=sess)
156 auth = identity.V3Password(auth_url=auth_url,
157 username=username,
158 password=password,
159 project_name=project_name,
160 user_domain_name=user_domain_name,
161 project_domain_name=project_domain_name)
162 sess = session.Session()
171163
172 project_list = keystone_client.projects.list(name=project_name)
173
174 ctxt = keystone_token.KeystoneToken(
175 token=auth.auth_ref.auth_token,
176 project_id=project_list[0].id)
177
178 return ctxt
164 return keystone_token.KeystoneToken(
165 token=auth.get_token(sess),
166 project_id=auth.get_project_id(sess))
5151 .. note::
5252
5353 Keystone Token and Password authentication is achieved using
54 keystoneclient.auth.identity.v3 Token and Password auth plugins.
54 keystoneauth1.identity Token and Password auth plugins.
5555 There are a variety of different variables which can be set for the
5656 keystone credential options.
5757
8787
8888 .. code:: python
8989
90 from keystoneclient.v3 import client
90 from keystoneauth1 import identity
91 from keystoneauth1 import session
9192 from oslo_context import context
9293
9394 username = 'admin'
9495 password = 'openstack'
9596 project_name = 'admin'
96 auth_url = 'http://localhost:5000/v3'
97 keystone_client = client.Client(username=username,
98 password=password,
99 project_name=project_name,
100 auth_url=auth_url,
101 project_domain_id='default')
102
103 project_list = keystone_client.projects.list(name=project_name)
104
105 ctxt = context.RequestContext(auth_token=keystone_client.auth_token,
106 tenant=project_list[0].id)
97 auth_url = 'http://localhost:5000/'
98 auth = identity.Password(auth_url=auth_url,
99 username=username,
100 password=password,
101 project_name=project_name,
102 default_domain_id='default')
103 sess = session.Session()
104
105 ctxt = context.RequestContext(auth_token=auth.get_token(sess),
106 tenant=auth.get_project_id(sess))
107107
108108 ctxt can then be passed into any key_manager api call.
109109