Skip to content

Commit

Permalink
Merge pull request #83 from knikolla/fix/conflict
Browse files Browse the repository at this point in the history
Handle possible race conditions on user create
  • Loading branch information
jtriley authored Feb 1, 2023
2 parents 4a3fefa + a9956ff commit 4d28cdf
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/coldfront_plugin_cloud/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,14 @@ def get_federated_user(self, username):
return query_response['users'][0]

def create_federated_user(self, unique_id):
create_response = get_session_for_resource(self.resource).post(
f'{self.resource.get_attribute(attributes.RESOURCE_AUTH_URL)}/v3/users',
json=self.get_user_payload_for_resource(unique_id)
)
if create_response.ok:
try:
create_response = get_session_for_resource(self.resource).post(
f'{self.resource.get_attribute(attributes.RESOURCE_AUTH_URL)}/v3/users',
json=self.get_user_payload_for_resource(unique_id)
)
return create_response.json()['user']
except ksa_exceptions.Conflict:
return self.get_federated_user(unique_id)

def assign_role_on_user(self, username, project_id):
role = self.identity.roles.find(name=self.member_role_name)
Expand Down

0 comments on commit 4d28cdf

Please sign in to comment.