|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
13 | | -from openstack.auth.identity import v2 |
14 | | -from openstack.auth.identity import v3 |
15 | 13 | from openstack import exceptions |
16 | 14 |
|
| 15 | +from stevedore import driver |
17 | 16 |
|
18 | | -def create(username=None, password=None, token=None, auth_url=None, |
19 | | - version=None, project_name=None, domain_name=None, |
20 | | - project_domain_name=None, user_domain_name=None): |
| 17 | + |
| 18 | +def create(auth_plugin=None, **auth_args): |
21 | 19 | """Temporary code for creating an authenticator |
22 | 20 |
|
23 | 21 | This is temporary code to create an authenticator. This code will be |
24 | 22 | removed in the future. |
25 | 23 |
|
26 | | - :param string username: User name for authentication. |
27 | | - :param string password: Password associated with the user. |
28 | | - :param string token: Authentication token to use if available. |
29 | | - :param string auth_url: The URL to use for authentication. |
30 | | - :param string version: Version of authentication to use. |
31 | | - :param string project_name: Project name to athenticate. |
32 | | - :param string domain_name: Domain name to athenticate. |
33 | | - :param string project_domain_name: Project domain name to athenticate. |
34 | | - :param string user_domain_name: User domain name to athenticate. |
| 24 | + :param string auth_plugin: Name of authentication plugin to use. |
| 25 | + :param auth_args: Arguments for auth plugin. |
35 | 26 |
|
36 | 27 | :returns string: An authenticator. |
37 | 28 | """ |
38 | | - if auth_url is None: |
39 | | - msg = ("auth_url wasn't provided.") |
40 | | - raise exceptions.AuthorizationFailure(msg) |
41 | | - |
42 | | - endpoint_version = auth_url.split('v')[-1] |
43 | | - if version is None: |
44 | | - version = endpoint_version |
45 | 29 |
|
46 | | - version = version.lower().replace('v', '') |
47 | | - version = version.split('.')[0] |
48 | | - if version == '3': |
49 | | - args = {'user_name': username, 'password': password} |
50 | | - if project_name: |
51 | | - args['project_name'] = project_name |
52 | | - if domain_name: |
53 | | - args['domain_name'] = domain_name |
54 | | - if project_domain_name: |
55 | | - args['project_domain_name'] = project_domain_name |
56 | | - if user_domain_name: |
57 | | - args['user_domain_name'] = user_domain_name |
58 | | - if token: |
59 | | - args['token'] = token |
60 | | - return v3.Auth(auth_url, **args) |
61 | | - elif version == '2': |
62 | | - args = {'user_name': username, 'password': password} |
63 | | - if project_name: |
64 | | - args['project_name'] = project_name |
65 | | - if token: |
66 | | - args['token'] = token |
67 | | - return v2.Auth(auth_url, **args) |
68 | | - msg = ("No support for identity version: %s" % version) |
69 | | - raise exceptions.NoMatchingPlugin(msg) |
| 30 | + if auth_plugin is None: |
| 31 | + if 'auth_url' not in auth_args: |
| 32 | + msg = ("auth_url was not provided.") |
| 33 | + raise exceptions.AuthorizationFailure(msg) |
| 34 | + auth_url = auth_args['auth_url'] |
| 35 | + endpoint_version = auth_url.split('v')[-1][0] |
| 36 | + if endpoint_version == '2': |
| 37 | + auth_plugin = 'identity_v2' |
| 38 | + else: |
| 39 | + auth_plugin = 'identity_v3' |
| 40 | + |
| 41 | + mgr = driver.DriverManager( |
| 42 | + namespace="openstack.auth.plugin", |
| 43 | + name=auth_plugin, |
| 44 | + invoke_on_load=False, |
| 45 | + ) |
| 46 | + plugin = mgr.driver |
| 47 | + valid_list = plugin.valid_options |
| 48 | + args = {} |
| 49 | + for k in valid_list: |
| 50 | + if k in auth_args: |
| 51 | + args[k] = auth_args[k] |
| 52 | + return plugin(**args) |
0 commit comments