2017-05-11 21:38:54 +00:00
|
|
|
package mongodb
|
|
|
|
|
2020-01-24 08:32:47 +00:00
|
|
|
import "go.mongodb.org/mongo-driver/mongo/writeconcern"
|
|
|
|
|
2017-05-11 21:38:54 +00:00
|
|
|
type createUserCommand struct {
|
|
|
|
Username string `bson:"createUser"`
|
2020-02-13 22:54:00 +00:00
|
|
|
Password string `bson:"pwd,omitempty"`
|
2017-05-11 21:38:54 +00:00
|
|
|
Roles []interface{} `bson:"roles"`
|
|
|
|
}
|
2019-07-05 18:57:01 +00:00
|
|
|
|
2020-01-24 08:32:47 +00:00
|
|
|
type updateUserCommand struct {
|
|
|
|
Username string `bson:"updateUser"`
|
|
|
|
Password string `bson:"pwd"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type dropUserCommand struct {
|
|
|
|
Username string `bson:"dropUser"`
|
|
|
|
WriteConcern *writeconcern.WriteConcern `bson:"writeConcern"`
|
|
|
|
}
|
|
|
|
|
2017-05-11 21:38:54 +00:00
|
|
|
type mongodbRole struct {
|
|
|
|
Role string `json:"role" bson:"role"`
|
|
|
|
DB string `json:"db" bson:"db"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type mongodbRoles []mongodbRole
|
|
|
|
|
|
|
|
type mongoDBStatement struct {
|
|
|
|
DB string `json:"db"`
|
|
|
|
Roles mongodbRoles `json:"roles"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert array of role documents like:
|
|
|
|
//
|
|
|
|
// [ { "role": "readWrite" }, { "role": "readWrite", "db": "test" } ]
|
|
|
|
//
|
|
|
|
// into a "standard" MongoDB roles array containing both strings and role documents:
|
|
|
|
//
|
|
|
|
// [ "readWrite", { "role": "readWrite", "db": "test" } ]
|
|
|
|
//
|
|
|
|
// MongoDB's createUser command accepts the latter.
|
|
|
|
func (roles mongodbRoles) toStandardRolesArray() []interface{} {
|
|
|
|
var standardRolesArray []interface{}
|
|
|
|
for _, role := range roles {
|
|
|
|
if role.DB == "" {
|
|
|
|
standardRolesArray = append(standardRolesArray, role.Role)
|
|
|
|
} else {
|
|
|
|
standardRolesArray = append(standardRolesArray, role)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return standardRolesArray
|
|
|
|
}
|