HttpHelper

class cloudpassage.HttpHelper(connection)

This class handles communication with the CloudPassage API.

When instantiating this class, pass in a cloudpassage.HaloSession object (referred to here as connection, as it defines connection parameters for interacting with the API).

delete(endpoint, **kwargs)

This method performs a Delete against Halo’s API.

It will attempt to authenticate using the credentials (required to instantiate the object) if the session has either:

  1. Not been authenticated yet
  2. OAuth Token has expired

This is a primary method, meaning it reaches out directly to the Halo API, and should only be utilized by secondary methods with a more specific purpose, like gathering events from /v1/events. If you’re using this method because the SDK doesn’t provide a more specific method, please reach out to toolbox@cloudpassage.com so we can get an enhancement request in place for you.

Parameters:endpoint (str) – Path component of URL
get(endpoint, **kwargs)

This method performs a GET against Halo’s API.

It will attempt to authenticate using the credentials (required to instantiate the object) if the session has either: 1) Not been authenticated yet 2) OAuth Token has expired

This is a primary method, meaning it reaches out directly to the Halo API, and should only be utilized by secondary methods with a more specific purpose, like gathering events from /v1/events. If you’re using this method because the SDK doesn’t provide a more specific method, please reach out to toolbox@cloudpassage.com so we can get an enhancement request in place for you.

Parameters:endpoint (str) – URL- everything between api.cloudpassage.com and any parameters to be passed. Example: /v1/events
Keyword Arguments:
 params (dict) – This is a dictionary object, represented like this: {“k1”: “two,too”} which goes into the URL looking like this: ?k1=two,too. If you use a list as the value in a dictionary here, you’ll get two k/v pairs represented in the URL and the CloudPassage API doesn’t operate like that. Only the last instance of that variable will be considered, and your results may be confusing. So don’t do it. Dictionaries should be {str:str}.
get_paginated(endpoint, key, max_pages, **kwargs)

This method returns a concatenated list of objects from the Halo API.

It’s really a wrapper for the get() method. Pass in the path as with the get() method, and a maxpages number. Maxpages is expected to be an integer between 2 and 100

Parameters:
  • endpoint (str) – Path for initial query
  • key (str) – The key in the response containing the objects of interest. For instance, the /v1/events endpoint will have the “events” key, which contains a list of dictionary objects representing Halo events.
  • maxpages (int) – This is a number from 2-100. More than 100 pages can take quite a while to return, so beyond that you should consider using this SDK as a component in a multi-threaded tool.
Keyword Arguments:
 

params (dict) – This is a dictionary object, represented like this: {“k1”: “two,too”} which goes into the URL looking like this: ?k1=two,too . If you use a list as the value in a dictionary here, you’ll get two k/v pairs represented in the URL and the CloudPassage API doesn’t operate like that. Only the last instance of that variable will be considered, and your results may be confusing. So don’t do it. Dictionaries should be {str:str}.

post(endpoint, reqbody)

This method performs a POST against Halo’s API.

As with the GET method, it will attempt to (re)authenticate the session if the key is expired or has not yet been retrieved.

Also like the GET method, it is not intended for direct use (though we won’t stop you). If you need something that the SDK doesn’t already provide, please reach out to toolbox@cloudpassage.com and let us get an enhancement request submitted for you.

Parameters:
  • endpoint (str) – path component of URL
  • reqbody (dict) – Dictionary to be converted to JSON for insertion as payload for request.
classmethod process_page(page, key)

Page goes in, list data comes out.

put(endpoint, reqbody)

This method performs a PUT against Halo’s API.

As with the GET method, it will attempt to (re)authenticate the session if the key is expired or has not yet been retrieved.

Also like the GET method, it is not intended for direct use (though we won’t stop you). If you need something that the SDK doesn’t already provide, please reach out to toolbox@cloudpassage.com and let us get an enhancement request submitted for you.

Parameters:
  • endpoint (str) – Path component of URL
  • reqbody (dict) – Dictionary to be converted to JSON for insertion as payload for request.