Skip to content
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

database: update plugin to adhere to Database v5 interface #14

Merged
merged 8 commits into from Oct 12, 2020

Conversation

calvn
Copy link
Member

@calvn calvn commented Oct 2, 2020

Overview

Updates the MongoDB Atlas Database plugin to adhere to the v5 Database interface. Doc updates will be done directly on the SDK and Database v5 feature. The change should be relatively transparent for users.

Related Issues/Pull Requests

Test Output

Acceptance test output using a real MongoDB Atlas account:

Test Output
=== RUN   TestIntegrationDatabaseUser_Initialize
--- PASS: TestIntegrationDatabaseUser_Initialize (0.00s)
=== RUN   TestAcceptanceDatabaseUser_CreateUser
--- PASS: TestAcceptanceDatabaseUser_CreateUser (1.06s)
=== RUN   TestAcceptanceDatabaseUser_CreateUserWithSpecialChar
--- PASS: TestAcceptanceDatabaseUser_CreateUserWithSpecialChar (0.75s)
=== RUN   TestAcceptanceDatabaseUser_DeleteUser
--- PASS: TestAcceptanceDatabaseUser_DeleteUser (0.66s)
=== RUN   TestAcceptanceDatabaseUser_UpdateUser_Password
--- PASS: TestAcceptanceDatabaseUser_UpdateUser_Password (1.16s)
PASS

Acceptance test output with user connection verification:

Test Output
=== RUN   TestIntegrationDatabaseUser_Initialize
--- PASS: TestIntegrationDatabaseUser_Initialize (0.00s)
=== RUN   TestAcceptanceDatabaseUser_CreateUser
    mongodbatlas_test.go:187: Asserting username: v-test-SWaadlrmUfSZN
--- PASS: TestAcceptanceDatabaseUser_CreateUser (21.30s)
=== RUN   TestAcceptanceDatabaseUser_CreateUserWithSpecialChar
    mongodbatlas_test.go:232: Asserting username: v-test-yOzs6ajy7t5pv
--- PASS: TestAcceptanceDatabaseUser_CreateUserWithSpecialChar (31.46s)
=== RUN   TestAcceptanceDatabaseUser_DeleteUser
    mongodbatlas_test.go:281: Asserting username: v-test-bmAyoVRmV2VHx
--- PASS: TestAcceptanceDatabaseUser_DeleteUser (31.66s)
=== RUN   TestAcceptanceDatabaseUser_UpdateUser_Password
    mongodbatlas_test.go:325: Asserting username: testmongouser
    mongodbatlas_test.go:338: Asserting username: testmongouser
--- PASS: TestAcceptanceDatabaseUser_UpdateUser_Password (123.04s)
PASS

Contributor Checklist

  • Add relevant docs to upstream Vault repository, or sufficient reasoning why docs won’t be added yet
  • Docs update on setting up and running acceptance tests
  • Backwards compatible. Not backward compatible with Vault versions that dispenses a v4 database client (i.e. prior to Vault 1.6.0) if ran externally.

@calvn calvn requested review from pcman312 and tvoran October 2, 2020 20:54
mongodbatlas.go Outdated Show resolved Hide resolved
mongodbatlas.go Outdated Show resolved Hide resolved
mongodbatlas_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pcman312 pcman312 left a comment

Choose a reason for hiding this comment

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

Looks good overall with a couple of issues

}

// Unmarshal statements.CreationStatements into mongodbRoles
var databaseUser mongoDBAtlasStatement
err = json.Unmarshal([]byte(statements.Creation[0]), &databaseUser)
err = json.Unmarshal([]byte(req.Statements.Commands[0]), &databaseUser)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since any statements beyond the first one are ignored, can you return an error if there are more than one?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems that we are currently ignoring the other statements if they are provided (same for the MongoDB implementation/update). Would this be a breaking behavior if this is changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically it would since we'd be erroring if they provide more than one command rather than ignoring them, however I think this a bad user experience if we leave it as-is since we claim that we'll do something (additional commands) but don't actually.

Copy link
Member Author

@calvn calvn Oct 9, 2020

Choose a reason for hiding this comment

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

Theron pointed me to the elasticsearch bit of code where we do this. I think it's a fair point, though we should probably do the same for the mongodb (non-Atlas) db engine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed on the non-Atlas plugin

mongodbatlas.go Outdated Show resolved Hide resolved
mongodbatlas_test.go Outdated Show resolved Hide resolved
@calvn calvn requested review from pcman312 and tvoran October 9, 2020 17:47
Copy link
Member

@tvoran tvoran left a comment

Choose a reason for hiding this comment

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

I also don't think we need RotateRootCredentials() anymore:

// RotateRootCredentials is not currently supported on MongoDB
func (m *MongoDBAtlas) RotateRootCredentials(ctx context.Context, statements []string) (map[string]interface{}, error) {
return nil, errors.New("root credential rotation is not currently implemented in this database secrets engine")
}

mongodbatlas_test.go Outdated Show resolved Hide resolved
mongodbatlas.go Outdated Show resolved Hide resolved
@calvn calvn merged commit af41da1 into master Oct 12, 2020
@calvn calvn deleted the dbpw-v5-update branch October 12, 2020 17:32
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.

None yet

3 participants