Skip to content
Snippets Groups Projects
Commit 0a6186bc authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Add https option to config

parent 9e9ea02e
No related branches found
No related tags found
No related merge requests found
......@@ -159,10 +159,9 @@ def build_url(config, endpoint: str = "") -> str:
"""
Build a URL for requests
"""
if config["server"]["port"] == 80:
protocol = "http"
else:
protocol = "https"
if not config["server"]["https"]:
protocol = "http"
url = '{}://{}/{}'.format(protocol, config["server"]["address"].rstrip("/"), endpoint.lstrip("/"))
return url
......@@ -198,7 +197,7 @@ def send_request(verified_id, config, logger) -> str:
Send post request to stechuhr-server
Return true if everything was ok, false otherwise
"""
if int(config["server"]["port"]) == 443:
if int(config["server"]["https"]):
target_address = 'https://{}:{}/'.format(config["server"]["address"], config["server"]["port"])
else:
target_address = 'http://{}:{}/'.format(config["server"]["address"], config["server"]["port"])
......@@ -370,7 +369,11 @@ def update_id_patterns(config, logger) -> 'Config':
logger.debug("Requesting id_pattern update at address: {}".format(url))
# Send request
try:
r = requests.get(url, timeout=config["server"]["timeout"])
except urllib3.exceptions.NewConnectionError as e:
logger.error(f"Couldn't reach server at \"{url}\" (using existing patterns instead): {e}")
return config
# If the response was ok update the pattern if it changed, else display a warning
if r.ok:
......
......@@ -24,6 +24,7 @@ dryrun = true
[server]
address = "127.0.0.1"
port = 80
https = true
timeout = 5
verify_cert = true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment