Skip to content

Commit

Permalink
Support for HTTPS (#14)
Browse files Browse the repository at this point in the history
* Added support for HTTPS with optional certificate validation.

* Now FullyKiosk defaults to HTTP instead of HTTPS.
  • Loading branch information
r01k authored Nov 27, 2022
1 parent 12dad9e commit fddd27f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions fullykiosk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@


class FullyKiosk:
def __init__(self, session, host, port, password):
self._rh = _RequestsHandler(session, host, port)
def __init__(self, session, host, port, password, use_ssl=False, verify_ssl=False):
if not use_ssl:
verify_ssl = False
self._rh = _RequestsHandler(session, host, port, use_ssl=use_ssl,
verify_ssl=verify_ssl)
self._password = password
self._deviceInfo = None
self._settings = None
Expand Down Expand Up @@ -119,26 +122,30 @@ async def rebootDevice(self):
class _RequestsHandler:
"""Internal class to create FullyKiosk requests"""

def __init__(self, session: aiohttp.ClientSession, host, port):
def __init__(self, session: aiohttp.ClientSession, host, port, use_ssl=False,
verify_ssl=False):
self.headers = {"Accept": "application/json"}

self.session = session
self.host = host
self.port = port
self.use_ssl = use_ssl
self.verify_ssl = verify_ssl

async def get(self, **kwargs):
url = f"http://{self.host}:{self.port}"
url = f"http{'s' if self.use_ssl else ''}://{self.host}:{self.port}"
params = []

for key, value in kwargs.items():
if value is not None:
params.append((key, str(value)))
req_params = {"url": url, "headers": self.headers, "params": params}
if not self.verify_ssl:
req_params["ssl"] = False

_LOGGER.debug("Sending request to: %s", url)
_LOGGER.debug("Parameters: %s", params)
async with self.session.get(
url, headers=self.headers, params=params
) as response:
async with self.session.get(**req_params) as response:
if response.status != 200:
_LOGGER.warning(
"Invalid response from Fully Kiosk Browser API: %s", response.status
Expand Down

0 comments on commit fddd27f

Please sign in to comment.