mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	* WIP on mongodb plugin * Add mongodb plugin * Add tests * Update mongodb.CreateUser() comment * Update docs * Add missing docs * Fix mongodb docs * Minor comment and test updates * Fix imports * Fix dockertest import * Set c.Initialized at the end, check for empty CreationStmts first on CreateUser * Remove Initialized check on Connection() * Add back Initialized check * Update docs * Move connProducer and credsProducer into pkg for mongodb and cassandra * Chage parseMongoURL to be a private func * Default to admin if no db is provided in creation_statements * Update comments and docs
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
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
 | 
						|
}
 |