diff --git a/threescale_api_crd/client.py b/threescale_api_crd/client.py index 3976146..52f6826 100644 --- a/threescale_api_crd/client.py +++ b/threescale_api_crd/client.py @@ -13,10 +13,10 @@ class ThreeScaleClientCRD(threescale_api.client.ThreeScaleClient): Threescale client for CRD. """ - def __init__(self, url, token, ocp_provider_ref=None, *args, **kwargs): + def __init__(self, url, token, ocp_provider_ref=None, ocp_namespace=None, *args, **kwargs): super().__init__(url, token, *args, **kwargs) self._ocp_provider_ref = ocp_provider_ref - self._ocp_namespace = ThreeScaleClientCRD.get_namespace() + self._ocp_namespace = ThreeScaleClientCRD.get_namespace(ocp_namespace) self._services = resources.Services( parent=self, instance_klass=resources.Service ) @@ -47,12 +47,12 @@ def __init__(self, url, token, ocp_provider_ref=None, *args, **kwargs): ) @classmethod - def get_namespace(_ignore): + def get_namespace(_ignore, namespace): """ Returns namespace. If there is no valid Openshift 'oc' session, returns "NOT LOGGED IN". """ try: - return ocp.get_project_name() + return namespace or ocp.get_project_name() except OpenShiftPythonException: return "NOT LOGGED IN" diff --git a/threescale_api_crd/defaults.py b/threescale_api_crd/defaults.py index 10310bb..fcaa6ba 100644 --- a/threescale_api_crd/defaults.py +++ b/threescale_api_crd/defaults.py @@ -33,6 +33,7 @@ def __init__( entity_name=entity_name, entity_collection=entity_collection, ) + ocp.set_default_project(self.threescale_client.ocp_namespace) def get_list(self, typ="normal"): """Returns list of entities.""" @@ -87,17 +88,17 @@ def read_by_name(self, name: str, **kwargs) -> "DefaultResourceCRD": """ return self.fetch_crd_entity(name) or super().read_by_name(name, **kwargs) - # def read(self, entity_id: int = None) -> 'DefaultResourceCRD': - # """Read the instance, read will just create empty resource and lazyloads only if needed - # Args: - # entity_id(int): Entity id - # Returns(DefaultResourceCRD): Default resource - # """ - # LOG.debug(self._log_message("[READ] CRD Read ", entity_id=entity_id)) - # if self.is_crd_implemented(): - # self.fetch(entity_id=entity_id) - # else: - # return threescale_api.defaults.DefaultClient.read(self, entity_id, **kwargs) + def read(self, entity_id: int = None, **kwargs) -> 'DefaultResourceCRD': + """Read the instance, read will just create empty resource and lazyloads only if needed + Args: + entity_id(int): Entity id + Returns(DefaultResourceCRD): Default resource + """ + LOG.debug(self._log_message("[READ] CRD Read ", entity_id=entity_id)) + if self.is_crd_implemented(): + return self.fetch(entity_id=entity_id, **kwargs) + else: + return threescale_api.defaults.DefaultClient.read(self, entity_id, **kwargs) def fetch(self, entity_id: int = None, **kwargs): """Fetches the entity dictionary @@ -568,6 +569,8 @@ def __init__(self, *args, crd=None, **kwargs): @property def crd(self): """CRD object property.""" + if not self._crd: + self.read() return self._crd or self.entity.get("crd", None) @crd.setter diff --git a/threescale_api_crd/resources.py b/threescale_api_crd/resources.py index 518ce1a..175c4ce 100644 --- a/threescale_api_crd/resources.py +++ b/threescale_api_crd/resources.py @@ -1966,6 +1966,7 @@ def __init__(self, **kwargs): "auth_user_key", "auth_app_id", "auth_app_key", + "api_test_path" ] if any([att not in entity for att in required_attrs]): self.client.disable_crd_implemented() @@ -2052,7 +2053,7 @@ def update(self, params: dict = None, **kwargs): proxy = self.parent.list() oidc = proxy.oidc["oidc_configuration"] oidc.update(params["oidc_configuration"]) - proxy.update(oidc=oidc) + return proxy.update(oidc=oidc) def read(self, params: dict = None, **kwargs): proxy = self.parent.list()