|
|
@ -33,13 +33,14 @@ from .exceptions import KeycloakConnectionError |
|
|
|
|
|
|
|
|
|
|
|
class ConnectionManager(object): |
|
|
|
"""Represents a simple server connection. |
|
|
|
Args: |
|
|
|
base_url (str): The server URL. |
|
|
|
headers (dict): The header parameters of the requests to the server. |
|
|
|
timeout (int): Timeout to use for requests to the server. |
|
|
|
verify (bool): Verify server SSL. |
|
|
|
proxies (dict): The proxies servers requests is sent by. |
|
|
|
""" |
|
|
|
Represents a simple server connection. |
|
|
|
|
|
|
|
:param base_url: (str) The server URL. |
|
|
|
:param headers: (dict) The header parameters of the requests to the server. |
|
|
|
:param timeout: (int) Timeout to use for requests to the server. |
|
|
|
:param verify: (bool) Verify server SSL. |
|
|
|
:param proxies: (dict) The proxies servers requests is sent by. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, base_url, headers={}, timeout=60, verify=True, proxies=None): |
|
|
@ -108,11 +109,11 @@ class ConnectionManager(object): |
|
|
|
self._headers = value |
|
|
|
|
|
|
|
def param_headers(self, key): |
|
|
|
"""Return a specific header parameter. |
|
|
|
:arg |
|
|
|
key (str): Header parameters key. |
|
|
|
:return: |
|
|
|
If the header parameters exist, return its value. |
|
|
|
""" |
|
|
|
Return a specific header parameter. |
|
|
|
|
|
|
|
:param key: (str) Header parameters key. |
|
|
|
:returns: If the header parameters exist, return its value. |
|
|
|
""" |
|
|
|
return self.headers.get(key) |
|
|
|
|
|
|
@ -122,36 +123,33 @@ class ConnectionManager(object): |
|
|
|
|
|
|
|
def exist_param_headers(self, key): |
|
|
|
"""Check if the parameter exists in the header. |
|
|
|
:arg |
|
|
|
key (str): Header parameters key. |
|
|
|
:return: |
|
|
|
If the header parameters exist, return True. |
|
|
|
|
|
|
|
:param key: (str) Header parameters key. |
|
|
|
:returns: If the header parameters exist, return True. |
|
|
|
""" |
|
|
|
return self.param_headers(key) is not None |
|
|
|
|
|
|
|
def add_param_headers(self, key, value): |
|
|
|
"""Add a single parameter inside the header. |
|
|
|
:arg |
|
|
|
key (str): Header parameters key. |
|
|
|
value (str): Value to be added. |
|
|
|
|
|
|
|
:param key: (str) Header parameters key. |
|
|
|
:param value: (str) Value to be added. |
|
|
|
""" |
|
|
|
self.headers[key] = value |
|
|
|
|
|
|
|
def del_param_headers(self, key): |
|
|
|
"""Remove a specific parameter. |
|
|
|
:arg |
|
|
|
key (str): Key of the header parameters. |
|
|
|
|
|
|
|
:param key: (str) Key of the header parameters. |
|
|
|
""" |
|
|
|
self.headers.pop(key, None) |
|
|
|
|
|
|
|
def raw_get(self, path, **kwargs): |
|
|
|
"""Submit get request to the path. |
|
|
|
:arg |
|
|
|
path (str): Path for request. |
|
|
|
:return |
|
|
|
Response the request. |
|
|
|
:exception |
|
|
|
HttpError: Can't connect to server. |
|
|
|
|
|
|
|
:param path: (str) Path for request. |
|
|
|
:returns: Response the request. |
|
|
|
:raises: HttpError Can't connect to server. |
|
|
|
""" |
|
|
|
|
|
|
|
try: |
|
|
@ -167,13 +165,11 @@ class ConnectionManager(object): |
|
|
|
|
|
|
|
def raw_post(self, path, data, **kwargs): |
|
|
|
"""Submit post request to the path. |
|
|
|
:arg |
|
|
|
path (str): Path for request. |
|
|
|
data (dict): Payload for request. |
|
|
|
:return |
|
|
|
Response the request. |
|
|
|
:exception |
|
|
|
HttpError: Can't connect to server. |
|
|
|
|
|
|
|
:param path: (str) Path for request. |
|
|
|
:param data: (dict) Payload for request. |
|
|
|
:returns: Response the request. |
|
|
|
:raises: HttpError Can't connect to server. |
|
|
|
""" |
|
|
|
try: |
|
|
|
return self._s.post( |
|
|
@ -189,13 +185,11 @@ class ConnectionManager(object): |
|
|
|
|
|
|
|
def raw_put(self, path, data, **kwargs): |
|
|
|
"""Submit put request to the path. |
|
|
|
:arg |
|
|
|
path (str): Path for request. |
|
|
|
data (dict): Payload for request. |
|
|
|
:return |
|
|
|
Response the request. |
|
|
|
:exception |
|
|
|
HttpError: Can't connect to server. |
|
|
|
|
|
|
|
:param path: (str) Path for request. |
|
|
|
:param data: (dict) Payload for request. |
|
|
|
:returns: Response the request. |
|
|
|
:raises: HttpError Can't connect to server. |
|
|
|
""" |
|
|
|
try: |
|
|
|
return self._s.put( |
|
|
@ -212,13 +206,10 @@ class ConnectionManager(object): |
|
|
|
def raw_delete(self, path, data={}, **kwargs): |
|
|
|
"""Submit delete request to the path. |
|
|
|
|
|
|
|
:arg |
|
|
|
path (str): Path for request. |
|
|
|
data (dict): Payload for request. |
|
|
|
:return |
|
|
|
Response the request. |
|
|
|
:exception |
|
|
|
HttpError: Can't connect to server. |
|
|
|
:param path: (str) Path for request. |
|
|
|
:param data: (dict) Payload for request. |
|
|
|
:returns: Response the request. |
|
|
|
:raises: HttpError Can't connect to server. |
|
|
|
""" |
|
|
|
try: |
|
|
|
return self._s.delete( |
|
|
|