Exemplo n.º 1
0
    def encrypt_files_dict(files_dict, encrypt_endpoint, asset_id,
                           account_address, signed_did):
        payload = json.dumps({
            'documentId': asset_id,
            'signedDocumentId': signed_did,
            'document': json.dumps(files_dict),
            'publisherAddress': account_address
        })
        response = Brizo._http_client.post(
            encrypt_endpoint,
            data=payload,
            headers={'content-type': 'application/json'})
        if response and hasattr(response, 'status_code'):
            if response.status_code != 201:
                msg = (
                    f'Encrypt file urls failed at the encryptEndpoint '
                    f'{encrypt_endpoint}, reason {response.text}, status {response.status_code}'
                )
                logger.error(msg)
                raise OceanEncryptAssetUrlsError(msg)

            logger.info(
                f'Asset urls encrypted successfully, encrypted urls str: {response.text},'
                f' encryptedEndpoint {encrypt_endpoint}')

            return response.text
Exemplo n.º 2
0
    def encrypt_files_dict(files_dict, encrypt_endpoint, asset_id,
                           publisher_address, signed_did):
        payload = json.dumps({
            "documentId": asset_id,
            "signature": signed_did,
            "document": json.dumps(files_dict),
            "publisherAddress": publisher_address,
        })

        response = DataServiceProvider._http_method(
            "post",
            encrypt_endpoint,
            data=payload,
            headers={"content-type": "application/json"},
        )
        if response and hasattr(response, "status_code"):
            if response.status_code != 201:
                msg = (
                    f"Encrypt file urls failed at the encryptEndpoint "
                    f"{encrypt_endpoint}, reason {response.text}, status {response.status_code}"
                )
                logger.error(msg)
                raise OceanEncryptAssetUrlsError(msg)

            logger.info(
                f"Asset urls encrypted successfully, encrypted urls str: {response.text},"
                f" encryptedEndpoint {encrypt_endpoint}")

            return response.json()["encryptedDocument"]