Skip to content

Commit

Permalink
Merge pull request #130 from francescotimperi/auto-protocol
Browse files Browse the repository at this point in the history
chore: fix in supporting nuvolaris.protocol parameter
  • Loading branch information
francescotimperi authored Nov 1, 2023
2 parents 8d9ee75 + b800d96 commit 0e1aa70
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions nuvolaris/apihost_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ def get_ingress(namespace="ingress-nginx",ingress_srv_name="service/ingress-ngin
return None

def assign_protocol(runtime_str, url):
"""
Assign the url protocol. If not protocol is defined or it is in auto mode
will use https in case the TLS compoenent is enabled, http otherwise.
Setting inside the whisk.yaml the attribute nuvolaris.protocol will forse always to use the
configured one, i.e it can be set as http despite it is in https and viceversa.
"""
# if no protocol is defined, or it is in auto mode, uses https in case tls is enabled
if not cfg.exists("nuvolaris.protocol") or 'auto' == cfg.get("nuvolaris.protocol"):
if cfg.exists("nuvolaris.protocol") and cfg.get("nuvolaris.protocol") in ["http","https"]:
url = url._replace(scheme = cfg.get("nuvolaris.protocol"))
else:
if cfg.get('components.tls'):
url = url._replace(scheme = "https")
else:
Expand All @@ -87,6 +95,8 @@ def assign_protocol(runtime_str, url):
if runtime_str == "kind":
url = url._replace(scheme = "http")

return url

def calculate_apihost(runtime_str,apiHost=None):
"""
Calculate the apihost url
Expand All @@ -103,13 +113,11 @@ def calculate_apihost(runtime_str,apiHost=None):
# in auto mode we should use the calculated ip address
if cfg.exists("nuvolaris.apihost") and not 'auto' == cfg.get('nuvolaris.apihost'):
url = url._replace(netloc = ensure_host(cfg.get("nuvolaris.apihost")))
if cfg.exists("nuvolaris.protocol") and not 'auto' == cfg.get("nuvolaris.protocol"):
url = url._replace(scheme = cfg.get("nuvolaris.protocol"))
if cfg.exists("nuvolaris.apiport"):
url = url._replace(netloc = f"{url.hostname}:{cfg.get('nuvolaris.apiport')}")

assign_protocol(runtime_str, url)
return url.geturl()
final_url = assign_protocol(runtime_str, url)
return final_url.geturl()

def get_apihost(runtime_str):
"""
Expand Down Expand Up @@ -170,8 +178,8 @@ def get_user_static_url(runtime, hostname):
"""
url = urllib.parse.urlparse(f"http://{hostname}")

assign_protocol(runtime, url)
return url.geturl()
final_url = assign_protocol(runtime, url)
return final_url.geturl()

def get_user_api_url(runtime, hostname, api_context):
"""
Expand All @@ -180,7 +188,7 @@ def get_user_api_url(runtime, hostname, api_context):
full_hostname = hostname.endswith("/") and f"{hostname}{api_context}" or f"{hostname}/{api_context}"
url = urllib.parse.urlparse(f"http://{full_hostname}")

assign_protocol(runtime, url)
return url.geturl()
final_url = assign_protocol(runtime, url)
return final_url.geturl()


0 comments on commit 0e1aa70

Please sign in to comment.