def worker_lookup_next(self, worker_type, organization_id, 
        application_type_id, lookup_tag, id=None):
        """ Similar to workerLookUp with additional parameter lookup_tag """
        if not isinstance(worker_type, WorkerType):
            logging.error("Worker type is invalid")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                "Worker type is invalid")
        if organization_id is None or not is_hex(organization_id):
            logging.error("Invalid organization id")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                "Invalid organization id")
        if application_type_id is not None:
            for appId in application_type_id:
                if not is_hex(appId):
                    logging.error("Invalid application id")
                    return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                        "Invalid application id")
                    break
        

        json_rpc_request = {
            "jsonrpc": "2.0",
            "method": "WorkerLookUpNext",
            "id": id,
            "params": {
                "workerType": worker_type.value,
                "organizationId": organization_id,
                "applicationTypeId": application_type_id,
                "lookUpTag": lookup_tag
            }
        }
        response = self.__uri_client._postmsg(json.dumps(json_rpc_request))
        return response
    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_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_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")

        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_hex(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_hex(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 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_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 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, 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_hex(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_hex(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_lookup_next(self,
                                       worker_service_id,
                                       worker_id,
                                       requester_id,
                                       receipt_status,
                                       last_lookup_tag,
                                       id=None):
        """
        Work Order Receipt Lookup Next
        """
        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 worker_service_id is None or not is_hex(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_hex(requester_id):
            logging.error("requester id is empty or Invalid")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                                        "requester id is empty or Invalid")

        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 = {
            "jsonrpc": "2.0",
            "method": "WorkOrderReceiptLookUpNext",
            "id": id,
            "params": {
                "workerServiceId": worker_service_id,
                "workerId": worker_id,
                "requesterId": requester_id,
                "updateIndex": receipt_status,
                "lastLookUpTag": last_lookup_tag
            }
        }
        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 appId in application_type_ids:
             if not is_hex(appId):
                 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": details
         }
     }
     response = self.__uri_client._postmsg(json.dumps(json_rpc_request))
     return response
示例#7
0
    def work_order_get_result(self, work_order_id, id=None):
        if not is_hex(work_order_id):
            logging.error("Invalid workOrder Id")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                                        "Invalid workOrder 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_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 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
示例#11
0
    def work_order_submit(self, params, in_data, out_data, id=None):
        is_valid = self.__validate_parameters(params, in_data, out_data)
        if is_valid is not None:
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                                        is_valid)
        if not is_hex(params["workOrderId"]):
            logging.error("Invalid work order id")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                                        "Invalid work order id")
        if not is_hex(params["workloadId"]):
            logging.error("Invalid work load id")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                                        "Invalid work load id")
        if not is_hex(params["requesterId"]):
            logging.error("Invalid requester id id")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                                        "Invalid requester id id")
        if not is_hex(params["workerEncryptionKey"]):
            logging.error("Invalid worker encryption key")
            return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER,
                                        "Invalid worker encryption key")
        for data in in_data:
            if not is_hex(data["dataHash"]):
                logging.error("Invalid data hash of in data")
                return create_jrpc_response(id,
                                            JsonRpcErrorCode.INVALID_PARAMETER,
                                            "Invalid data hash of in data")
            if not is_hex(data["encryptedDataEncryptionKey"]):
                logging.error("Invalid Encryption key of in data")
                return create_jrpc_response(
                    id, JsonRpcErrorCode.INVALID_PARAMETER,
                    "Invalid Encryption key of in data")
            if not is_hex(data["iv"]):
                logging.error("Invalid initialization vector of in data")
                return create_jrpc_response(
                    id, JsonRpcErrorCode.INVALID_PARAMETER,
                    "Invalid initialization vector of in data")
            try:
                base64.b64decode(data["data"])
            except Exception as e:
                logging.error("Invalid base64 format of in data")
                return create_jrpc_response(
                    id, JsonRpcErrorCode.INVALID_PARAMETER,
                    "Invalid base64 format of in data")

        for data in out_data:
            if not is_hex(data["dataHash"]):
                logging.error("Invalid data hash of out data")
                return create_jrpc_response(id,
                                            JsonRpcErrorCode.INVALID_PARAMETER,
                                            "Invalid data hash of out data")
            if not is_hex(data["encryptedDataEncryptionKey"]):
                logging.error("Invalid Encryption key of out data")
                return create_jrpc_response(
                    id, JsonRpcErrorCode.INVALID_PARAMETER,
                    "Invalid Encryption key of out data")
            if not is_hex(data["iv"]):
                logging.error("Invalid initialization vector of out data")
                return create_jrpc_response(
                    id, JsonRpcErrorCode.INVALID_PARAMETER,
                    "Invalid initialization vector of out data")
            try:
                base64.b64decode(data["data"])
            except Exception as e:
                logging.error("Invalid base64 format of out data")
                return create_jrpc_response(
                    id, JsonRpcErrorCode.INVALID_PARAMETER,
                    "Invalid base64 format of out data")

        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"],
                "inData": in_data,
                "outData": out_data
            }
        }
        response = self.__uri_client._postmsg(json.dumps(json_rpc_request))
        return response