|
19 | 19 | import pkg_resources |
20 | 20 | import sys |
21 | 21 |
|
22 | | -from keystoneauth1.loading import base |
23 | | -from osc_lib.api import auth |
24 | 22 | from osc_lib import clientmanager |
25 | 23 |
|
26 | 24 |
|
|
31 | 29 | USER_AGENT = 'python-openstackclient' |
32 | 30 |
|
33 | 31 |
|
34 | | -# NOTE(dtroyer): Bringing back select_auth_plugin() and build_auth_params() |
35 | | -# temporarily because osc-lib 0.3.0 removed it a wee bit early |
36 | | -def select_auth_plugin(options): |
37 | | - """Pick an auth plugin based on --os-auth-type or other options""" |
38 | | - |
39 | | - auth_plugin_name = None |
40 | | - |
41 | | - # Do the token/url check first as this must override the default |
42 | | - # 'password' set by os-client-config |
43 | | - # Also, url and token are not copied into o-c-c's auth dict (yet?) |
44 | | - if options.auth.get('url') and options.auth.get('token'): |
45 | | - # service token authentication |
46 | | - auth_plugin_name = 'token_endpoint' |
47 | | - elif options.auth_type in auth.PLUGIN_LIST: |
48 | | - # A direct plugin name was given, use it |
49 | | - auth_plugin_name = options.auth_type |
50 | | - elif options.auth.get('username'): |
51 | | - if options.identity_api_version == '3': |
52 | | - auth_plugin_name = 'v3password' |
53 | | - elif options.identity_api_version.startswith('2'): |
54 | | - auth_plugin_name = 'v2password' |
55 | | - else: |
56 | | - # let keystoneauth figure it out itself |
57 | | - auth_plugin_name = 'password' |
58 | | - elif options.auth.get('token'): |
59 | | - if options.identity_api_version == '3': |
60 | | - auth_plugin_name = 'v3token' |
61 | | - elif options.identity_api_version.startswith('2'): |
62 | | - auth_plugin_name = 'v2token' |
63 | | - else: |
64 | | - # let keystoneauth figure it out itself |
65 | | - auth_plugin_name = 'token' |
66 | | - else: |
67 | | - # The ultimate default is similar to the original behaviour, |
68 | | - # but this time with version discovery |
69 | | - auth_plugin_name = 'password' |
70 | | - LOG.debug("Auth plugin %s selected", auth_plugin_name) |
71 | | - return auth_plugin_name |
72 | | - |
73 | | - |
74 | | -def build_auth_params(auth_plugin_name, cmd_options): |
75 | | - if auth_plugin_name: |
76 | | - LOG.debug('auth_type: %s', auth_plugin_name) |
77 | | - auth_plugin_loader = base.get_plugin_loader(auth_plugin_name) |
78 | | - auth_params = { |
79 | | - opt.dest: opt.default |
80 | | - for opt in base.get_plugin_options(auth_plugin_name) |
81 | | - } |
82 | | - auth_params.update(dict(cmd_options.auth)) |
83 | | - # grab tenant from project for v2.0 API compatibility |
84 | | - if auth_plugin_name.startswith("v2"): |
85 | | - if 'project_id' in auth_params: |
86 | | - auth_params['tenant_id'] = auth_params['project_id'] |
87 | | - del auth_params['project_id'] |
88 | | - if 'project_name' in auth_params: |
89 | | - auth_params['tenant_name'] = auth_params['project_name'] |
90 | | - del auth_params['project_name'] |
91 | | - else: |
92 | | - LOG.debug('no auth_type') |
93 | | - # delay the plugin choice, grab every option |
94 | | - auth_plugin_loader = None |
95 | | - auth_params = dict(cmd_options.auth) |
96 | | - plugin_options = set( |
97 | | - [o.replace('-', '_') for o in auth.get_options_list()] |
98 | | - ) |
99 | | - for option in plugin_options: |
100 | | - LOG.debug('fetching option %s', option) |
101 | | - auth_params[option] = getattr(cmd_options.auth, option, None) |
102 | | - return (auth_plugin_loader, auth_params) |
103 | | - |
104 | | - |
105 | 32 | class ClientManager(clientmanager.ClientManager): |
106 | 33 | """Manages access to API clients, including authentication |
107 | 34 |
|
|
0 commit comments