From c1307a16b45908803b27b229ddef973734d2fbe7 Mon Sep 17 00:00:00 2001 From: Urtza Iturraspe <urtza.iturraspe@tecnalia.com> Date: Mon, 28 Oct 2024 16:05:31 +0100 Subject: [PATCH] Changes for avoiding CES and creating assets --- API_OASEES/app/utils/connector_utils.py | 56 +++++++++-- API_OASEES/app/utils/create_asset.py | 37 ++++++-- .../app/utils/create_contract_definition.py | 82 +++++++++++----- API_OASEES/app/utils/create_policy.py | 94 ++++++++++++++++--- .../app/utils/connector_utils.py | 56 +++++++++-- .../app/utils/create_asset.py | 37 ++++++-- .../app/utils/create_contract_definition.py | 82 +++++++++++----- .../app/utils/create_policy.py | 94 ++++++++++++++++--- 8 files changed, 438 insertions(+), 100 deletions(-) diff --git a/API_OASEES/app/utils/connector_utils.py b/API_OASEES/app/utils/connector_utils.py index 67e1d27..757755a 100644 --- a/API_OASEES/app/utils/connector_utils.py +++ b/API_OASEES/app/utils/connector_utils.py @@ -1,18 +1,56 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + import json import os -from datamite.models.dataProductResourcesBody import DataProductResourcesModel +import uuid +from tecnalia.models.dataProductResourcesBody import DataProductResourcesModel from fastapi import HTTPException 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 + def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): header_authorization = os.getenv("HEADER_AUTHORIZATION") # asset_id = asset_id.replace(os.getenv("DOMAIN_PART"),"") # Create asset + + print(body.dataProductPolicy) + policyData=body.dataProductPolicy + print(policyData) + policyData=policyData.replace("'", "\"") + print(policyData) + + 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: @@ -24,15 +62,21 @@ def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): raise HTTPException(status_code=400, detail=json.loads(create_asset_response.text)) # Create policy - policy_id = os.getenv("POLICY_ID") - contract_id = os.getenv("CONTRACT_ID") + + + #policy_id = os.getenv("POLICY_ID") + + + contract_uuid = uuid.uuid4() + + + + 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)) - - create_contract_response = invoke_create_contract_definition(contract_id, policy_id, dataresource.dataResourceInfo.name, header_authorization) diff --git a/API_OASEES/app/utils/create_asset.py b/API_OASEES/app/utils/create_asset.py index 84c73d4..8407d83 100644 --- a/API_OASEES/app/utils/create_asset.py +++ b/API_OASEES/app/utils/create_asset.py @@ -1,3 +1,27 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + import os import json import requests @@ -5,14 +29,15 @@ import requests def invoke_create_asset(dataProductId: str, dataProductName: str, dataProductFormatType: str, dataProductDescription: str, openAPI: str, header_authorization: str): - provider_host = os.getenv("PROVIDER_HOST") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") - - provider_host_port = os.getenv("PROVIDER_HOST_PORT") + #provider_host = os.getenv("PROVIDER_HOST") + #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") + #provider_host_port = os.getenv("PROVIDER_HOST_PORT") + #url = f"http://{provider_host}:{provider_management_port}/management/v3/assets" + # url = f"https://{provider_host_port}/management/v3/assets" - url = f"http://{provider_host}:{provider_management_port}/management/v3/assets" - # url = f"https://{provider_host_port}/management/v3/assets" + provider_management_url= os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/assets" payload = json.dumps( generate_asset_metadata(dataProductId, dataProductName, dataProductFormatType, dataProductDescription, openAPI)) diff --git a/API_OASEES/app/utils/create_contract_definition.py b/API_OASEES/app/utils/create_contract_definition.py index b20a7ce..5ad49cc 100644 --- a/API_OASEES/app/utils/create_contract_definition.py +++ b/API_OASEES/app/utils/create_contract_definition.py @@ -1,18 +1,47 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" import os import json import requests + + + def invoke_create_contract_definition(contract_id, policy_id, asset_id, header_authorization): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") +# 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") +# provider_host_port = os.getenv("PROVIDER_HOST_PORT") - url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" +# url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" # url = f"https://{provider_host_port}/management/v3/contractdefinitions" + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/contractdefinitions" + payload = json.dumps(generate_contract_metadata(contract_id, policy_id, asset_id)) headers = { 'Content-Type': 'application/json', @@ -29,10 +58,13 @@ def invoke_create_contract_definition(contract_id, policy_id, asset_id, header_a def invoke_create_contract_definition_equal(contract_id, policy_id, asset_id): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + # provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") + # provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + + #url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" - url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/contractdefinitions" payload = json.dumps(generate_contract_metadata_equal(contract_id, policy_id, asset_id)) headers = { @@ -45,25 +77,25 @@ def invoke_create_contract_definition_equal(contract_id, policy_id, asset_id): return response -# def generate_contract_metadata(contract_id, policy_id, asset_id): -# contract_metadata = { -# "@context": { -# "edc": "https://w3id.org/edc/v0.0.1/ns/" -# }, -# "@id": contract_id, -# "accessPolicyId": policy_id, -# "contractPolicyId": policy_id, -# "assetsSelector": { -# "@type": "edc:Criterion", -# "edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/id", -# "edc:operator": "in", -# "edc:operandRight": asset_id -# } -# } -# return contract_metadata +def generate_contract_metadata(contract_id, policy_id, asset_id): + contract_metadata = { + "@context": { + "edc": "https://w3id.org/edc/v0.0.1/ns/" + }, + "@id": contract_id, + "accessPolicyId": policy_id, + "contractPolicyId": policy_id, + "assetsSelector": { + "@type": "edc:Criterion", + "edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/id", + "edc:operator": "in", + "edc:operandRight": asset_id + } + } + return contract_metadata -def generate_contract_metadata(contract_id, policy_id, asset_id): +"""def generate_contract_metadata(contract_id, policy_id, asset_id): contract_metadata = { "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" @@ -74,7 +106,7 @@ def generate_contract_metadata(contract_id, policy_id, asset_id): "assetsSelector": [] } return contract_metadata - +""" def generate_contract_metadata_equal(contract_id, policy_id, asset_id): contract_metadata = { diff --git a/API_OASEES/app/utils/create_policy.py b/API_OASEES/app/utils/create_policy.py index 95f731b..743d0e3 100644 --- a/API_OASEES/app/utils/create_policy.py +++ b/API_OASEES/app/utils/create_policy.py @@ -1,18 +1,45 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" import json import os import requests def checkPolicyId(policy_id, header_authorization): - provider_host = os.getenv("PROVIDER_HOST") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") + #provider_host = os.getenv("PROVIDER_HOST") + #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") - provider_host_port = os.getenv("PROVIDER_HOST_PORT") + #provider_host_port = os.getenv("PROVIDER_HOST_PORT") - url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions/request" + #url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions/request" # url = f"https://{provider_host_port}/management/v3/policydefinitions/request" + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/policydefinitions/request" + + headers = { 'Content-Type': 'application/json', 'X-API-Key': header_authorization @@ -29,18 +56,54 @@ def checkPolicyId(policy_id, header_authorization): return True break - +""" def invoke_create_policy(policy_id, header_authorization): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + #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") + #provider_host_port = os.getenv("PROVIDER_HOST_PORT") - url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" + #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/request" + + + payload = json.dumps(generate_policy_metadata_without_restrictions(policy_id)) + headers = { + 'Content-Type': 'application/json', + 'X-API-Key': header_authorization + } + """"""headers = { + 'Content-Type': 'application/json' + }"""""" + response = requests.request("POST", url, headers=headers, data=payload) + + print(f"Create policy response={response.text}") + return response + +""" + +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 @@ -48,7 +111,7 @@ def invoke_create_policy(policy_id, header_authorization): """headers = { 'Content-Type': 'application/json' }""" - response = requests.request("POST", url, headers=headers, data=payload) + response = requests.request("POST", url, headers=headers, data=policy_data) print(f"Create policy response={response.text}") return response @@ -56,10 +119,15 @@ def invoke_create_policy(policy_id, header_authorization): def invoke_create_policy_time(policy_id, policy_time_interval, policy_time_interval_start_date, policy_time_interval_end_date): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + #provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") + #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + + #url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" + + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/policydefinitions/request" + - url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" payload = json.dumps(generate_policy_metadata_time(policy_id, policy_time_interval, policy_time_interval_start_date, policy_time_interval_end_date)) 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 67e1d27..757755a 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 @@ -1,18 +1,56 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + import json import os -from datamite.models.dataProductResourcesBody import DataProductResourcesModel +import uuid +from tecnalia.models.dataProductResourcesBody import DataProductResourcesModel from fastapi import HTTPException 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 + def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): header_authorization = os.getenv("HEADER_AUTHORIZATION") # asset_id = asset_id.replace(os.getenv("DOMAIN_PART"),"") # Create asset + + print(body.dataProductPolicy) + policyData=body.dataProductPolicy + print(policyData) + policyData=policyData.replace("'", "\"") + print(policyData) + + 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: @@ -24,15 +62,21 @@ def load_asset_edc(body:DataProductResourcesModel, dataResouceAPi_URL:str): raise HTTPException(status_code=400, detail=json.loads(create_asset_response.text)) # Create policy - policy_id = os.getenv("POLICY_ID") - contract_id = os.getenv("CONTRACT_ID") + + + #policy_id = os.getenv("POLICY_ID") + + + contract_uuid = uuid.uuid4() + + + + 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)) - - create_contract_response = invoke_create_contract_definition(contract_id, policy_id, dataresource.dataResourceInfo.name, header_authorization) 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 84c73d4..8407d83 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 @@ -1,3 +1,27 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + import os import json import requests @@ -5,14 +29,15 @@ import requests def invoke_create_asset(dataProductId: str, dataProductName: str, dataProductFormatType: str, dataProductDescription: str, openAPI: str, header_authorization: str): - provider_host = os.getenv("PROVIDER_HOST") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") - - provider_host_port = os.getenv("PROVIDER_HOST_PORT") + #provider_host = os.getenv("PROVIDER_HOST") + #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") + #provider_host_port = os.getenv("PROVIDER_HOST_PORT") + #url = f"http://{provider_host}:{provider_management_port}/management/v3/assets" + # url = f"https://{provider_host_port}/management/v3/assets" - url = f"http://{provider_host}:{provider_management_port}/management/v3/assets" - # url = f"https://{provider_host_port}/management/v3/assets" + provider_management_url= os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/assets" payload = json.dumps( generate_asset_metadata(dataProductId, dataProductName, dataProductFormatType, dataProductDescription, openAPI)) 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 b20a7ce..5ad49cc 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 @@ -1,18 +1,47 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" import os import json import requests + + + def invoke_create_contract_definition(contract_id, policy_id, asset_id, header_authorization): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") +# 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") +# provider_host_port = os.getenv("PROVIDER_HOST_PORT") - url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" +# url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" # url = f"https://{provider_host_port}/management/v3/contractdefinitions" + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/contractdefinitions" + payload = json.dumps(generate_contract_metadata(contract_id, policy_id, asset_id)) headers = { 'Content-Type': 'application/json', @@ -29,10 +58,13 @@ def invoke_create_contract_definition(contract_id, policy_id, asset_id, header_a def invoke_create_contract_definition_equal(contract_id, policy_id, asset_id): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + # provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") + # provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + + #url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" - url = f"http://{provider_host}:{provider_management_port}/management/v3/contractdefinitions" + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/contractdefinitions" payload = json.dumps(generate_contract_metadata_equal(contract_id, policy_id, asset_id)) headers = { @@ -45,25 +77,25 @@ def invoke_create_contract_definition_equal(contract_id, policy_id, asset_id): return response -# def generate_contract_metadata(contract_id, policy_id, asset_id): -# contract_metadata = { -# "@context": { -# "edc": "https://w3id.org/edc/v0.0.1/ns/" -# }, -# "@id": contract_id, -# "accessPolicyId": policy_id, -# "contractPolicyId": policy_id, -# "assetsSelector": { -# "@type": "edc:Criterion", -# "edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/id", -# "edc:operator": "in", -# "edc:operandRight": asset_id -# } -# } -# return contract_metadata +def generate_contract_metadata(contract_id, policy_id, asset_id): + contract_metadata = { + "@context": { + "edc": "https://w3id.org/edc/v0.0.1/ns/" + }, + "@id": contract_id, + "accessPolicyId": policy_id, + "contractPolicyId": policy_id, + "assetsSelector": { + "@type": "edc:Criterion", + "edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/id", + "edc:operator": "in", + "edc:operandRight": asset_id + } + } + return contract_metadata -def generate_contract_metadata(contract_id, policy_id, asset_id): +"""def generate_contract_metadata(contract_id, policy_id, asset_id): contract_metadata = { "@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" @@ -74,7 +106,7 @@ def generate_contract_metadata(contract_id, policy_id, asset_id): "assetsSelector": [] } return contract_metadata - +""" def generate_contract_metadata_equal(contract_id, policy_id, asset_id): contract_metadata = { 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 95f731b..743d0e3 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 @@ -1,18 +1,45 @@ +""" +MIT License + +Copyright (c) 2024 Tecnalia, Basque Research & Technology Alliance (BRTA) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" import json import os import requests def checkPolicyId(policy_id, header_authorization): - provider_host = os.getenv("PROVIDER_HOST") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") + #provider_host = os.getenv("PROVIDER_HOST") + #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT") - provider_host_port = os.getenv("PROVIDER_HOST_PORT") + #provider_host_port = os.getenv("PROVIDER_HOST_PORT") - url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions/request" + #url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions/request" # url = f"https://{provider_host_port}/management/v3/policydefinitions/request" + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/policydefinitions/request" + + headers = { 'Content-Type': 'application/json', 'X-API-Key': header_authorization @@ -29,18 +56,54 @@ def checkPolicyId(policy_id, header_authorization): return True break - +""" def invoke_create_policy(policy_id, header_authorization): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + #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") + #provider_host_port = os.getenv("PROVIDER_HOST_PORT") - url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" + #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/request" + + + payload = json.dumps(generate_policy_metadata_without_restrictions(policy_id)) + headers = { + 'Content-Type': 'application/json', + 'X-API-Key': header_authorization + } + """"""headers = { + 'Content-Type': 'application/json' + }"""""" + response = requests.request("POST", url, headers=headers, data=payload) + + print(f"Create policy response={response.text}") + return response + +""" + +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 @@ -48,7 +111,7 @@ def invoke_create_policy(policy_id, header_authorization): """headers = { 'Content-Type': 'application/json' }""" - response = requests.request("POST", url, headers=headers, data=payload) + response = requests.request("POST", url, headers=headers, data=policy_data) print(f"Create policy response={response.text}") return response @@ -56,10 +119,15 @@ def invoke_create_policy(policy_id, header_authorization): def invoke_create_policy_time(policy_id, policy_time_interval, policy_time_interval_start_date, policy_time_interval_end_date): - provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") - provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + #provider_host = os.getenv("PROVIDER_HOST", "ekodata2.tri.lan") + #provider_management_port = os.getenv("PROVIDER_MANAGEMENT_PORT", "9193") + + #url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" + + provider_management_url = os.getenv("PROVIDER_MANAGEMENT_URL") + url = f"{provider_management_url}/policydefinitions/request" + - url = f"http://{provider_host}:{provider_management_port}/management/v3/policydefinitions" payload = json.dumps(generate_policy_metadata_time(policy_id, policy_time_interval, policy_time_interval_start_date, policy_time_interval_end_date)) -- GitLab