Skip to content

Commit

Permalink
Merge pull request #4 from mkudlej/speedrun-fixes
Browse files Browse the repository at this point in the history
add speedrun fixes + using ocp namespace
  • Loading branch information
mkudlej authored Apr 18, 2024
2 parents 05297f2 + 0c788a7 commit 262a382
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions threescale_api_crd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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"

Expand Down
25 changes: 14 additions & 11 deletions threescale_api_crd/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion threescale_api_crd/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 262a382

Please sign in to comment.