Locking updates in database backend (#3774)
This commit is contained in:
parent
9fa314e639
commit
102ed8cfae
|
@ -56,7 +56,7 @@ func (b *databaseBackend) pathCredsCreateRead() framework.OperationFunc {
|
||||||
|
|
||||||
// Grab the read lock
|
// Grab the read lock
|
||||||
b.RLock()
|
b.RLock()
|
||||||
var unlockFunc func() = b.RUnlock
|
unlockFunc := b.RUnlock
|
||||||
|
|
||||||
// Get the Database object
|
// Get the Database object
|
||||||
db, ok := b.getDBObj(role.DBName)
|
db, ok := b.getDBObj(role.DBName)
|
||||||
|
@ -83,9 +83,8 @@ func (b *databaseBackend) pathCredsCreateRead() framework.OperationFunc {
|
||||||
|
|
||||||
// Create the user
|
// Create the user
|
||||||
username, password, err := db.CreateUser(ctx, role.Statements, usernameConfig, expiration)
|
username, password, err := db.CreateUser(ctx, role.Statements, usernameConfig, expiration)
|
||||||
// Unlock
|
|
||||||
unlockFunc()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
unlockFunc()
|
||||||
b.closeIfShutdown(role.DBName, err)
|
b.closeIfShutdown(role.DBName, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -98,6 +97,8 @@ func (b *databaseBackend) pathCredsCreateRead() framework.OperationFunc {
|
||||||
"role": name,
|
"role": name,
|
||||||
})
|
})
|
||||||
resp.Secret.TTL = role.DefaultTTL
|
resp.Secret.TTL = role.DefaultTTL
|
||||||
|
|
||||||
|
unlockFunc()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (b *databaseBackend) secretCredsRenew() framework.OperationFunc {
|
||||||
|
|
||||||
// Grab the read lock
|
// Grab the read lock
|
||||||
b.RLock()
|
b.RLock()
|
||||||
var unlockFunc func() = b.RUnlock
|
unlockFunc := b.RUnlock
|
||||||
|
|
||||||
// Get the Database object
|
// Get the Database object
|
||||||
db, ok := b.getDBObj(role.DBName)
|
db, ok := b.getDBObj(role.DBName)
|
||||||
|
@ -71,14 +71,14 @@ func (b *databaseBackend) secretCredsRenew() framework.OperationFunc {
|
||||||
// Make sure we increase the VALID UNTIL endpoint for this user.
|
// Make sure we increase the VALID UNTIL endpoint for this user.
|
||||||
if expireTime := resp.Secret.ExpirationTime(); !expireTime.IsZero() {
|
if expireTime := resp.Secret.ExpirationTime(); !expireTime.IsZero() {
|
||||||
err := db.RenewUser(ctx, role.Statements, username, expireTime)
|
err := db.RenewUser(ctx, role.Statements, username, expireTime)
|
||||||
// Unlock
|
|
||||||
unlockFunc()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
unlockFunc()
|
||||||
b.closeIfShutdown(role.DBName, err)
|
b.closeIfShutdown(role.DBName, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlockFunc()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ func (b *databaseBackend) secretCredsRevoke() framework.OperationFunc {
|
||||||
|
|
||||||
// Grab the read lock
|
// Grab the read lock
|
||||||
b.RLock()
|
b.RLock()
|
||||||
var unlockFunc func() = b.RUnlock
|
unlockFunc := b.RUnlock
|
||||||
|
|
||||||
// Get our connection
|
// Get our connection
|
||||||
db, ok := b.getDBObj(role.DBName)
|
db, ok := b.getDBObj(role.DBName)
|
||||||
|
@ -127,14 +127,13 @@ func (b *databaseBackend) secretCredsRevoke() framework.OperationFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.RevokeUser(ctx, role.Statements, username)
|
if err := db.RevokeUser(ctx, role.Statements, username); err != nil {
|
||||||
// Unlock
|
unlockFunc()
|
||||||
unlockFunc()
|
|
||||||
if err != nil {
|
|
||||||
b.closeIfShutdown(role.DBName, err)
|
b.closeIfShutdown(role.DBName, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlockFunc()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue