Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cerbapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import ssl
from hashlib import md5
from email.utils import formatdate
from urllib.request import Request, urlopen
Expand All @@ -13,10 +14,11 @@ class CerbException(Exception):

class Cerb(object):

def __init__(self, access_key, secret, base='https://localhost/index.php/rest/'):
def __init__(self, access_key, secret, base='https://localhost/index.php/rest/', secure=True):
self._access_key = access_key
self._secret = md5(secret.encode()).hexdigest()
self._base = base
self._secure = secure

# Test the connection and set values for version and build
test = self.get_contexts()
Expand All @@ -41,7 +43,12 @@ def send(self, verb, endpoint, payload=None, params=None):
verb, date, urlparse(url).path, query, data, self._secret, '']).encode()).hexdigest()
}

with urlopen(r) as f:
context = ssl.create_default_context()
if (not self._secure):
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

with urlopen(r, context=context) as f:

response = json.loads(f.read().decode())

Expand Down