diff --git a/API_OASEES/app/utils/connector_utils.py b/API_OASEES/app/utils/connector_utils.py index 757755ad293722e0ea44bfa3dca3a9ad2bd6b3ea..2a1fc3503abb7611a18a4d6fb02a9e4b29db0dde 100644 --- a/API_OASEES/app/utils/connector_utils.py +++ b/API_OASEES/app/utils/connector_utils.py @@ -32,6 +32,7 @@ from app.utils.create_asset import invoke_create_asset from app.utils.create_policy import invoke_create_policy, checkPolicyId from app.utils.create_contract_definition import invoke_create_contract_definition +logger = logging.getLogger("uvicorn.error") def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): @@ -40,17 +41,19 @@ def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): # asset_id = asset_id.replace(os.getenv("DOMAIN_PART"),"") # Create asset + #get policy metadata print(body.dataProductPolicy) policyData=body.dataProductPolicy - print(policyData) policyData=policyData.replace("'", "\"") print(policyData) + #get the policyId policy_json = json.loads(policyData) policy_id=policy_json["@id"] + print(policy_id) # check new data type - print(type(policy_json)) + for dataresource in body.dataResources: formatType = body.dataAccount[0].formatType if dataresource.dataResourceInfo is not None: @@ -74,6 +77,7 @@ def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): contract_id = "contract-"+policy_id+"-"+str(contract_uuid) #os.getenv("CONTRACT_ID") policyExist = checkPolicyId(policy_id, header_authorization) if not policyExist: + #create_policy_response = invoke_create_policy(policy_id, header_authorization) create_policy_response = invoke_create_policy(policyData, header_authorization) print (json.loads(create_policy_response.text)) diff --git a/API_OASEES/app/utils/create_asset.py b/API_OASEES/app/utils/create_asset.py index 8407d837b45dc438f633164196afff9594346cad..0d99b44e9ffbd592a13775e2d6603513a0427d2c 100644 --- a/API_OASEES/app/utils/create_asset.py +++ b/API_OASEES/app/utils/create_asset.py @@ -27,6 +27,8 @@ import json import requests +logger = logging.getLogger("uvicorn.error") + def invoke_create_asset(dataProductId: str, dataProductName: str, dataProductFormatType: str, dataProductDescription: str, openAPI: str, header_authorization: str): #provider_host = os.getenv("PROVIDER_HOST") @@ -49,6 +51,7 @@ def invoke_create_asset(dataProductId: str, dataProductName: str, dataProductFor 'Content-Type': 'application/json' }""" + print (type(payload)) response = requests.request("POST", url, headers=headers, data=payload) print(f"Create asset response={response.text}") diff --git a/API_OASEES/app/utils/create_contract_definition.py b/API_OASEES/app/utils/create_contract_definition.py index 5ad49cc3f7032d3c1f4ebea68e72738bc1a88134..8ee18517363eb167c00104002f342017eb3b16fe 100644 --- a/API_OASEES/app/utils/create_contract_definition.py +++ b/API_OASEES/app/utils/create_contract_definition.py @@ -27,6 +27,9 @@ import requests +logger = logging.getLogger("uvicorn.error") + + def invoke_create_contract_definition(contract_id, policy_id, asset_id, header_authorization): diff --git a/API_OASEES/app/utils/create_policy.py b/API_OASEES/app/utils/create_policy.py index 743d0e36e37aa3d2a06dc067d0d9a90c6cf867b5..ffeba85e3462e4c15168e7a5c61294ec12af2369 100644 --- a/API_OASEES/app/utils/create_policy.py +++ b/API_OASEES/app/utils/create_policy.py @@ -25,6 +25,8 @@ import json import os import requests +logger = logging.getLogger("uvicorn.error") + def checkPolicyId(policy_id, header_authorization): #provider_host = os.getenv("PROVIDER_HOST") @@ -88,22 +90,12 @@ def invoke_create_policy(policy_id, header_authorization): """ def invoke_create_policy(policy_data, header_authorization): - #provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") - #provider_host_port = os.getenv("PROVIDER_HOST_PORT") - - #url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" - - # url = f"https://{provider_host_port}/management/v3/policydefinitions" provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") url = f"{provider_management_url}/policydefinitions" - - #payload = json.dumps(policy_data) - headers = { 'Content-Type': 'application/json', 'X-API-Key': header_authorization @@ -111,7 +103,9 @@ def invoke_create_policy(policy_data, header_authorization): """headers = { 'Content-Type': 'application/json' }""" + response = requests.request("POST", url, headers=headers, data=policy_data) + # response = requests.request("POST", url, headers=headers, data=payload) print(f"Create policy response={response.text}") return response @@ -194,21 +188,7 @@ def generate_policy_metadata_time(policy_id, policy_time_interval, policy_time_i def generate_policy_metadata_without_restrictions(policy_id): - policy_metadata = { - "@context": { - "@vocab": "https://w3id.org/edc/v0.0.1/ns/" - }, - "@id": policy_id, - "@type": "edc:PolicyDefinition", - "policy": { - "@context": "http://www.w3.org/ns/odrl.jsonld", - "@type": "Set", - "permission": [], - "prohibition": [], - "obligation": [] - } - } - # edc 0.3.1 + policy_metadata = { "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/", @@ -223,5 +203,6 @@ def generate_policy_metadata_without_restrictions(policy_id): "odrl:obligation": [] } } + print (type(policy_metadata)) return policy_metadata diff --git a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/connector_utils.py b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/connector_utils.py index 757755ad293722e0ea44bfa3dca3a9ad2bd6b3ea..2a1fc3503abb7611a18a4d6fb02a9e4b29db0dde 100644 --- a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/connector_utils.py +++ b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/connector_utils.py @@ -32,6 +32,7 @@ from app.utils.create_asset import invoke_create_asset from app.utils.create_policy import invoke_create_policy, checkPolicyId from app.utils.create_contract_definition import invoke_create_contract_definition +logger = logging.getLogger("uvicorn.error") def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): @@ -40,17 +41,19 @@ def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): # asset_id = asset_id.replace(os.getenv("DOMAIN_PART"),"") # Create asset + #get policy metadata print(body.dataProductPolicy) policyData=body.dataProductPolicy - print(policyData) policyData=policyData.replace("'", "\"") print(policyData) + #get the policyId policy_json = json.loads(policyData) policy_id=policy_json["@id"] + print(policy_id) # check new data type - print(type(policy_json)) + for dataresource in body.dataResources: formatType = body.dataAccount[0].formatType if dataresource.dataResourceInfo is not None: @@ -74,6 +77,7 @@ def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): contract_id = "contract-"+policy_id+"-"+str(contract_uuid) #os.getenv("CONTRACT_ID") policyExist = checkPolicyId(policy_id, header_authorization) if not policyExist: + #create_policy_response = invoke_create_policy(policy_id, header_authorization) create_policy_response = invoke_create_policy(policyData, header_authorization) print (json.loads(create_policy_response.text)) diff --git a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_asset.py b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_asset.py index 8407d837b45dc438f633164196afff9594346cad..0d99b44e9ffbd592a13775e2d6603513a0427d2c 100644 --- a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_asset.py +++ b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_asset.py @@ -27,6 +27,8 @@ import json import requests +logger = logging.getLogger("uvicorn.error") + def invoke_create_asset(dataProductId: str, dataProductName: str, dataProductFormatType: str, dataProductDescription: str, openAPI: str, header_authorization: str): #provider_host = os.getenv("PROVIDER_HOST") @@ -49,6 +51,7 @@ def invoke_create_asset(dataProductId: str, dataProductName: str, dataProductFor 'Content-Type': 'application/json' }""" + print (type(payload)) response = requests.request("POST", url, headers=headers, data=payload) print(f"Create asset response={response.text}") diff --git a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_contract_definition.py b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_contract_definition.py index 5ad49cc3f7032d3c1f4ebea68e72738bc1a88134..8ee18517363eb167c00104002f342017eb3b16fe 100644 --- a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_contract_definition.py +++ b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_contract_definition.py @@ -27,6 +27,9 @@ import requests +logger = logging.getLogger("uvicorn.error") + + def invoke_create_contract_definition(contract_id, policy_id, asset_id, header_authorization): diff --git a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_policy.py b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_policy.py index 743d0e36e37aa3d2a06dc067d0d9a90c6cf867b5..ffeba85e3462e4c15168e7a5c61294ec12af2369 100644 --- a/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_policy.py +++ b/GAIAX_DATAPRODUCT_OASEES_DOCKER_COMPOSE/gaiax-selfdescriptor-module/app/utils/create_policy.py @@ -25,6 +25,8 @@ import json import os import requests +logger = logging.getLogger("uvicorn.error") + def checkPolicyId(policy_id, header_authorization): #provider_host = os.getenv("PROVIDER_HOST") @@ -88,22 +90,12 @@ def invoke_create_policy(policy_id, header_authorization): """ def invoke_create_policy(policy_data, header_authorization): - #provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") - #provider_host_port = os.getenv("PROVIDER_HOST_PORT") - - #url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" - - # url = f"https://{provider_host_port}/management/v3/policydefinitions" provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") url = f"{provider_management_url}/policydefinitions" - - #payload = json.dumps(policy_data) - headers = { 'Content-Type': 'application/json', 'X-API-Key': header_authorization @@ -111,7 +103,9 @@ def invoke_create_policy(policy_data, header_authorization): """headers = { 'Content-Type': 'application/json' }""" + response = requests.request("POST", url, headers=headers, data=policy_data) + # response = requests.request("POST", url, headers=headers, data=payload) print(f"Create policy response={response.text}") return response @@ -194,21 +188,7 @@ def generate_policy_metadata_time(policy_id, policy_time_interval, policy_time_i def generate_policy_metadata_without_restrictions(policy_id): - policy_metadata = { - "@context": { - "@vocab": "https://w3id.org/edc/v0.0.1/ns/" - }, - "@id": policy_id, - "@type": "edc:PolicyDefinition", - "policy": { - "@context": "http://www.w3.org/ns/odrl.jsonld", - "@type": "Set", - "permission": [], - "prohibition": [], - "obligation": [] - } - } - # edc 0.3.1 + policy_metadata = { "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/", @@ -223,5 +203,6 @@ def generate_policy_metadata_without_restrictions(policy_id): "odrl:obligation": [] } } + print (type(policy_metadata)) return policy_metadata