mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
secret/database: Fix upgrading database backend (#3714)
This commit is contained in:
@@ -131,6 +131,21 @@ func (b *databaseBackend) DatabaseConfig(s logical.Storage, name string) (*Datab
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
type upgradeStatements struct {
|
||||
// This json tag has a typo in it, the new version does not. This
|
||||
// necessitates this upgrade logic.
|
||||
CreationStatements string `json:"creation_statments"`
|
||||
RevocationStatements string `json:"revocation_statements"`
|
||||
RollbackStatements string `json:"rollback_statements"`
|
||||
RenewStatements string `json:"renew_statements"`
|
||||
}
|
||||
|
||||
type upgradeCheck struct {
|
||||
// This json tag has a typo in it, the new version does not. This
|
||||
// necessitates this upgrade logic.
|
||||
Statements upgradeStatements `json:"statments"`
|
||||
}
|
||||
|
||||
func (b *databaseBackend) Role(s logical.Storage, roleName string) (*roleEntry, error) {
|
||||
entry, err := s.Get("role/" + roleName)
|
||||
if err != nil {
|
||||
@@ -140,11 +155,24 @@ func (b *databaseBackend) Role(s logical.Storage, roleName string) (*roleEntry,
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var upgradeCh upgradeCheck
|
||||
if err := entry.DecodeJSON(&upgradeCh); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result roleEntry
|
||||
if err := entry.DecodeJSON(&result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
empty := upgradeCheck{}
|
||||
if upgradeCh != empty {
|
||||
result.Statements.CreationStatements = upgradeCh.Statements.CreationStatements
|
||||
result.Statements.RevocationStatements = upgradeCh.Statements.RevocationStatements
|
||||
result.Statements.RollbackStatements = upgradeCh.Statements.RollbackStatements
|
||||
result.Statements.RenewStatements = upgradeCh.Statements.RenewStatements
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user