Skip to content

Commit

Permalink
Merge pull request #76 from francescotimperi/issue-229
Browse files Browse the repository at this point in the history
  • Loading branch information
giusdp authored Jul 5, 2023
2 parents c799647 + fce52ea commit fe7646e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
18 changes: 17 additions & 1 deletion nuvolaris/apihost_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
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()
12 changes: 9 additions & 3 deletions nuvolaris/minio_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion nuvolaris/user_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


6 changes: 5 additions & 1 deletion tests/microk8s/whisk-user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ spec:
mongodb:
enabled: true
database: franztt
password: ahfdajsfdafdasffdasdja
password: ahfdajsfdafdasffdasdja
postgres:
enabled: true
database: franztt
password: urghgdghhggkjdgksdjh

0 comments on commit fe7646e

Please sign in to comment.