database.client.sapi_requests

Mixin class for databse client with SAPI request related functions

class accre.database.client.sapi_requests.DBClientSAPIRequestMixin[source]

Bases: object

Functionality related to SAPI requests

add_sapi_request(*, action, payload, requester, ticket=0, status='PENDING', stage=0, creation_time=None, modification_time=None)[source]

Create a new SAPI request with the specified attributes.

Parameters:
  • action (str) – The SAPI action name for the request, i.e. NEWUSER, ADDGROUP, REMOVEGROUP, etc..

  • payload (str) – String representing a valid JSON object with properties for the action, the contents of the JSON are action dependent.

  • requester (str) – The staff member or entity requesting the action.

  • ticket (int) – The RT ticket number associated with this action. If set to 0 (default), a ticket will be generated.

  • status (str) – The status code for the new request, defaults to pending

  • stage (int) – Action-dependent processing stage code, default 0

  • creation_time (datetime.datetime) – Time when this request was created, if set to None it will be the current time

  • modification_time (datetime.datetime) – Time of the last request modification, if set to None it will be the current time

Returns:

The SAPI request ID number of the new request

Return type:

int

all_sapi_requests_info(show_inactive=False, limit=None, offset=None)[source]

Retrieve general information for all SAPI requests, optionally those that are already resolved

Parameters:
  • show_inactive (bool) – Return all SAPI requests including those with status RESOLVED.

  • limit (int) – Maximum number of records to return, return all if None

  • offset (int) – Offset from first record to begin list of records, start at the first record if None

Returns:

General account information for all SAPI requests

Return type:

list(dict)

delete_sapi_request(srid)[source]

Remove the specified SAPI request from the database. Note that under normal circumstances a SAPI request should be marked RESOLVED but not deleted, only use this method to remove spurious SAPI requests generated by testing procedures or automated errors.

Parameters:

srid (int) – Numeric ID of the SAPI request

list_sapi_requests(show_inactive=False, include_payloads=False, ticket=None)[source]

Return a list of SAPI requests as dicts with the properties of each request. By default, inactive requests with the RESOLVED status are excluded and the json payload of each request is not included.

Parameters:
  • show_inactive (bool) – Return all SAPI requests including those with status RESOLVED.

  • include_payloads (bool) – Include the JSON payload data with each request.

  • ticket (int) – If not None, return only requests with the specified RT ticket id

Returns:

List of dicts containing properties of each request

Return type:

list(dict)

modify_sapi_request(srid, **updates)[source]

Modify one or more fields of an existing SAPI request and update the modification time.

Parameters:
  • srid (int) – Numeric ID of the SAPI request

  • updates (dict) – Columns to be updated with their values note that payload should be a json-compatible dict and will be stringified, and modification_time will be added if not present

sapi_request_info(srid)[source]

Return all information about a specified SAPI request identified by numeric ID.

Parameters:

srid (int) – Numeric ID of the SAPI Request

Returns:

All data for the specified SAPI Request

Return type:

dict