10.8.4.1. Rest Result

class pytan3.results.Rest(api_objects, response_body, request_body, method, url, status_code, origin=None, lvl='info')[source]

Bases: pytan3.results.CommonMixin, pytan3.results.Result

Deserialize REST API responses from Tanium API.

MANUAL_OBJECT_ROUTES = {'audit_logs': 'audit_logs', 'parse_question': 'parse_question_results'}

dict – Manual route defs for object_api().

DATA_ROUTES = {'merged_result_data': 'merged_result_set', 'result_data': 'result_sets', 'result_info': 'result_infos'}

dict – Manual route defs for data_api().

__call__(raw=False, **kwargs)[source]

Get data_api or object_api.

Parameters:
  • raw (bool, optional) –

    Return the serialized object instead of the object deserialized into an ApiModel.

    Defaults to: False.

  • **kwargs
    rest of kwargs:
    passed to object_api() or data_api().

Notes

Will return object_api() or data_api() by determining if RestUrlPath.route is an object or data request.

Returns:pytan3.api_models.ApiModel or object
error_map

Map of status codes to regex patterns and exceptions.

Notes

Keys should be int of a status code to check patterns of.

Values should be list of [pattern, exc], where pattern is a regex pattern to search response body, and exc is exception to throw if pattern match is found.

Raises:
Returns:

dict

error_check()[source]

Check for errors in CommonMixin.response_body_str.

Raises:
error_check_response()[source]

Check CommonMixin.response_body_str for errors.

Notes

For each key value pair in error_map, if key matches CommonMixin.status_code or key is None, the patterns in value are checked against response body, and if matched the patterns associated exception is thrown.

error_check_code()[source]

Check if CommonMixin.status_code is one of valid_codes.

Raises:exceptions.ResponseError
valid_codes

List of valid status codes.

Returns:list of int
error_text

Get the error text from CommonMixin.response_body_str.

Returns:str
url_path

Parse CommonMixin.url using RestUrlPath.

Returns:(RestUrlPath)
request_body_obj

Deserialize CommonMixin.request_body_str into a python object.

Returns:dict
request_object_obj

Get the request objects from request_body_obj.

Returns:dict
response_body_obj

Get CommonMixin.response_body_str deserialized into a python object.

Returns:dict
data_obj

Get the response data from response_body_obj.

Returns:dict
data_api(**kwargs)[source]

Get data_obj deserialized into an ApiModel object.

Parameters:**kwargs
rest of kwargs:
passed to CommonMixin.obj_to_api()
Returns:pytan3.api_models.ApiModel
object_obj

Get the response objects from response_body_obj.

Returns:dict
object_api(**kwargs)[source]

Get object_obj deserialized into an ApiModel object.

Parameters:**kwargs
rest of kwargs:
passed to CommonMixin.obj_to_api()
Returns:pytan3.api_models.ApiModel
str_to_obj(text, src, **kwargs)[source]

Deserialize string into a python object.

Parameters:
  • text (str) – String to decode into python object
  • src (str) – Where text came from, used in error text.
  • **kwargs
    rest of kwargs:
    Passed to json.loads().
Raises:

exceptions.TextDeserializeError – If an exception is thrown from json.loads().

Returns:

object

_abc_impl = <_abc_data object>