Skip to content

Move CreateProviderUser into credential operations#3141

Merged
dnephin merged 1 commit intomainfrom
dnephin/remove-provider-user-access-methods
Sep 8, 2022
Merged

Move CreateProviderUser into credential operations#3141
dnephin merged 1 commit intomainfrom
dnephin/remove-provider-user-access-methods

Conversation

@dnephin
Copy link
Contributor

@dnephin dnephin commented Sep 6, 2022

Summary

While working on another change I noticed this access.CreateProviderUser function. Unlike most of the other access functions this is not a function that performs authorization for an API operation. It's a helper function for creating the necessary join table when an admin performs an operation that creates an infra user (either by creating a new user, or giving an IDP user a password).

By moving this create-if-not-exists into the CreateCredential and UpdateCredential functions we remove the need for this access function, and we make the {Create,Update}Credential functions safer (because other callers will no longer need to perform this operation).

data.CreateProviderUser already checks for an existing user, so it's safe to call in any case. We should probably rename that function as it behaves differently from other Create functions in the data package, but i've left that rename for a different time. I'm also not sure what the new name should be.

@dnephin dnephin force-pushed the dnephin/remove-provider-user-access-methods branch from 07d88eb to 916ca6d Compare September 6, 2022 23:25

// if the request is from an admin, the infra user may not exist yet, so create the
// provider_user if it's missing.
_, _ = data.CreateProviderUser(rCtx.DBTxn, data.InfraProvider(rCtx.DBTxn), user)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ignored the error here previously. It's probably ok, but I wonder if we should handle it for consistency. The data.CreateProviderUser function already returns no error if the entry already exists.

By moving the creation of the provider user into the credential operations we can
remove the need for this extra access function
Copy link
Collaborator

@BruceMacD BruceMacD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for cleaning this up

@dnephin dnephin force-pushed the dnephin/remove-provider-user-access-methods branch from 916ca6d to 79ef082 Compare September 7, 2022 14:41
@dnephin dnephin merged commit ec3fa3c into main Sep 8, 2022
@dnephin dnephin deleted the dnephin/remove-provider-user-access-methods branch September 8, 2022 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants