Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #61 from EOEPCA/release/v0.3
Browse files Browse the repository at this point in the history
v0.3.1 re-issue
  • Loading branch information
hector-rodriguez authored Mar 8, 2021
2 parents b1b04f4 + 66276d4 commit e957a53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/blueprints/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ def resource_creation():
#If the reply is not of type Response, the creation was successful
#Here we register a default ownership policy to the new resource, with the PDP
if not isinstance(resource_reply, Response):
resource_id = resource_reply
resource_id = resource_reply["id"]
policy_reply = pdp_policy_handler.create_policy(policy_body=get_default_ownership_policy_body(resource_id, uid), input_headers=request.headers)
print("CODE: "+str(policy_reply.status_code))
print(policy_reply.text)
if policy_reply.status_code == 200:
return resource_id
return resource_reply
response.status_code = policy_reply.status_code
response.headers["Error"] = "Error when registering resource ownership policy!"
print(response.headers["Error"])
Expand Down Expand Up @@ -191,7 +191,10 @@ def create_resource(uid, request, uma_handler, response):
if "resource_scopes" not in data.keys():
data["resource_scopes"] = ["protected_access"]
if "name" in data.keys() and "resource_scopes" in data.keys():
return uma_handler.create(data.get("name"), data.get("resource_scopes"), data.get("description"), uid, data.get("icon_uri"))
resource_id = uma_handler.create(data.get("name"), data.get("resource_scopes"), data.get("description"), uid, data.get("icon_uri"))
data["ownership_id"] = uid
data["id"] = resource_id
return data
else:
response.status_code = 500
response.headers["Error"] = "Invalid data passed on URL called for resource creation!"
Expand All @@ -202,7 +205,10 @@ def create_resource(uid, request, uma_handler, response):
return response
except Exception as e:
print("Error while creating resource: "+str(e))
response.status_code = 500
if "already exists for URI" in str(e):
response.status_code = 422
else:
response.status_code = 500
response.headers["Error"] = str(e)
return response

Expand Down
5 changes: 5 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
uma_handler = UMA_Handler(g_wkh, oidc_client, g_config["check_ssl_certs"])
uma_handler.status()

#Default behavior is open_access
try:
uma_handler.create("Base Path", ["public_access"], "Base path for Open Access to PEP", "0000000000000", "/")
except:
pass
#PDP Policy Handler
pdp_policy_handler = policy_handler(pdp_url=g_config["pdp_url"], pdp_port=g_config["pdp_port"], pdp_policy_endpoint=g_config["pdp_policy_endpoint"])

Expand Down

0 comments on commit e957a53

Please sign in to comment.