Skip to content

Commit

Permalink
openshift.py: Use super() in init and added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanMPhm committed Feb 6, 2024
1 parent c214a5b commit 76b302a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/coldfront_plugin_cloud/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def __init__(
resource: resource_models.Resource,
allocation: allocation_models.Allocation,
):
self.resource = resource
self.allocation = allocation
super().__init__(resource, allocation)

# Load Endpoint URL and Auth token for new k8 client
var_name = utils.env_safe_name(self.resource.name)
Expand All @@ -110,9 +109,11 @@ def __init__(
k8_config.host = openshift_url

if functional_tests == "true" or verify == "false":
self.logger = logging.getLogger()
logger = logging.getLogger()
k8_config.verify_ssl = False
else:
self.logger = logging.getLogger("django")
logger = logging.getLogger("django")
k8_config.verify_ssl = True

Expand Down Expand Up @@ -192,7 +193,8 @@ def create_federated_user(self, unique_id):
return "TODO create user"

if created:
return {"msg": f"user created ({unique_id})"}
self.logger.info(f"msg: user created ({unique_id})")
return

raise Conflict("400: " + f"user already exists ({unique_id})")
except Conflict:
Expand Down Expand Up @@ -241,17 +243,18 @@ def _create_project(self, project_name, project_id):
annotations=annotations,
labels=labels,
)
return {"msg": f"project created ({project_name})"}
self.logger.info(f"msg: project created ({project_name})")

def _get_role(self, username, project_id):
# /users/<user_name>/projects/<project>/roles/<role>

if self.client.user_rolebinding_exists(
username, project_id, self.member_role_name
):
return {
"msg": f"user role exists ({project_id},{username},{self.member_role_name})"
}
self.logger.info(
f"msg: user role exists ({project_id},{username},{self.member_role_name})"
)
return

raise NotFound(
"404: "
Expand All @@ -260,7 +263,8 @@ def _get_role(self, username, project_id):

def _get_project(self, project_id):
if self.client.project_exists(project_id):
return {"msg": f"project exists ({project_id})"}
self.logger.info(f"msg: project exists ({project_id})")
return

raise NotFound("400: " + f"project does not exist ({project_id})")

Expand Down

0 comments on commit 76b302a

Please sign in to comment.