pydent.aqsession.AqHTTP

class pydent.aqsession.AqHTTP(login, password, aquarium_url)[source]

Bases: object

Defines a Python to Aquarium server connection. Makes HTTP requests to Aquarium and returns JSON.

This class should be obscured from Trident users so that they cannot make arbitrary requests to an Aquarium server and get sensitive information (e.g. User json that is returned contains api_key, password_digest, etc.) or make damaging posts. These requests should be made by a SessionInterface object instead.

Initializes an aquarium session with login, password, and server.

Parameters
  • login (str) – Aquarium login

  • aquarium_url (str) – aquarium url to the server

__init__(login, password, aquarium_url)[source]

Initializes an aquarium session with login, password, and server.

Parameters
  • login (str) – Aquarium login

  • aquarium_url (str) – aquarium url to the server

Methods

__init__(login, password, aquarium_url)

Initializes an aquarium session with login, password, and server.

create_session_json(login, password)

rtype

Dict

delete(path[, timeout])

rtype

dict

get(path[, timeout, allow_none])

Make a get request to the session.

off()

Turn off requests.

on()

Turn on requests.

post(path[, json_data, timeout, allow_none])

Make a post request to the session.

put(path[, json_data, timeout, allow_none])

Make a put request to the session.

request(method, path[, timeout, allow_none])

Performs a http request.

Attributes

TIMEOUT

url

An alias of aquarium_url.

static _disallow_null_in_json(json_data)[source]

Raises :class:pydent.exceptions.TridentJSONDataIncomplete exception if json data being sent contains a null value.

Raises

TridentJSONDataIncomplete: if json data containers a null or None value.

_login(login, password)[source]

Login to aquarium and saves header as a requests.Session()

Parameters
  • login (str) – Aquarium login

  • password (str) – Aquarium password

Returns

None

Raises

TridentLoginError: If Aquarium authentication fails or server could not be contacted TridentTimeoutError: If response time exceeds specified timeout

_requests_session = None

the requests session

_response_to_json(response)[source]

Turns requests.Request instance into a json.

Raises TridentRequestError if an error occurs.

Return type

dict

_using_requests = None

if False, any HTTP requests will throw and error

aquarium_url = None

the aquarium url

get(path, timeout=None, allow_none=True, **kwargs)[source]

Make a get request to the session.

Parameters
  • path (str) – url

  • timeout (int) – time in seconds to process request before raising exception

  • allow_none (boolean) – if False throw error when json_data contains a null or None value (default: True)

  • kwargs (dict) – additional arguments to post to request

Returns

json

Return type

dict

log = None

the logger

login = None

the user login name

num_requests = None

number of requests counter

off()[source]

Turn off requests. Will cause.

ForbiddenRequestError to be raised if a request is made.

Returns

None

on()[source]

Turn on requests. When requests are off, this causes.

ForbiddenRequestError to be raised if a request is made.

Returns

None

post(path, json_data=None, timeout=None, allow_none=True, **kwargs)[source]

Make a post request to the session.

Parameters
  • path (str) – url

  • json_data (dict) – json_data to post

  • timeout (int) – time in seconds to process request before raising exception

  • allow_none (boolean) – if False throw error if json_data contains a null or None value (default True)

  • kwargs (dict) – additional arguments to post to request

Returns

json

Return type

dict

put(path, json_data=None, timeout=None, allow_none=True, **kwargs)[source]

Make a put request to the session.

Parameters
  • path (str) – url

  • json_data (dict) – json_data to post

  • timeout (int) – time in seconds to process request before raising exception

  • allow_none (boolean) – if False throw error when json_data contains a null or None value (default True)

  • kwargs (dict) – additional arguments to post to request

Returns

json

Return type

dict

request(method, path, timeout=None, allow_none=True, **kwargs)[source]

Performs a http request.

Parameters
  • method (str) – request method (e.g. ‘put’, ‘post’, ‘get’, etc.)

  • path (str) – url to perform the request

  • timeout (int) – time in seconds to process request before raising exception

  • allow_none (boolean) – if False will raise error when json_data contains a None or null value (default: True)

  • kwargs (dict) – additional arguments to post to request

Returns

json

Return type

dict

timeout = None

the timeout (s) for requests

property url

An alias of aquarium_url.

Return type

str