1515
1616import logging
1717
18- from os_client_config import config
1918from os_client_config import exceptions as occ_exceptions
20- from oslo_utils import strutils
21- import six
19+ from osc_lib .cli import client_config
2220
2321
2422LOG = logging .getLogger (__name__ )
2523
2624
2725# Sublcass OpenStackConfig in order to munge config values
2826# before auth plugins are loaded
29- class OSC_Config (config . OpenStackConfig ):
27+ class OSC_Config (client_config . OSC_Config ):
3028
3129 # TODO(dtroyer): Once os-client-config with pw_func argument is in
3230 # global-requirements we can remove __init()__
@@ -62,75 +60,8 @@ def __init__(
6260
6361 return ret
6462
65- def _auth_select_default_plugin (self , config ):
66- """Select a default plugin based on supplied arguments
67-
68- Migrated from auth.select_auth_plugin()
69- """
70-
71- identity_version = config .get ('identity_api_version' , '' )
72-
73- if config .get ('username' , None ) and not config .get ('auth_type' , None ):
74- if identity_version == '3' :
75- config ['auth_type' ] = 'v3password'
76- elif identity_version .startswith ('2' ):
77- config ['auth_type' ] = 'v2password'
78- else :
79- # let keystoneauth figure it out itself
80- config ['auth_type' ] = 'password'
81- elif config .get ('token' , None ) and not config .get ('auth_type' , None ):
82- if identity_version == '3' :
83- config ['auth_type' ] = 'v3token'
84- elif identity_version .startswith ('2' ):
85- config ['auth_type' ] = 'v2token'
86- else :
87- # let keystoneauth figure it out itself
88- config ['auth_type' ] = 'token'
89- else :
90- # The ultimate default is similar to the original behaviour,
91- # but this time with version discovery
92- if not config .get ('auth_type' , None ):
93- config ['auth_type' ] = 'password'
94-
95- LOG .debug ("Auth plugin %s selected" % config ['auth_type' ])
96- return config
97-
98- def _auth_v2_arguments (self , config ):
99- """Set up v2-required arguments from v3 info
100-
101- Migrated from auth.build_auth_params()
102- """
103-
104- if ('auth_type' in config and config ['auth_type' ].startswith ("v2" )):
105- if 'project_id' in config ['auth' ]:
106- config ['auth' ]['tenant_id' ] = config ['auth' ]['project_id' ]
107- if 'project_name' in config ['auth' ]:
108- config ['auth' ]['tenant_name' ] = config ['auth' ]['project_name' ]
109- return config
110-
111- def _auth_v2_ignore_v3 (self , config ):
112- """Remove v3 arguemnts if present for v2 plugin
113-
114- Migrated from clientmanager.setup_auth()
115- """
116-
117- # NOTE(hieulq): If USER_DOMAIN_NAME, USER_DOMAIN_ID, PROJECT_DOMAIN_ID
118- # or PROJECT_DOMAIN_NAME is present and API_VERSION is 2.0, then
119- # ignore all domain related configs.
120- if (config .get ('identity_api_version' , '' ).startswith ('2' ) and
121- config .get ('auth_type' , None ).endswith ('password' )):
122- domain_props = [
123- 'project_domain_id' ,
124- 'project_domain_name' ,
125- 'user_domain_id' ,
126- 'user_domain_name' ,
127- ]
128- for prop in domain_props :
129- if config ['auth' ].pop (prop , None ) is not None :
130- LOG .warning ("Ignoring domain related config " +
131- prop + " because identity API version is 2.0" )
132- return config
133-
63+ # TODO(dtroyer): Remove _auth_default_domain when the v3otp fix is
64+ # backported to osc-lib, should be in release 1.3.0
13465 def _auth_default_domain (self , config ):
13566 """Set a default domain from available arguments
13667
@@ -171,23 +102,6 @@ def _auth_default_domain(self, config):
171102 config ['auth' ]['user_domain_id' ] = default_domain
172103 return config
173104
174- def auth_config_hook (self , config ):
175- """Allow examination of config values before loading auth plugin
176-
177- OpenStackClient will override this to perform additional chacks
178- on auth_type.
179- """
180-
181- config = self ._auth_select_default_plugin (config )
182- config = self ._auth_v2_arguments (config )
183- config = self ._auth_v2_ignore_v3 (config )
184- config = self ._auth_default_domain (config )
185-
186- if LOG .isEnabledFor (logging .DEBUG ):
187- LOG .debug ("auth_config_hook(): %s" ,
188- strutils .mask_password (six .text_type (config )))
189- return config
190-
191105 def load_auth_plugin (self , config ):
192106 """Get auth plugin and validate args"""
193107
@@ -196,10 +110,12 @@ def load_auth_plugin(self, config):
196110 auth_plugin = loader .load_from_options (** config ['auth' ])
197111 return auth_plugin
198112
113+ # TODO(dtroyer): Remove _validate_auth_ksc when it is in osc-lib 1.3.0
199114 def _validate_auth_ksc (self , config , cloud , fixed_argparse = None ):
200115 """Old compatibility hack for OSC, no longer needed/wanted"""
201116 return config
202117
118+ # TODO(dtroyer): Remove _validate_auth when it is in osc-lib 1.3.0
203119 def _validate_auth (self , config , loader , fixed_argparse = None ):
204120 """Validate auth plugin arguments"""
205121 # May throw a keystoneauth1.exceptions.NoMatchingPlugin
0 commit comments