-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INTMDB217 - Wait until user is applied to clusters #27
INTMDB217 - Wait until user is applied to clusters #27
Conversation
mongodbatlas.go
Outdated
@@ -126,6 +128,56 @@ func (m *MongoDBAtlas) NewUser(ctx context.Context, req dbplugin.NewUserRequest) | |||
return dbplugin.NewUserResponse{}, err | |||
} | |||
|
|||
clusters, _, err := client.Clusters.List(ctx, m.ProjectID, &mongodbatlas.ListOptions{}) | |||
if err != nil { | |||
return dbplugin.NewUserResponse{}, fmt.Errorf("roles array is required in creation statement") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] no need for formatting
return dbplugin.NewUserResponse{}, fmt.Errorf("roles array is required in creation statement") | |
return dbplugin.NewUserResponse{}, errors.New("roles array is required in creation statement") |
mongodbatlas.go
Outdated
|
||
operation := func() error { | ||
|
||
status, _, err := client.Clusters.Status(context.Background(), m.ProjectID, clustername) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to reuse the context from outside the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, will fix this
@@ -126,6 +128,56 @@ func (m *MongoDBAtlas) NewUser(ctx context.Context, req dbplugin.NewUserRequest) | |||
return dbplugin.NewUserResponse{}, err | |||
} | |||
|
|||
clusters, _, err := client.Clusters.List(ctx, m.ProjectID, &mongodbatlas.ListOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this api call is paginated, if someone has more than 100 clusters you may miss those outside the [1,100] range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this is not correctly implemented on the client, will raise an issue with the mongo team
After some more research we have elected to not merge this PR. Please see #10 (comment) for more details. |
Overview
As reported in the Vault repo issue: #10
Right now the vault database user plugin for Atlas returns as soon as the API request is successfully accepted by Atlas. However the user takes time to apply to all the clusters in a project, meaning that if the credential is handed to an application that tries to then use that new credential right away- authentication fails. We now have an endpoint to check the status: https://docs.atlas.mongodb.com/reference/api/clusters-check-operation-status/
We need to build in the ability to poll that endpoint and wait to return the credential till it is really applied. Ideally this is an optional function so that if users would rather a faster return over being sure the user is really created we don't inadvertently frustrate them - if not possible then we'll default to the "really applied" default.
https://jira.mongodb.org/browse/INTMDB-217
Design of Change
Create a goroutine for each of the clusters then wait until the change is applied on each of them. Wrap the errors and return error or the user if it's sucessfull.
Related Issues/Pull Requests
https://jira.mongodb.org/browse/INTMDB-217
Contributor Checklist
[ ] Add relevant docs to upstream Vault repository, or sufficient reasoning why docs won’t be added yet
My Docs PR Link
Example
[x] Add output for any tests not ran in CI to the PR description (eg, acceptance tests)
[x] Backwards compatible
No documentation is necessary at the time