11from castle .api_request import APIRequest
22from castle .commands .authenticate import CommandsAuthenticate
33from castle .commands .identify import CommandsIdentify
4- from castle .commands .impersonate import CommandsImpersonate
4+ from castle .commands .start_impersonation import CommandsStartImpersonation
5+ from castle .commands .end_impersonation import CommandsEndImpersonation
56from castle .commands .track import CommandsTrack
67from castle .configuration import configuration
78from castle .context .prepare import ContextPrepare
@@ -43,7 +44,7 @@ def _add_timestamp_if_necessary(self, options):
4344 def authenticate (self , options ):
4445 if self .tracked ():
4546 self ._add_timestamp_if_necessary (options )
46- command = CommandsAuthenticate (self .context ).build (options )
47+ command = CommandsAuthenticate (self .context ).call (options )
4748 try :
4849 response = self .api .call (command )
4950 response .update (failover = False , failover_reason = None )
@@ -61,11 +62,18 @@ def identify(self, options):
6162 if not self .tracked ():
6263 return None
6364 self ._add_timestamp_if_necessary (options )
64- return self .api .call (CommandsIdentify (self .context ).build (options ))
65+ return self .api .call (CommandsIdentify (self .context ).call (options ))
6566
66- def impersonate (self , options ):
67+ def start_impersonation (self , options ):
6768 self ._add_timestamp_if_necessary (options )
68- response = self .api .call (CommandsImpersonate (self .context ).build (options ))
69+ response = self .api .call (CommandsStartImpersonation (self .context ).call (options ))
70+ if not response .get ('success' ):
71+ raise ImpersonationFailed
72+ return response
73+
74+ def end_impersonation (self , options ):
75+ self ._add_timestamp_if_necessary (options )
76+ response = self .api .call (CommandsEndImpersonation (self .context ).call (options ))
6977 if not response .get ('success' ):
7078 raise ImpersonationFailed
7179 return response
@@ -74,7 +82,7 @@ def track(self, options):
7482 if not self .tracked ():
7583 return None
7684 self ._add_timestamp_if_necessary (options )
77- return self .api .call (CommandsTrack (self .context ).build (options ))
85+ return self .api .call (CommandsTrack (self .context ).call (options ))
7886
7987 def disable_tracking (self ):
8088 self .do_not_track = True
0 commit comments