Browse Source

Merge "Clean up app initialization and config"

tags/4.0.0
Zuul 5 days ago
parent
commit
06b49c03dd
2 changed files with 1 additions and 103 deletions
  1. 0
    71
      openstackclient/common/client_config.py
  2. 1
    32
      openstackclient/shell.py

+ 0
- 71
openstackclient/common/client_config.py View File

@@ -1,71 +0,0 @@
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
-"""OpenStackConfig subclass for argument compatibility"""
15
-
16
-from osc_lib.cli import client_config
17
-
18
-
19
-# Sublcass OpenStackConfig in order to munge config values
20
-# before auth plugins are loaded
21
-class OSC_Config(client_config.OSC_Config):
22
-
23
-    # TODO(dtroyer): Remove _auth_default_domain when the v3otp fix is
24
-    #                backported to osc-lib, should be in release 1.3.0
25
-    def _auth_default_domain(self, config):
26
-        """Set a default domain from available arguments
27
-
28
-        Migrated from clientmanager.setup_auth()
29
-        """
30
-
31
-        identity_version = config.get('identity_api_version', '')
32
-        auth_type = config.get('auth_type', None)
33
-
34
-        # TODO(mordred): This is a usability improvement that's broadly useful
35
-        # We should port it back up into os-client-config.
36
-        default_domain = config.get('default_domain', None)
37
-        if (identity_version == '3' and
38
-                not auth_type.startswith('v2') and
39
-                default_domain):
40
-
41
-            # NOTE(stevemar): If PROJECT_DOMAIN_ID or PROJECT_DOMAIN_NAME is
42
-            # present, then do not change the behaviour. Otherwise, set the
43
-            # PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
44
-            if (
45
-                    auth_type in ("password", "v3password", "v3totp") and
46
-                    not config['auth'].get('project_domain_id') and
47
-                    not config['auth'].get('project_domain_name')
48
-            ):
49
-                config['auth']['project_domain_id'] = default_domain
50
-
51
-            # NOTE(stevemar): If USER_DOMAIN_ID or USER_DOMAIN_NAME is present,
52
-            # then do not change the behaviour. Otherwise, set the
53
-            # USER_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
54
-            # NOTE(aloga): this should only be set if there is a username.
55
-            # TODO(dtroyer): Move this to os-client-config after the plugin has
56
-            # been loaded so we can check directly if the options are accepted.
57
-            if (
58
-                    auth_type in ("password", "v3password", "v3totp") and
59
-                    not config['auth'].get('user_domain_id') and
60
-                    not config['auth'].get('user_domain_name')
61
-            ):
62
-                config['auth']['user_domain_id'] = default_domain
63
-        return config
64
-
65
-    def load_auth_plugin(self, config):
66
-        """Get auth plugin and validate args"""
67
-
68
-        loader = self._get_auth_loader(config)
69
-        config = self._validate_auth(config, loader)
70
-        auth_plugin = loader.load_from_options(**config['auth'])
71
-        return auth_plugin

+ 1
- 32
openstackclient/shell.py View File

@@ -25,7 +25,6 @@ from osc_lib import shell
25 25
 import six
26 26
 
27 27
 import openstackclient
28
-from openstackclient.common import client_config as cloud_config
29 28
 from openstackclient.common import clientmanager
30 29
 
31 30
 
@@ -133,37 +132,7 @@ class OpenStackShell(shell.OpenStackShell):
133 132
     def initialize_app(self, argv):
134 133
         super(OpenStackShell, self).initialize_app(argv)
135 134
 
136
-        # Argument precedence is really broken in multiple places
137
-        # so we're just going to fix it here until o-c-c and osc-lib
138
-        # get sorted out.
139
-        # TODO(dtroyer): remove when os-client-config and osc-lib are fixed
140
-
141
-        # First, throw away what has already been done with o-c-c and
142
-        # use our own.
143
-        try:
144
-            self.cloud_config = cloud_config.OSC_Config(
145
-                override_defaults={
146
-                    'interface': None,
147
-                    'auth_type': self._auth_type,
148
-                },
149
-            )
150
-        except (IOError, OSError):
151
-            self.log.critical("Could not read clouds.yaml configuration file")
152
-            self.print_help_if_requested()
153
-            raise
154
-
155
-        if not self.options.debug:
156
-            self.options.debug = None
157
-
158
-        # NOTE(dtroyer): Need to do this with validate=False to defer the
159
-        #                auth plugin handling to ClientManager.setup_auth()
160
-        self.cloud = self.cloud_config.get_one_cloud(
161
-            cloud=self.options.cloud,
162
-            argparse=self.options,
163
-            validate=False,
164
-        )
165
-
166
-        # Then, re-create the client_manager with the correct arguments
135
+        # Re-create the client_manager with our subclass
167 136
         self.client_manager = clientmanager.ClientManager(
168 137
             cli_options=self.cloud,
169 138
             api_version=self.api_version,

Loading…
Cancel
Save