Skip to content

Commit

Permalink
fix: use HTTPS for the API connectivity check
Browse files Browse the repository at this point in the history
  • Loading branch information
haatveit committed Oct 12, 2023
1 parent 0e8d24a commit 72478be
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions tsdapiclient/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import os
import pathlib
import socket
import sys
import time

Expand Down Expand Up @@ -224,14 +223,28 @@ def get_data_path(env: str, pnum: str) -> str:
return str(data_path)


def has_api_connectivity(hostname: str, port: int = 443, timeout: float = 0.5) -> bool:
def has_api_connectivity(
hostname: str,
port: int = 443,
timeout: float = 0.5,
schema: str = "https",
) -> bool:
"""Verify that a connection can be made to the API.
Args:
hostname (str): domain where the API is hosted
port (int, optional): TCP port the API is listening on. Defaults to 443.
timeout (float, optional): how long to wait for a response. Defaults to 0.5 seconds.
schema (str, optional): protocol to use. Defaults to "https".
Returns:
bool: _description_
"""
connectivity = False
try:
sock = socket.socket()
sock.settimeout(timeout)
sock.connect((hostname, port))
connectivity = True
sock.close()
r = requests.get(f"{schema}://{hostname}:{port}", timeout=timeout)
if r.status_code != 403:
connectivity = True
except:
pass
return connectivity
Expand Down

0 comments on commit 72478be

Please sign in to comment.