wo4h"ddlZddlZddlmZddlmZddlmZddlm Z dZ Gdd e Z Gd d e Z Gd d ZGddeZGddeZGddeZeje fzZeejfdZdZdS)N)Any)UserType)Scope)RpcError __rpc_commandceZdZdS)DuplicateHandlerErrorN__name__ __module__ __qualname__U/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/rpc_tools/lookup.pyr r Drr ceZdZdS)NotCoroutineErrorNr rrrrrrrrceZdZdZejZeZe j ie j iiZ gZ fdZedZdZee j fdefdZed dZed ZxZS) Endpointsz\Endpoints class implements registration and lookup for functions implementing RPC calls.c ntjdi||j|dS)Nr)super__init_subclass__ _subclassesappend)clskwargs __class__s rrzEndpoints.__init_subclass__!s<!!++F+++ s#####rcxg}|jD]/}tj|d}|r||0|S)Nc.t|tdSN)getattr _RPC_MARK)items rz0Endpoints.get_active_endpoints..+sWT9d%C%Cr)rinspect getmembersr)ractive_endpointssubcls rpc_handlerss rget_active_endpointszEndpoints.get_active_endpoints%s[o 0 0F"-CCL 0 ''///rc||_dSr!)_sink)selfsinks r__init__zEndpoints.__init__1s  rreturnc.K|d}t|}||j|vr+tdd|dz|j||\}}t |||}|di|dd{VS)a:Find appropriate class and function within that class that implements processing for request based on supplied 'command' within. Call that (async) function and return its result. If target class/function for given request['command'] is not found then RpcError exception is raised.commandz&Endpoint not found for RPC method "%s" paramsNr)tuple_Endpoints__COMMAND_MAPrjoinr") rrequestr/userr3key cls_handler handler_namehandlers rroute_to_endpointzEndpoints.route_to_endpoint4s)$Gnn c'- - -8((79-../ %($5d$;C$@! \++d++\::W11wx0111111111rNct|D]}|drt||}t|td}|At j|st d|jD][}||j|vr8d |||j|||}t|||f|j||<\dS)z{Registers RPC handlers for all functions within a class. Functions should be decorated with @bind('command', ...)._NzMust be a coroutinez1Duplicate handlers for command {} ({}): {} and {}) dir startswithr"r#r&iscoroutinefunctionrAPPLICABLE_USER_TYPESr7formatr )rnameattrr3 user_typemsgs rregister_rpc_handlerszEndpoints.register_rpc_handlersHs HH D DDs## 3%%DdIt44G.t44 ?'(=>>> 6 D D c/ :::K#%-i8A 04449rrWc"eZdZdZejhZdS) RootEndpointsz'Endpoints available only for root user.N)r r rrPrrNrErrrrYrYqs 11%]OrrYc"eZdZdZejhZdS)UserOnlyEndpointsz,Endpoints available only for non root users.N)r r rrPrrMrErrrr[r[ws"66%./rr[cFtjtj|||S)z4Decorator replacing functools.wraps for rpc handlerswrappedassignedupdated) functoolspartialupdate_wrapperr]s rwrapsrds-       rcfd}|S)z4Mark a function as processing RPC calls for command.c4t|t|Sr!)setattrr#)funcr3s r decoratorzbind..decoratorsi))) rr)r3ris` rbindrjs$ r)rar&typingr defence360agent.contracts.configrdefence360agent.utilsr exceptionsrr# Exceptionr rrrWrYr[WRAPPER_ASSIGNMENTSLOOKUP_ASSIGNMENTSWRAPPER_UPDATESrdrjrrrrss555555''''''       I           S.S.S.S.S.S.S.S.l?????i??? ,,,,,I,,, 00000 000 2i\A))2K    r