def work_order_receipt_update_retrieve(self, work_order_id, updater_id, update_index, id=None): """ Retrieving a Work Order Receipt Update """ if work_order_id is None or not is_hex(work_order_id): logging.error("Work order id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") if updater_id is None or not is_hex(updater_id): logging.error("Updater id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderReceiptUpdateRetrieve", "id": id, "params": { "workOrderId": work_order_id, "updaterId": updater_id, "updateIndex": update_index } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_submit(self, params, in_data, out_data=None, id=None): valid, err = self.__validate_parameters(params) if not valid: return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, err) valid, err = self.__validate_data_format(in_data) if not valid: return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, err) if out_data is not None: valid, err = self.__validate_data_format(out_data) if not valid: return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, err) json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderSubmit", "id": id } json_rpc_request["params"] = params json_rpc_request["params"]["inData"] = in_data if out_data is not None: json_rpc_request["outData"] = out_data logging.debug("Work order request %s", json.dumps(json_rpc_request)) response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_receipt_lookup_next(self, last_lookup_tag, worker_service_id=None, worker_id=None, requester_id=None, receipt_status=None, id=None): """ Work Order Receipt Lookup Next """ json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderReceiptLookUpNext", "id": id, "params": { "lastLookUpTag": last_lookup_tag } } if worker_service_id is not None: if not is_valid_hex_str(worker_service_id): logging.error("Worker service id is Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker service id is Invalid") json_rpc_request["params"]["workerServiceId"] = worker_service_id if worker_id is not None: if not is_valid_hex_str(worker_id): logging.error("Worker id is Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is Invalid") json_rpc_request["params"]["workerId"] = worker_id if requester_id is not None: if not is_valid_hex_str(requester_id): logging.error("Requester id is Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Requester id is Invalid") json_rpc_request["params"]["requesterId"] = requester_id if receipt_status is not None: if not isinstance(receipt_status, ReceiptCreateStatus): logging.error("Invalid receipt status") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid receipt status") json_rpc_request["params"]["receiptStatus"] = receipt_status if last_lookup_tag is None or not is_valid_hex_str(last_lookup_tag): logging.error("Last lookup tag is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Last lookup tag is empty or Invalid") response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_receipt_create(self, work_order_id, worker_id, worker_service_id, requester_id, receipt_create_status, work_order_request_hash, id=None): """ Creating a Work Order Receipt json rpc request and submit tcs listener """ if work_order_id is None or not is_valid_hex_str(work_order_id): logging.error("Work order id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") if worker_id is None or not is_valid_hex_str(worker_id): logging.error("Worker id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") if not isinstance(worker_type, ReceiptCreateStatus): logging.error("Invalid receipt create status") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid receipt create status") if worker_service_id is None or not is_valid_hex_str( worker_service_id): logging.error("Worker service id is empty or Invalid") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker service id is empty or Invalid") if requester_id is None or not is_valid_hex_str(requester_id): logging.error("requester id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "requester id is empty or Invalid") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderReceiptCreate", "id": id, "params": { "workOrderId": work_order_id, "workerId": worker_id, "workerServiceId": worker_service_id, "requesterId": requester_id, "receiptCreateStatus": receipt_create_status, "workOrderRequestHash": work_order_request_hash } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_receipt_update(self, work_order_id, updater_id, update_type, update_data, update_signature, signature_rules, id=None): """ Update a Work Order Receipt json rpc request and submit tcs listener """ if work_order_id is None or not is_valid_hex_str(work_order_id): logging.error("Work order id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") if updater_id is None or not is_valid_hex_str(updater_id): logging.error("Updater id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") if not isinstance(update_type, ReceiptCreateStatus): logging.error("Invalid Update type") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid update type") if update_data is None or not is_valid_hex_str(update_data): logging.error("Update data is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Update data is empty or Invalid") if update_signature is None or not is_valid_hex_str(update_signature): logging.error("update signature is empty or Invalid") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "update signature is empty or Invalid") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderReceiptUpdate", "id": id, "params": { "workOrderId": work_order_id, "updaterId": updater_id, "updateType": update_type, "updateData": update_data, "updateSignature": update_signature, "signatureRules": signature_rules } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def worker_register(self, worker_id, worker_type, org_id, application_type_ids, details, id=None): """ Adds worker details to registry """ if worker_id is None or not is_hex(worker_id): logging.error("Worker id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") if not isinstance(worker_type, WorkerType): logging.error("Invalid worker type") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid worker type") if org_id is not None and not is_hex(org_id): logging.error("Invalid organization id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid organization id") if application_type_ids is not None: for app_id in application_type_ids: if not is_hex(app_id): logging.error("Invalid application type id") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid application type id") break if details is not None: is_valid = validate_details(details) if is_valid is not None: logging.error(is_valid) return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, is_valid) json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerRegister", "id": id, "params": { "workerId": worker_id, "workerType": worker_type.value, "organizationId": org_id, "applicationTypeId": application_type_ids, "details": json.loads(details) } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_receipt_lookup(self, worker_service_id=None, worker_id=None, requester_id=None, receipt_status=None, id=None): """ Work Order Receipt Lookup """ json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerLookUp", "id": id, "params": { } } if worker_service_id is not None: if not is_hex(worker_service_id): logging.error("Worker service id is Invalid") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker service id is Invalid") json_rpc_request["params"]["workerServiceId"] = worker_service_id if worker_id is not None: if not is_hex(worker_id): logging.error("Worker id is Invalid") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is Invalid") json_rpc_request["params"]["workerId"] = worker_id if requester_id is not None: if not is_hex(requester_id): logging.error("Requester id is Invalid") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Requester id is Invalid") json_rpc_request["params"]["requesterId"] = requester_id if receipt_status is not None: if not isinstance(receipt_status, ReceiptCreateStatus): logging.error("Receipt status is Invalid") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Receipt status is Invalid") json_rpc_request["params"]["receiptStatus"] = receipt_status response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_submit(self, params, in_data, out_data=None, id=None): valid, err = self.__validate_parameters(params) if not valid: return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, err) valid, err = self.__validate_data_format(in_data) if not valid: return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, err) if out_data is not None: valid, err = self.__validate_data_format(out_data) if not valid: return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, err) json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderSubmit", "id": id, "params": { "responseTimeoutMSecs": params["responseTimeoutMSecs"], "payloadFormat": params["payloadFormat"], "resultUri": params["resultUri"], "notifyUri": params["notifyUri"], "workOrderId": params["workOrderId"], "workerId": params["workerId"], "workloadId": params["workloadId"], "requesterId": params["requesterId"], "workerEncryptionKey": params["workerEncryptionKey"], "dataEncryptionAlgorithm": params["dataEncryptionAlgorithm"], "encryptedSessionKey": params["encryptedSessionKey"], "sessionKeyIv": params["sessionKeyIv"], "requesterNonce": params["requesterNonce"], "encryptedRequestHash": params["encryptedRequestHash"], "requesterSignature": params["requesterSignature"], "verifyingKey": params["verifyingKey"], "inData": in_data, } } if out_data is not None: json_rpc_request["outData"] = out_data response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def worker_lookup_next(self, lookup_tag, worker_type=None, organization_id=None, application_type_id=None, id=None): """ Similar to workerLookUp with additional parameter lookup_tag """ json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerLookUpNext", "id": id, "params": { "lookUpTag": lookup_tag } } if worker_type is not None: if not isinstance(worker_type, WorkerType): logging.error("Invalid worker type2") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid worker type") json_rpc_request["params"]["workerType"] = worker_type.value if organization_id is not None: if not is_hex(organization_id): logging.error("Invalid organization id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid organization id") json_rpc_request["params"]["organizationId"] = organization_id if application_type_id is not None: for app_id in application_type_id: if not is_hex(app_id): logging.error("Invalid application type id") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid application type id") json_rpc_request["params"][ "applicationTypeId"] = application_type_id response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def worker_lookup(self, worker_type=None, organization_id=None, application_type_id=None, id=None): """ Worker lookup based on worker type, organization id and application id""" json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerLookUp", "id": id, "params": {} } if worker_type is not None: if not isinstance(worker_type, WorkerType): logging.error("Invalid worker type") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid worker type") json_rpc_request["params"]["workerType"] = worker_type.value if organization_id is not None: if not is_valid_hex_str(organization_id): logging.error("Invalid organization id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid organization id") json_rpc_request["params"]["organizationId"] = organization_id if application_type_id is not None: for app_id in application_type_id: if not is_valid_hex_str(app_id): logging.error("Invalid application type id") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid application type id") json_rpc_request["params"]["applicationTypeId"] = \ application_type_id response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_get_result(self, work_order_id, id=None): if not is_hex(work_order_id): logging.error("Invalid work order Id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid work order Id") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderGetResult", "id": id, "params": { "workOrderId": work_order_id } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def encryption_key_set(self, worker_id, encryption_key, encryption_key_nonce, tag, signature_nonce, signature, id=None): if not is_valid_hex_str(worker_id): logging.error("Invalid Worker id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid Worker id") if not is_valid_hex_str(encryption_key): logging.error("Invalid encryption key") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid encryption key") if encryption_key_nonce is not None and not is_valid_hex_str( encryption_key_nonce): logging.error("Invalid encryption nonce") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid encryption nonce") if tag is not None and not is_valid_hex_str(tag): logging.error("Invalid tag") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid tag") if signature_nonce is not None and not is_valid_hex_str( signature_nonce): logging.error("Invalid signature nonce") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid signature nonce") if signature is not None: try: base64.b64decode(signature) except Exception as e: logging.error("Invalid signature") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid signature") json_rpc_request = { "jsonrpc": "2.0", "method": "EncryptionKeySet", "id": id, "params": { "workerId": worker_id, "encryptionKey": encryption_key, "encryptionKeyNonce": encryption_key_nonce, "tag": tag, "signatureNonce": signature_nonce, "signature": signature } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def worker_update(self, worker_id, details, id=None): """ Update worker with new information """ if worker_id is None or not is_hex(worker_id): logging.error("Worker id is empty or invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerUpdate", "id": id, "params": { "workerId": worker_id, "details": details } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def worker_retrieve(self, worker_id, id=None): """ Retrieve the worker identified by worker id """ if worker_id is None or not is_hex(worker_id): logging.error("Worker id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerRetrieve", "id": id, "params": { "workerId": worker_id } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_receipt_retrieve(self, work_order_id, id=None): """ Retrieve a Work Order Receipt json rpc request and submit tcs listener """ if work_order_id is None or not is_valid_hex_str(work_order_id): logging.error("Work order id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderReceiptRetrieve", "id": id, "params": { "workOrderId": work_order_id } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def work_order_get_result_nonblocking(self, work_order_id, id=None): """ Get the work order result in non-blocking way. It return json rpc response of dictionary type """ if not is_valid_hex_str(work_order_id): logging.error("Invalid work order Id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid work order Id") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkOrderGetResult", "id": id, "params": { "workOrderId": work_order_id } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def worker_set_status(self, worker_id, status, id=None): """ Set the worker status to active, offline, decommissioned or compromised state """ if worker_id is None or not is_hex(worker_id): logging.error("Worker id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerSetStatus", "id": id, "params": { "workerId": worker_id, "status": status.value } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response
def encryption_key_get(self, worker_id, last_used_key_nonce, tag, requester_id, signature_nonce, signature, id=None): if not is_hex(worker_id): logging.error("Invalid Worker id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid Worker id") if last_used_key_nonce is not None and not is_hex(last_used_key_nonce): logging.error("Invalid last used key nonce") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid last used key nonce") if tag is not None and not is_hex(tag): logging.error("Invalid tag") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid tag") if requester_id is not None and not is_hex(requester_id): logging.error("Invalid requester id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid requester id") if signature_nonce is not None and not is_hex(signature_nonce): logging.error("Invalid signature nonce") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid signature nonce") if signature is not None: try: base64.b64decode(signature) except Exception as e: logging.error("Invalid signature") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid signature") json_rpc_request = { "jsonrpc": "2.0", "method": "EncryptionKeyGet", "id": id, "params": { "workerId": worker_id, "lastUsedKeyNonce": last_used_key_nonce, "tag": tag, "requesterId": requester_id, "signatureNonce": signature_nonce, "signature": signature } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response