From fce52eac4f08b90694b038d4593f8a8d93b3a211 Mon Sep 17 00:00:00 2001 From: Francesco Timperi Tiberi Date: Wed, 5 Jul 2023 18:12:32 +0100 Subject: [PATCH] feature: adds STATIC_CONTENT_URL user metadata when user web bucket is exposed via the static ingress --- nuvolaris/apihost_util.py | 18 +++++++++++++++++- nuvolaris/minio_static.py | 12 +++++++++--- nuvolaris/user_metadata.py | 2 +- tests/microk8s/whisk-user.yaml | 6 +++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/nuvolaris/apihost_util.py b/nuvolaris/apihost_util.py index bb0a5ff..8f48534 100644 --- a/nuvolaris/apihost_util.py +++ b/nuvolaris/apihost_util.py @@ -150,4 +150,20 @@ def get_user_static_hostname(runtime_str, username): apihost = extract_hostname(apihost_url) return f"{username}.{apihost}" - raise Exception(f"Could not determine hostname for static bucket for username {username}") \ No newline at end of file + raise Exception(f"Could not determine hostname for static bucket for username {username}") + +def get_user_static_url(runtime_str, hostname, bucket_name): + """ + Build the full URL that will give access to the user web bucket via the static endpoint + """ + if runtime_str=="kind": + hostname = f"{hostname}/{bucket_name}" + + url = urllib.parse.urlparse(f"http://{hostname}") + + if cfg.get('components.tls') and not runtime_str=="kind": + url = url._replace(scheme = "https") + else: + url = url._replace(scheme = "http") + + return url.geturl() diff --git a/nuvolaris/minio_static.py b/nuvolaris/minio_static.py index 60d458d..eb943c1 100644 --- a/nuvolaris/minio_static.py +++ b/nuvolaris/minio_static.py @@ -23,6 +23,8 @@ import nuvolaris.template as ntp import nuvolaris.apihost_util as apihost_util +from nuvolaris.user_metadata import UserMetadata + def create(owner=None): logging.info(f"*** configuring nuvolaris nginx static provider") @@ -148,14 +150,18 @@ def create_static_route(namespace,data): return res -def create_ow_static_endpoint(ucfg, owner=None): +def create_ow_static_endpoint(ucfg, user_metadata: UserMetadata, owner=None): namespace = ucfg.get("namespace") runtime = cfg.get('nuvolaris.kube') - hostname = apihost_util.get_user_static_hostname(runtime, namespace) + bucket_name = ucfg.get("object-storage.route.bucket") + + hostname = apihost_util.get_user_static_hostname(runtime, namespace) logging.debug(f"using hostname {hostname} to configure access to user web static space") - try: + try: + user_metadata.add_metadata("STATIC_CONTENT_URL",apihost_util.get_user_static_url(runtime, hostname, bucket_name)) data = runtime=='openshift' and prepare_static_osh_data(ucfg, hostname) or prepare_static_ingress_data(ucfg, hostname) + if(runtime=='openshift'): return create_static_route(namespace, data) diff --git a/nuvolaris/user_metadata.py b/nuvolaris/user_metadata.py index 2948e02..9f1f832 100644 --- a/nuvolaris/user_metadata.py +++ b/nuvolaris/user_metadata.py @@ -41,6 +41,6 @@ def add_metadata(self, key: str, value: str): self._data['metadata'].append({"key":key, "value":value}) def get_metadata(self): - return self._data + return self._data diff --git a/tests/microk8s/whisk-user.yaml b/tests/microk8s/whisk-user.yaml index 6be4b7a..861b600 100644 --- a/tests/microk8s/whisk-user.yaml +++ b/tests/microk8s/whisk-user.yaml @@ -40,4 +40,8 @@ spec: mongodb: enabled: true database: franztt - password: ahfdajsfdafdasffdasdja \ No newline at end of file + password: ahfdajsfdafdasffdasdja + postgres: + enabled: true + database: franztt + password: urghgdghhggkjdgksdjh \ No newline at end of file