Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
 
Answered
How to create a generic Audit callback?

I'm writing an extension that will listen to several AuditActions (possibly the 141 Audit Actions that are marked as IsRiskAction=true in the Q2_AuditAction table). All actions will invoke the same generic code.

From the tutorial, it seems I need to create 141 individual methods, one per AuditAction, but instead of doing that, I was thinking to override the method __getattr__ to return a reference to the generic method for any of the 141 audit actions I have registered in the AUDIT_ACTIONS list. This seems to be compatible with the implementation I see in Q2AuditActionRequestHandler. And seems to work ok:

async def generic_audit_handler(self):
		self.logger.info('Auditing action %s:', self.audit_details.audit_action)

def __getattr__(self, item):
		if item in self.AUDIT_ACTIONS:
				return self.generic_audit_handler
		return super().__getattr__(item)

Another way I thought of doing this was to invoke setattr(cls, audit_name, method_ref) for each of the 141 AuditActions (in a loop on AUDIT_ACTIONS), this would actually create the methods in the class, although the __getattr__ approach seems simpler.

Is there another, more proper, way to achieve this in Q2? Like a default action handler?

Thanks.

Votes Newest

Answers


Hello,

What a cool use case! When we designed the Audit Action Handler, it was not nearly as flexible as you are looking for here. This is a great idea, and we want to help you solve it, but before we propose an interim solution, we'd like to talk as a team and see if there's a more optimal way of organizing this on our side that saves you some work.

There's a few backend things to think through that aren't obvious from the outside perspective and we want to make sure we're following best practices there, too. We have added this to our agenda to talk through on Thursday (11/26). Will get back to you after that.

Hope this helps,
Trey Teter

Posted 2 years ago
Trey Teter
124 × 2 Administrator
118 Views
1 Answer
3 years ago
2 years ago