create the db automatically as soon as we add some users to it.
parent
aba029fd2a
commit
a9d9127741
|
@ -76,6 +76,11 @@ func (self *ClusterConfiguration) DropDatabase(name string) error {
|
|||
}
|
||||
|
||||
delete(self.databaseNames, name)
|
||||
|
||||
self.usersLock.Lock()
|
||||
defer self.usersLock.Unlock()
|
||||
|
||||
delete(self.dbUsers, name)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -159,6 +159,7 @@ func (self *CoordinatorImpl) CreateDbUser(requester common.User, db, username st
|
|||
return fmt.Errorf("Insufficient permissions")
|
||||
}
|
||||
|
||||
self.clusterConfiguration.CreateDatabase(db) // ignore the error since the db may exist
|
||||
dbUsers := self.clusterConfiguration.dbUsers[db]
|
||||
if dbUsers != nil && dbUsers[username] != nil {
|
||||
return fmt.Errorf("User %s already exists", username)
|
||||
|
|
|
@ -394,6 +394,37 @@ func (self *UserSuite) BenchmarkHashing(c *C) {
|
|||
}
|
||||
}
|
||||
|
||||
func (self *CoordinatorSuite) TestAutomaitcDbCreations(c *C) {
|
||||
servers := startAndVerifyCluster(1, c)
|
||||
defer clean(servers)
|
||||
|
||||
coordinator := NewCoordinatorImpl(nil, servers[0], servers[0].clusterConfig)
|
||||
|
||||
time.Sleep(REPLICATION_LAG)
|
||||
|
||||
// Root user is created
|
||||
var root User
|
||||
var err error
|
||||
// we should have the root user
|
||||
root, err = coordinator.AuthenticateClusterAdmin("root", "root")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(root.IsClusterAdmin(), Equals, true)
|
||||
|
||||
// can create db users
|
||||
c.Assert(coordinator.CreateDbUser(root, "db1", "db_user"), IsNil)
|
||||
c.Assert(coordinator.ChangeDbUserPassword(root, "db1", "db_user", "pass"), Equals, nil)
|
||||
|
||||
// the db should be in the index now
|
||||
dbs, err := coordinator.ListDatabases(root)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(dbs, DeepEquals, []string{"db1"})
|
||||
|
||||
// if the db is dropped it should remove the users as well
|
||||
c.Assert(coordinator.DropDatabase(root, "db1"), IsNil)
|
||||
_, err = coordinator.AuthenticateDbUser("db1", "db_user", "pass")
|
||||
c.Assert(err, ErrorMatches, ".*Invalid.*")
|
||||
}
|
||||
|
||||
func (self *CoordinatorSuite) TestAdminOperations(c *C) {
|
||||
servers := startAndVerifyCluster(1, c)
|
||||
defer clean(servers)
|
||||
|
|
Loading…
Reference in New Issue