HQ Request Handler
Specific abilities
self.request_as_obj - HQ communicates with Caliper via SOAP, which is an XML format. This variable turns that XML body into an object which you can parse with dot notation (ex. self.request_as_obj.nodename.child_nodes[2])
Q2_OnFinish
We expose a q2_on_finish
function that is called after q2_post
. This is
useful if you want to respond to the user quickly, but continue to work in the
background after the HTTP request is completed. To take advantage of this, simply add this
to your extension:
async def q2_on_finish(self):
# Do extra work
- class q2_sdk.core.http_handlers.hq_handler.Q2HqRequestHandler(application, request, **kwargs)[source]
Bases:
Q2BaseRequestHandler
RequestHandler meant to be used for requests incoming from HQ.
Parses apart XML posts into inspectable objects using lxml
Puts form fields into a dictionary
If WEDGE_ADDRESS_CONFIGS is set, ensures the entries are set in the database on installation of the extension.
WEDGE_ADDRESS_CONFIGS is an instance of DbConfigList filled with DbConfig objects.
hq_response_attrs is a dict that will be appended as attributes to the Data node HQ is expecting
- async get_user_dob()[source]
Date of Birth is sometimes populated in the Q2 database, but rarely passed in the initial payload from HQ. Calling self.get_user_dob() will efficiently look it up if it exists. After that, self.online_user.dob will have it stored.
- async get_wedge_address_configs(force=False)[source]
Gather wedge_address_configs either from incoming data or from database Has the side effect of seeding data for subsequent self.db_config calls
- Parameters:
force – If True, will query the database even if self.WEDGE_ADDRESS_CONFIGS is blank
- Return type:
dict
- static get_dc_cookie()[source]
Q2’s production environments run in two data centers. New sessions (in production) are distributed evenly across those two data centers. In order to make sure the Ardent API calls return to the same data center that this token was generated in, we need to pass a cookie on the Ardent API requests. To do that we will inspect an environment variable and generate the cookie string accordingly.
- property session_cache: Q2CacheClient[source]
Same as self.cache but limited to online user session
- property stack_cache: Q2CacheClient[source]
Q2CacheClient scoped to the current financial institution stack.
- property wedge_address_configs: dict
Alias to self.db_config
- property db_config: dict
Dictionary representation of data passed from the Q2_WedgeAddress table’s Config column
- async post(*args, **kwargs)[source]
Parses apart POST data based on content-type and format, creates a few handy objects, then farms out the work to the extension specific function defined in
q2_post
- async q2_post(*args, **kwargs)[source]
Overridable method. Should be defined in the extension inheriting this class. Called from the housekeeping Q2 specific POST method after the incoming message is parsed and broken into objects
- async q2_on_finish()[source]
Called after the end of
q2_post
.This will not send data back to the end user, but is meant for background processing after the http connection has been closed.
This will NOT be called if the response is a 500
- Return type:
None
- wrap_soap_response(custom_response)[source]
If the incoming request is wrapped in a soap envelope, this prepares it for return back to HQ. There are two formats we know about, but since it is possible for HQ instances to be customized and expect a different format, this allows for overriding the response at an extension level.
- Parameters:
custom_response – Response to wrap in an appropriate soap envelope
- async download_file(input_name)[source]
Downloads file_key from AWS using the ardent.file_upload.File class
- Return type:
bytes
- set_hq_commands(hq_commands)[source]
HQ has the ability to reload accounts from the DB/Core or skip a disclaimer for the remainder of a session. To do so, call this method with a valid HqCommands instance.
Note: This does NOT immediately call HQ to do the operation, but rather will send the command to HQ along with the response shape from your route.
For instance:
async def default(self): #do stuff account_id = 12345 hq_commands_obj = HqCommands( HqCommands.AccountReloadType.FROM_HOST, [account_id], ) self.set_hq_commands(hq_commands_obj) # Nothing happens here html = self.get_template('template_name.html', {}) return html # This is where the magic happens