open-vault/builtin/logical/pki/config_util.go
Alexander Scheel 920ec37b21
Refactor PKI storage calls to take a shared struct (#16019)
This will allow us to refactor the storage functions to take additional
parameters (or backend-inferred values) in the future. In particular, as
we look towards adding a storage cache layer, we'll need to add this to
the backend, which is now accessible from all storage functions.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2022-06-29 12:00:44 -04:00

54 lines
981 B
Go

package pki
import (
"strings"
)
func (sc *storageContext) isDefaultKeySet() (bool, error) {
config, err := sc.getKeysConfig()
if err != nil {
return false, err
}
return strings.TrimSpace(config.DefaultKeyId.String()) != "", nil
}
func (sc *storageContext) isDefaultIssuerSet() (bool, error) {
config, err := sc.getIssuersConfig()
if err != nil {
return false, err
}
return strings.TrimSpace(config.DefaultIssuerId.String()) != "", nil
}
func (sc *storageContext) updateDefaultKeyId(id keyID) error {
config, err := sc.getKeysConfig()
if err != nil {
return err
}
if config.DefaultKeyId != id {
return sc.setKeysConfig(&keyConfigEntry{
DefaultKeyId: id,
})
}
return nil
}
func (sc *storageContext) updateDefaultIssuerId(id issuerID) error {
config, err := sc.getIssuersConfig()
if err != nil {
return err
}
if config.DefaultIssuerId != id {
return sc.setIssuersConfig(&issuerConfigEntry{
DefaultIssuerId: id,
})
}
return nil
}