diff --git a/osc_lib/api/auth.py b/osc_lib/api/auth.py index 5d5064b..3963d0f 100644 --- a/osc_lib/api/auth.py +++ b/osc_lib/api/auth.py @@ -101,7 +101,7 @@ def check_valid_authentication_options(options, auth_plugin_name): msgs = [] # when no auth params are passed in, user advised to use os-cloud - if not options.auth: + if not options.auth and auth_plugin_name != 'none': msgs.append(_( 'Set a cloud-name with --os-cloud or OS_CLOUD' )) diff --git a/osc_lib/clientmanager.py b/osc_lib/clientmanager.py index afcda30..c7d0398 100644 --- a/osc_lib/clientmanager.py +++ b/osc_lib/clientmanager.py @@ -202,9 +202,15 @@ class ClientManager(object): self._auth_ref = self.auth.get_auth_ref(self.session) return self._auth_ref + def _override_for(self, service_type): + key = '%s_endpoint_override' % service_type.replace('-', '_') + return self._cli_options.config.get(key) + def is_service_available(self, service_type): """Check if a service type is in the current Service Catalog""" - + # If there is an override, assume the service is available + if self._override_for(service_type): + return True # Trigger authentication necessary to discover endpoint if self.auth_ref: service_catalog = self.auth_ref.service_catalog @@ -226,6 +232,11 @@ class ClientManager(object): def get_endpoint_for_service_type(self, service_type, region_name=None, interface='public'): """Return the endpoint URL for the service type.""" + # Overrides take priority unconditionally + override = self._override_for(service_type) + if override: + return override + if not interface: interface = 'public' # See if we are using password flow auth, i.e. we have a diff --git a/osc_lib/tests/test_clientmanager.py b/osc_lib/tests/test_clientmanager.py index 36ac56b..0f32fbe 100644 --- a/osc_lib/tests/test_clientmanager.py +++ b/osc_lib/tests/test_clientmanager.py @@ -419,6 +419,31 @@ class TestClientManager(utils.TestClientManager): self.assertEqual(client_manager.auth.project_id, fakes.PROJECT_ID) self.assertTrue(client_manager._auth_setup_completed) + def test_client_manager_none_auth(self): + # test token auth + client_manager = self._make_clientmanager( + auth_args={}, + auth_plugin_name='none', + ) + self.assertIsNone( + client_manager.get_endpoint_for_service_type('compute')) + + def test_client_manager_endpoint_override(self): + # test token auth + client_manager = self._make_clientmanager( + auth_args={}, + config_args={'compute_endpoint_override': 'http://example.com', + 'foo_bar_endpoint_override': 'http://example2.com'}, + auth_plugin_name='none', + ) + self.assertEqual( + 'http://example.com', + client_manager.get_endpoint_for_service_type('compute')) + self.assertEqual( + 'http://example2.com', + client_manager.get_endpoint_for_service_type('foo-bar')) + self.assertTrue(client_manager.is_service_available('compute')) + class TestClientManagerSDK(utils.TestClientManager): diff --git a/releasenotes/notes/auth-type-none-d96760912605f822.yaml b/releasenotes/notes/auth-type-none-d96760912605f822.yaml new file mode 100644 index 0000000..fad2291 --- /dev/null +++ b/releasenotes/notes/auth-type-none-d96760912605f822.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes incorrect error when using ``auth_type: none`` in ``clouds.yaml``. + - | + Respects the ``_endpoint_override`` configuration options, + similarly to openstacksdk.