def Handle(self, args, token=None): ValidateVfsPath(args.file_path) aff4_path = args.client_id.ToClientURN().Add(args.file_path) fd = aff4.FACTORY.Open(aff4_path, token=token) if args.max_depth == 1: flow_args = filesystem.ListDirectoryArgs(pathspec=fd.real_pathspec) flow_urn = flow.StartFlow( client_id=args.client_id.ToClientURN(), flow_name=filesystem.ListDirectory.__name__, args=flow_args, notify_to_user=args.notify_user, token=token) else: flow_args = filesystem.RecursiveListDirectoryArgs( pathspec=fd.real_pathspec, max_depth=args.max_depth) flow_urn = flow.StartFlow( client_id=args.client_id.ToClientURN(), flow_name=filesystem.RecursiveListDirectory.__name__, args=flow_args, notify_to_user=args.notify_user, token=token) return ApiCreateVfsRefreshOperationResult(operation_id=str(flow_urn))
def CreateRecursiveListFlow(self, client_id): flow_args = filesystem.RecursiveListDirectoryArgs() return flow.StartFlow( client_id=client_id, flow_cls=filesystem.RecursiveListDirectory, flow_args=flow_args)
def CreateRecursiveListFlow(self, client_id, token): flow_args = filesystem.RecursiveListDirectoryArgs() return flow.StartAFF4Flow( client_id=client_id, flow_name=filesystem.RecursiveListDirectory.__name__, args=flow_args, token=token)
def Run(self): acl_test_lib.CreateUser(self.test_username) client_id = self.SetupClient(0) # Create a running mock refresh operation. flow_args = filesystem.RecursiveListDirectoryArgs() running_flow_id = flow_test_lib.StartFlow( filesystem.RecursiveListDirectory, client_id, flow_args=flow_args, creator=self.test_username) # Create a mock refresh operation and complete it. finished_flow_id = flow_test_lib.StartFlow( filesystem.RecursiveListDirectory, client_id, flow_args=flow_args, creator=self.test_username) # Kill flow. rdf_flow = data_store.REL_DB.LeaseFlowForProcessing( client_id, finished_flow_id, rdfvalue.Duration.From(5, rdfvalue.MINUTES)) flow_cls = registry.FlowRegistry.FlowClassByName(rdf_flow.flow_class_name) flow_obj = flow_cls(rdf_flow) flow_obj.Error("Fake error") data_store.REL_DB.ReleaseProcessedFlow(rdf_flow) # Create an arbitrary flow to check on 404s. non_refresh_flow_id = flow_test_lib.StartFlow( discovery.Interrogate, client_id, creator=self.test_username) # Unknown flow ids should also cause 404s. unknown_flow_id = "12345678" # Check both operations. self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=running_flow_id), replace={running_flow_id: "ABCDEF"}) self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=finished_flow_id), replace={finished_flow_id: "ABCDEF"}) self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=non_refresh_flow_id), replace={non_refresh_flow_id: "ABCDEF"}) self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=unknown_flow_id), replace={unknown_flow_id: "ABCDEF"})
def CreateRecursiveListFlow(self, client_id, token): flow_args = filesystem.RecursiveListDirectoryArgs() if data_store.RelationalDBFlowsEnabled(): return flow.StartFlow( client_id=client_id.Basename(), flow_cls=filesystem.RecursiveListDirectory, flow_args=flow_args) else: return flow.StartAFF4Flow( client_id=client_id, flow_name=filesystem.RecursiveListDirectory.__name__, args=flow_args, token=token).Basename()
def Run(self): acl_test_lib.CreateUser(self.token.username) client_id = self.SetupClient(0).Basename() # Create a running mock refresh operation. flow_args = filesystem.RecursiveListDirectoryArgs() running_flow_id = api_regression_test_lib.StartFlow( client_id, filesystem.RecursiveListDirectory, flow_args=flow_args, token=self.token) # Create a mock refresh operation and complete it. finished_flow_id = api_regression_test_lib.StartFlow( client_id, filesystem.RecursiveListDirectory, flow_args=flow_args, token=self.token) self._KillFlow(client_id, finished_flow_id) # Create an arbitrary flow to check on 404s. non_refresh_flow_id = api_regression_test_lib.StartFlow( client_id, discovery.Interrogate, token=self.token) # Unkonwn flow ids should also cause 404s. unknown_flow_id = "F:12345678" # Check both operations. self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=running_flow_id), replace={running_flow_id: "W:ABCDEF"}) self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=finished_flow_id), replace={finished_flow_id: "W:ABCDEF"}) self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=non_refresh_flow_id), replace={non_refresh_flow_id: "W:ABCDEF"}) self.Check( "GetVfsRefreshOperationState", args=vfs_plugin.ApiGetVfsRefreshOperationStateArgs( client_id=client_id, operation_id=unknown_flow_id), replace={unknown_flow_id: "W:ABCDEF"})
def Handle(self, args, token=None): if args.max_depth == 1: flow_args = filesystem.ListDirectoryArgs( pathspec=self._FindPathspec(args)) flow_cls = filesystem.ListDirectory else: flow_args = filesystem.RecursiveListDirectoryArgs( pathspec=self._FindPathspec(args), max_depth=args.max_depth) flow_cls = filesystem.RecursiveListDirectory flow_id = flow.StartFlow(client_id=str(args.client_id), flow_cls=flow_cls, flow_args=flow_args, creator=token.username if token else None) return ApiCreateVfsRefreshOperationResult(operation_id=flow_id)