1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
13
// AdminUser is the name of the user that is initially created in mongo.
14
const AdminUser = "admin"
17
processSignal = (*os.Process).Signal
20
// SetAdminMongoPassword sets the administrative password
21
// to access a mongo database. If the password is non-empty,
22
// all subsequent attempts to access the database must
23
// be authorized; otherwise no authorization is required.
24
func SetAdminMongoPassword(session *mgo.Session, user, password string) error {
25
admin := session.DB("admin")
27
if err := admin.UpsertUser(&mgo.User{
30
Roles: []mgo.Role{mgo.RoleDBAdminAny, mgo.RoleUserAdminAny, mgo.RoleClusterAdmin, mgo.RoleReadWriteAny},
32
return fmt.Errorf("cannot set admin password: %v", err)
35
if err := admin.RemoveUser(user); err != nil && err != mgo.ErrNotFound {
36
return fmt.Errorf("cannot disable admin password: %v", err)