Skip to content

Commit 2f4cfb6

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Move OSC auth plugins so they can be found"
2 parents 0fed88f + 749920b commit 2f4cfb6

7 files changed

Lines changed: 123 additions & 113 deletions

File tree

‎examples/common.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ def base_parser(parser):
8484
"""
8585

8686
# Global arguments
87-
parser.add_argument(
88-
'--os-url',
89-
metavar='<url>',
90-
default=env('OS_URL'),
91-
help='Defaults to env[OS_URL]',
92-
)
9387
parser.add_argument(
9488
'--os-region-name',
9589
metavar='<auth-region-name>',

‎openstackclient/api/auth.py‎

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616
import argparse
1717
import logging
1818

19-
from six.moves.urllib import parse as urlparse
2019
import stevedore
2120

22-
from oslo_config import cfg
23-
2421
from keystoneclient.auth import base
25-
from keystoneclient.auth.identity.generic import password as ksc_password
2622

2723
from openstackclient.common import exceptions as exc
2824
from openstackclient.common import utils
@@ -201,96 +197,3 @@ def build_auth_plugins_option_parser(parser):
201197
help=argparse.SUPPRESS,
202198
)
203199
return parser
204-
205-
206-
class TokenEndpoint(base.BaseAuthPlugin):
207-
"""Auth plugin to handle traditional token/endpoint usage
208-
209-
Implements the methods required to handle token authentication
210-
with a user-specified token and service endpoint; no Identity calls
211-
are made for re-scoping, service catalog lookups or the like.
212-
213-
The purpose of this plugin is to get rid of the special-case paths
214-
in the code to handle this authentication format. Its primary use
215-
is for bootstrapping the Keystone database.
216-
"""
217-
218-
def __init__(self, url, token, **kwargs):
219-
"""A plugin for static authentication with an existing token
220-
221-
:param string url: Service endpoint
222-
:param string token: Existing token
223-
"""
224-
super(TokenEndpoint, self).__init__()
225-
self.endpoint = url
226-
self.token = token
227-
228-
def get_endpoint(self, session, **kwargs):
229-
"""Return the supplied endpoint"""
230-
return self.endpoint
231-
232-
def get_token(self, session):
233-
"""Return the supplied token"""
234-
return self.token
235-
236-
def get_auth_ref(self, session, **kwargs):
237-
"""Stub this method for compatibility"""
238-
return None
239-
240-
# Override this because it needs to be a class method...
241-
@classmethod
242-
def get_options(self):
243-
options = super(TokenEndpoint, self).get_options()
244-
245-
options.extend([
246-
# Maintain name 'url' for compatibility
247-
cfg.StrOpt('url',
248-
help='Specific service endpoint to use'),
249-
cfg.StrOpt('token',
250-
secret=True,
251-
help='Authentication token to use'),
252-
])
253-
254-
return options
255-
256-
257-
class OSCGenericPassword(ksc_password.Password):
258-
"""Auth plugin hack to work around broken Keystone configurations
259-
260-
The default Keystone configuration uses http://localhost:xxxx in
261-
admin_endpoint and public_endpoint and are returned in the links.href
262-
attribute by the version routes. Deployments that do not set these
263-
are unusable with newer keystoneclient version discovery.
264-
265-
"""
266-
267-
def create_plugin(self, session, version, url, raw_status=None):
268-
"""Handle default Keystone endpoint configuration
269-
270-
Build the actual API endpoint from the scheme, host and port of the
271-
original auth URL and the rest from the returned version URL.
272-
"""
273-
274-
ver_u = urlparse.urlparse(url)
275-
276-
# Only hack this if it is the default setting
277-
if ver_u.netloc.startswith('localhost'):
278-
auth_u = urlparse.urlparse(self.auth_url)
279-
# from original auth_url: scheme, netloc
280-
# from api_url: path, query (basically, the rest)
281-
url = urlparse.urlunparse((
282-
auth_u.scheme,
283-
auth_u.netloc,
284-
ver_u.path,
285-
ver_u.params,
286-
ver_u.query,
287-
ver_u.fragment,
288-
))
289-
LOG.debug('Version URL updated: %s' % url)
290-
291-
return super(OSCGenericPassword, self).create_plugin(
292-
session=session,
293-
version=version,
294-
url=url,
295-
raw_status=raw_status,
296-
)

‎openstackclient/api/auth_plugin.py‎

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
# http://www.apache.org/licenses/LICENSE-2.0
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+
#
13+
14+
"""Authentication Plugin Library"""
15+
16+
import logging
17+
18+
from oslo_config import cfg
19+
from six.moves.urllib import parse as urlparse
20+
21+
from keystoneclient.auth import base
22+
from keystoneclient.auth.identity.generic import password as ksc_password
23+
24+
25+
LOG = logging.getLogger(__name__)
26+
27+
28+
class TokenEndpoint(base.BaseAuthPlugin):
29+
"""Auth plugin to handle traditional token/endpoint usage
30+
31+
Implements the methods required to handle token authentication
32+
with a user-specified token and service endpoint; no Identity calls
33+
are made for re-scoping, service catalog lookups or the like.
34+
35+
The purpose of this plugin is to get rid of the special-case paths
36+
in the code to handle this authentication format. Its primary use
37+
is for bootstrapping the Keystone database.
38+
"""
39+
40+
def __init__(self, url, token, **kwargs):
41+
"""A plugin for static authentication with an existing token
42+
43+
:param string url: Service endpoint
44+
:param string token: Existing token
45+
"""
46+
super(TokenEndpoint, self).__init__()
47+
self.endpoint = url
48+
self.token = token
49+
50+
def get_endpoint(self, session, **kwargs):
51+
"""Return the supplied endpoint"""
52+
return self.endpoint
53+
54+
def get_token(self, session):
55+
"""Return the supplied token"""
56+
return self.token
57+
58+
def get_auth_ref(self, session, **kwargs):
59+
"""Stub this method for compatibility"""
60+
return None
61+
62+
# Override this because it needs to be a class method...
63+
@classmethod
64+
def get_options(self):
65+
options = super(TokenEndpoint, self).get_options()
66+
67+
options.extend([
68+
# Maintain name 'url' for compatibility
69+
cfg.StrOpt('url',
70+
help='Specific service endpoint to use'),
71+
cfg.StrOpt('token',
72+
secret=True,
73+
help='Authentication token to use'),
74+
])
75+
76+
return options
77+
78+
79+
class OSCGenericPassword(ksc_password.Password):
80+
"""Auth plugin hack to work around broken Keystone configurations
81+
82+
The default Keystone configuration uses http://localhost:xxxx in
83+
admin_endpoint and public_endpoint and are returned in the links.href
84+
attribute by the version routes. Deployments that do not set these
85+
are unusable with newer keystoneclient version discovery.
86+
87+
"""
88+
89+
def create_plugin(self, session, version, url, raw_status=None):
90+
"""Handle default Keystone endpoint configuration
91+
92+
Build the actual API endpoint from the scheme, host and port of the
93+
original auth URL and the rest from the returned version URL.
94+
"""
95+
96+
ver_u = urlparse.urlparse(url)
97+
98+
# Only hack this if it is the default setting
99+
if ver_u.netloc.startswith('localhost'):
100+
auth_u = urlparse.urlparse(self.auth_url)
101+
# from original auth_url: scheme, netloc
102+
# from api_url: path, query (basically, the rest)
103+
url = urlparse.urlunparse((
104+
auth_u.scheme,
105+
auth_u.netloc,
106+
ver_u.path,
107+
ver_u.params,
108+
ver_u.query,
109+
ver_u.fragment,
110+
))
111+
LOG.debug('Version URL updated: %s' % url)
112+
113+
return super(OSCGenericPassword, self).create_plugin(
114+
session=session,
115+
version=version,
116+
url=url,
117+
raw_status=raw_status,
118+
)

‎openstackclient/common/clientmanager.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def setup_auth(self):
122122
# password auth is requested.
123123
if (self.auth_plugin_name.endswith('password') and
124124
not self._cli_options.os_password):
125-
self._cli_options.os_password = self.pw_callback()
125+
self._cli_options.os_password = self._pw_callback()
126126

127127
(auth_plugin, self._auth_params) = auth.build_auth_params(
128128
self.auth_plugin_name,

‎openstackclient/shell.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ def build_option_parser(self, description, version):
188188
description,
189189
version)
190190

191-
# service token auth argument
192-
parser.add_argument(
193-
'--os-url',
194-
metavar='<url>',
195-
default=utils.env('OS_URL'),
196-
help='Defaults to env[OS_URL]')
197191
# Global arguments
198192
parser.add_argument(
199193
'--os-region-name',

‎openstackclient/tests/common/test_clientmanager.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from oslo_serialization import jsonutils
2121

2222
from openstackclient.api import auth
23+
from openstackclient.api import auth_plugin
2324
from openstackclient.common import clientmanager
2425
from openstackclient.common import exceptions as exc
2526
from openstackclient.tests import fakes
@@ -100,7 +101,7 @@ def test_client_manager_token_endpoint(self):
100101
)
101102
self.assertIsInstance(
102103
client_manager.auth,
103-
auth.TokenEndpoint,
104+
auth_plugin.TokenEndpoint,
104105
)
105106
self.assertFalse(client_manager._insecure)
106107
self.assertTrue(client_manager._verify)

‎setup.cfg‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ console_scripts =
2828
openstack = openstackclient.shell:main
2929

3030
keystoneclient.auth.plugin =
31-
token_endpoint = openstackclient.api.auth:TokenEndpoint
32-
osc_password = openstackclient.api.auth:OSCGenericPassword
31+
token_endpoint = openstackclient.api.auth_plugin:TokenEndpoint
32+
osc_password = openstackclient.api.auth_plugin:OSCGenericPassword
3333

3434
openstack.cli =
3535
command_list = openstackclient.common.module:ListCommand

0 commit comments

Comments
 (0)