forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
39 lines (35 loc) · 1.02 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package mongodb
type createUserCommand struct {
Username string `bson:"createUser"`
Password string `bson:"pwd"`
Roles []interface{} `bson:"roles"`
}
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
}