def build_grpc_response(request_id, response): if response[CDS_IS_SUCCESSFUL_KEY]: status = CommandExecutor_pb2.SUCCESS else: status = CommandExecutor_pb2.FAILURE response.pop(CDS_IS_SUCCESSFUL_KEY) logs = response.pop(RESULTS_LOG_KEY) errorMessage = "" if ERR_MSG_KEY in response: errorMessage = '\n'.join(response.pop(ERR_MSG_KEY)) # Payload should only contain response data returned from the executed script and/or the error message payload = json.dumps(response) timestamp = Timestamp() timestamp.GetCurrentTime() execution_output = CommandExecutor_pb2.ExecutionOutput(requestId=request_id, response=logs, status=status, payload=payload, timestamp=timestamp, errMsg=errorMessage) return truncate_execution_output(execution_output)
def build_grpc_blueprint_upload_response(request_id, subrequest_id, success=True, payload=[]): timestamp = Timestamp() timestamp.GetCurrentTime() return CommandExecutor_pb2.UploadBlueprintOutput(requestId=request_id, subRequestId=subrequest_id, status=CommandExecutor_pb2.SUCCESS if success else CommandExecutor_pb2.FAILURE, timestamp=timestamp, payload=json.dumps(payload))
def build_grpc_blueprint_validation_response(request_id, subrequest_id, cba_uuid, success=True): timestamp = Timestamp() timestamp.GetCurrentTime() return CommandExecutor_pb2.BlueprintValidationOutput(requestId=request_id, subRequestId=subrequest_id, status=CommandExecutor_pb2.SUCCESS if success else CommandExecutor_pb2.FAILURE, cbaUUID=cba_uuid, timestamp=timestamp)
def build_response(request, results, is_success=True): if is_success: status = CommandExecutor_pb2.SUCCESS else: status = CommandExecutor_pb2.FAILURE timestamp = Timestamp() timestamp.GetCurrentTime() return CommandExecutor_pb2.ExecutionOutput(requestId=request.requestId, response=results, status=status, timestamp=timestamp)
def build_response(request, log_results, payload_return, is_success=False): if is_success: status = CommandExecutor_pb2.SUCCESS else: status = CommandExecutor_pb2.FAILURE timestamp = Timestamp() timestamp.GetCurrentTime() if 'cds_return_code' in payload_return: payload_return.pop('cds_return_code') payload_str = json.dumps(payload_return) return CommandExecutor_pb2.ExecutionOutput(requestId=request.requestId, response=log_results, status=status, payload=payload_str, timestamp=timestamp)