diff --git a/os_client_config/__init__.py b/os_client_config/__init__.py index 4246525..f5976b4 100644 --- a/os_client_config/__init__.py +++ b/os_client_config/__init__.py @@ -45,7 +45,7 @@ def get_config( def make_rest_client( service_key, options=None, - app_name=None, app_version=None, + app_name=None, app_version=None, version=None, **kwargs): """Simple wrapper function. It has almost no features. @@ -63,7 +63,7 @@ def make_rest_client( service_key=service_key, options=options, app_name=app_name, app_version=app_version, **kwargs) - return cloud.get_session_client(service_key) + return cloud.get_session_client(service_key, version=version) # Backwards compat - simple_client was a terrible name simple_client = make_rest_client # Backwards compat - session_client was a terrible name diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py index d8b1e26..2e97629 100644 --- a/os_client_config/cloud_config.py +++ b/os_client_config/cloud_config.py @@ -235,7 +235,27 @@ class CloudConfig(object): """Helper method to grab the service catalog.""" return self._auth.get_access(self.get_session()).service_catalog - def get_session_client(self, service_key): + def _get_version_args(self, service_key, version): + """Translate OCC version args to those needed by ksa adapter. + + If no version is requested explicitly and we have a configured version, + set the version parameter and let ksa deal with expanding that to + min=ver.0, max=ver.latest. + + If version is set, pass it through. + + If version is not set and we don't have a configured version, default + to latest. + """ + if version == 'latest': + return None, None, 'latest' + if not version: + version = self.get_api_version(service_key) + if not version: + return None, None, 'latest' + return version, None, None + + def get_session_client(self, service_key, version=None): """Return a prepped requests adapter for a given service. This is useful for making direct requests calls against a @@ -249,12 +269,17 @@ class CloudConfig(object): and it will work like you think. """ + (version, min_version, max_version) = self._get_version_args( + service_key, version) return adapter.Adapter( session=self.get_session(), service_type=self.get_service_type(service_key), service_name=self.get_service_name(service_key), interface=self.get_interface(service_key), + version=version, + min_version=min_version, + max_version=max_version, region_name=self.region) def _get_highest_endpoint(self, service_types, kwargs): diff --git a/releasenotes/notes/make-rest-client-version-discovery-84125700f159491a.yaml b/releasenotes/notes/make-rest-client-version-discovery-84125700f159491a.yaml new file mode 100644 index 0000000..7326978 --- /dev/null +++ b/releasenotes/notes/make-rest-client-version-discovery-84125700f159491a.yaml @@ -0,0 +1,6 @@ +--- +features: + - Add version argument to make_rest_client and plumb + version discovery through get_session_client so that + versioned endpoints are properly found if unversioned + are in the catalog.