class cloudpassage.HaloSession(apikey, apisecret, **kwargs)

Create a Halo API connection object.

On instantiation, it will attempt to authenticate against the Halo API using the apikey and apisecret provided, together with any overrides passed in through kwargs.

  • apikey (str) – API key, retrieved from your CloudPassage Halo account
  • apisecret (str) – API key secret, found with your API key in your CloudPassage Halo account
Keyword Arguments:
  • api_host (str) – Override the API endpoint hostname. Defaults to api.cloudpassage.com.
  • api_port (str) – Override the API HTTPS port. Defaults to 443.
  • proxy_host (str) – Hostname or IP address of proxy
  • proxy_port (str) – Port for proxy. Ignored if proxy_host is not set
  • user_agent (str) – Override for UserAgent string. We set this so that we can see what tools are being used in the field and set our development focus accordingly. To override the default, feel free to pass this kwarg in.
  • integration_string (str) – If set, this will cause the user agent string to include an identifier for the integration being used.

This method attempts to set an OAuth token

Call this method and it will use the API key and secret as well as the proxy settings (if used) to authenticate this HaloSession instance.


Build client object for class instantiation.


This constructs everything to the left of the file path in the URL.


This constructs the auth header, required for all API interaction.

classmethod build_proxy_struct(host, port)

Return a structure describing the environment’s HTTP proxy settings.

It returns a dictionary object that can be passed to the requests module.

get_auth_token(endpoint, headers)

Returns the oauth token and scope.

  • endpoint (str) – Full URL, including schema.
  • headers (dict) – Dictionary, containing header with encoded credentials. Example: {“Authorization”: str(“Basic ” + encoded)}

token, scope

Return type:


get_response(client_method, verb, url, params, reqbody)

Base method for getting response from Halo API.

  • client_method (requests.Session() – This method is what performs the actual interaction with the Halo API. Example: self.connection.client.get
  • verb (str) – The HTTP verb used in interacting with the Halo API.
  • url (str) – Complete URL for request.
  • params (list) – URL params in a list of dictionaries.
  • reqbody (dict) – Body of put/post request

success (bool) response (requests.response) exception (Exception)

interact(verb, endpoint, params=None, reqbody=None)

This method allows us to wrap common Halo interaction functionality.

Most exceptions will be caught and validated here, and if retries fail, those exceptions will be raised again for catching at a higher level.

  • verb (str) – get, post, put, or delete.
  • endpoint (str) – URL- everything past api.cloudpassage.com.
  • params (list of dict) – This is a list of dictionary objects, represented like this: [{“k1”: “two,too”}]
  • reqbody (dict) – Dictionary to be converted to JSON for insertion as payload for request.

response object

try_wrapper(verb, url, params, reqbody)

Wraps tries.

  • endpoint (str) – Path part of URL.
  • params (list of dict) – URL params.
  • reqbody (dict) – Request body.

success (bool) response (requests.response) exception (Exception)