Skip to content

Commit

Permalink
break out get_opa_permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
daisieh committed Jan 17, 2025
1 parent 0f8cf1e commit a0be093
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/authx/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,7 @@ def is_site_admin(request, token=None, opa_url=OPA_URL, admin_secret=None):
return False


def is_action_allowed_for_program(token, method=None, path=None, program=None, opa_url=OPA_URL, admin_secret=None):
"""
Is the user allowed to perform this action on this program?
"""

def get_opa_permissions(token, method=None, path=None, program=None, opa_url=OPA_URL, admin_secret=None):
token = get_auth_token(None, token=token)
if opa_url is None:
print("WARNING: AUTHORIZATION IS DISABLED; OPA_URL is not present")
Expand All @@ -227,8 +223,18 @@ def is_action_allowed_for_program(token, method=None, path=None, program=None, o
}
)
if response.status_code == 200:
if 'allowed' in response.json()["result"]:
return response.json()["result"]["allowed"]
return response.json()["result"], 200
return response.text, response.status_code

def is_action_allowed_for_program(token, method=None, path=None, program=None, opa_url=OPA_URL, admin_secret=None):
"""
Is the user allowed to perform this action on this program?
"""

response, status_code = get_opa_permissions(token, method, path, program, opa_url, admin_secret)
if status_code == 200:
if 'allowed' in response:
return response["allowed"]
return False


Expand Down

0 comments on commit a0be093

Please sign in to comment.