Skip to content

Commit

Permalink
Update auth.py
Browse files Browse the repository at this point in the history
  • Loading branch information
daisieh committed Jan 18, 2025
1 parent 2679bcf commit c1e0f23
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/authx/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ def add_program_to_opa(program_auth):
response2, status_code = set_service_store_secret("opa", key="programs", value=json.dumps(response2))
return response, status_code

# add the users to the preapproved user list

return {"message": f"{program_id} not added"}, status_code


Expand Down Expand Up @@ -822,7 +824,7 @@ def clear_pending_users_in_opa():
def list_preapproved_users_in_opa():
response, status_code = get_service_store_secret("opa", key=f"preapproved_users")
if status_code == 200:
response = list(response["preapproved_users"].keys())
response = response["preapproved_users"]
return response, status_code


Expand All @@ -842,18 +844,16 @@ def get_preapproved_user(user_name):

def add_preapproved_user_in_opa(user_name):
response, status_code = get_service_store_secret("opa", key=f"preapproved_users")
if status_code != 200:
return response, status_code
preapproved_users = response["preapproved_users"]
if user_name in preapproved_users:
user_dict = preapproved_users[user_name]
user_dict["dac_authorizations"] = {}
response2, status_code = write_user_in_opa(user_dict)
if status_code == 200:
preapproved_users.pop(user_name)
response3, status_code = set_service_store_secret("opa", key=f"preapproved_users", value=json.dumps(response))
else:
return {"error": f"no preapproved user with ID {user_name}"}, 404

if user_name in response["preapproved_users"]:
# return 200 to indicate OK but nothing was added
return {"message": f"User {user_name} already pending"}, 200

response["preapproved_users"].append(user_name)

response, status_code = set_service_store_secret("opa", key=f"preapproved_users", value=json.dumps(response))
if status_code == 200:
return response, 201 # 201 created, to indicate that we added the user
return response, status_code


Expand Down

0 comments on commit c1e0f23

Please sign in to comment.