Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
cli: fix build_component_url func.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinclert committed Apr 14, 2020
1 parent 51b3246 commit 75b7bff
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions reana_cluster/utils.py
Expand Up @@ -98,23 +98,27 @@ def build_component_url(host, ports, insecure=False):
:returns: Full URL to the component.
:rtype: str
"""
def _discover_https_port(ports):
https_ports = [443, 30443]
https_port_index = None
for https_port in https_ports:
def _discover_port(ports, target_ports):
target_port_index = None
for target in target_ports:
try:
https_port_index = ports.index(https_port)
target_port_index = ports.index(target)
except ValueError:
continue
return ports[https_port_index] if https_port_index else None
return ports[target_port_index] if target_port_index else None

https_port = _discover_port(ports, [443, 30443])
http_port = _discover_port(ports, [80, 30080])

https_port = _discover_https_port(ports)
if https_port and not insecure:
scheme = 'https'
port = https_port
else:
elif http_port:
scheme = 'http'
port = ports[0]
port = http_port
else:
logging.info('There are no ports available')
raise ValueError()

return '{scheme}://{host}:{port}'.format(
scheme=scheme, host=host, port=port)
Expand Down

0 comments on commit 75b7bff

Please sign in to comment.