def send_command(command_id: str, user_name: str, command_to_check: str, host: str = LOCALHOST, port: int = DEFAULT_PORT) -> Action: StateDTO.update_forward_refs() command_to_execute = StateDTO(command_id=command_id, user_name=user_name, command=command_to_check) clai_client = ClaiClient(host=host, port=port) return clai_client.send(command_to_execute)
def serialize_message(data) -> State: StateDTO.update_forward_refs() dto = StateDTO(**json.loads(data)) return State(command_id=dto.command_id, user_name=dto.user_name, command=dto.command, root=dto.root, processes=dto.processes, file_changes=dto.file_changes, network=dto.network, result_code=dto.result_code, stderr=dto.stderr)
def send_files(command_id: str, user_name: str, files_values: FilesChangesValues): file_state = StateDTO(command_id=command_id, user_name=user_name, file_changes=files_values) clai_client = ClaiClient() clai_client.send(file_state)
def write(self, message: StateDTO): events = self.sel.select(timeout=5) key = events[0][0] client_socket = key.fileobj data = key.data self.sel.modify(client_socket, selectors.EVENT_WRITE, data) logger.info(f'echoing ${data}') data.outb = str(message.json()) sent = client_socket.send(data.outb.encode('utf-8')) data.outb = data.outb[sent:] self.sel.modify(client_socket, selectors.EVENT_READ, data)
def send_command_post_execute(command_id: str, user_name: str, result_code: str, stderr: str, processes: ProcessesValues, host: str = LOCALHOST, port: int = DEFAULT_PORT) -> Action: post_execute_state = StateDTO(command_id=command_id, user_name=user_name, result_code=result_code, stderr=stderr, processes=processes) clai_client = ClaiClient(host=host, port=port) return clai_client.send(post_execute_state)
user_name=user_name, command=command_to_check) clai_client = ClaiClient(host=host, port=port) return clai_client.send(command_to_execute) if __name__ == '__main__': if len(sys.argv) < 3: print("usage:", sys.argv[0], "<host> <port> <websocket>") sys.exit(1) # pylint: disable=unbalanced-tuple-unpacking HOST, PORT = sys.argv[1:3] WEBSOCKET = False if sys.argv[3]: WEBSOCKET = sys.argv[3] == "websocket" INPUT_VALUE = input('$') print(HOST, PORT, WEBSOCKET) if WEBSOCKET: CLAI_CLIENT = ClaiClient(connector=WebSocketClientConnector(host=HOST)) else: CLAI_CLIENT = ClaiClient( connector=SocketClientConnector(host=HOST, port=PORT)) VALUE = CLAI_CLIENT.send( StateDTO(command_id='4', user_name="user", command=INPUT_VALUE)) print(f"VALUE: {VALUE}") print(f"suggested command: {VALUE.suggested_command}") print(f"suggested description: {VALUE.description}")
async def __send_message(self, message: StateDTO): async with websockets.connect(self.host) as websocket: await websocket.send(str(message.json())) received_data = await websocket.recv() return process_message(received_data)
def send_command(command_id: str, user_name: str, command_to_check: str, host: str = LOCALHOST, port: int = DEFAULT_PORT) -> Action: StateDTO.update_forward_refs() command_to_execute = StateDTO(command_id=command_id, user_name=user_name, command=command_to_check) clai_client = ClaiClient(host=host, port=port) return clai_client.send(command_to_execute) if __name__ == '__main__': if len(sys.argv) < 3: print("usage:", sys.argv[0], "<host> <port> <websocket>") sys.exit(1) # pylint: disable=unbalanced-tuple-unpacking HOST, PORT = sys.argv[1:3] WEBSOCKET = False if sys.argv[3]: WEBSOCKET = sys.argv[3] == "websocket" INPUT_VALUE = input('$') print(HOST, PORT, WEBSOCKET) if WEBSOCKET: CLAI_CLIENT = ClaiClient(connector=WebSocketClientConnector(host=HOST)) else: CLAI_CLIENT = ClaiClient(connector=SocketClientConnector(host=HOST, port=PORT)) VALUE = CLAI_CLIENT.send(StateDTO(command_id='4', user_name="user", command=INPUT_VALUE)) print(f"VALUE: {VALUE}") print(f"suggested command: {VALUE.suggested_command}") print(f"suggested description: {VALUE.description}")