2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-01-05 18:02:03 +00:00
|
|
|
//go:build !enterprise
|
2021-05-13 13:55:46 +00:00
|
|
|
|
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
passwordPolicySubPath = "password_policy/"
|
|
|
|
)
|
|
|
|
|
|
|
|
// retrievePasswordPolicy retrieves a password policy from the logical storage
|
|
|
|
func (d dynamicSystemView) retrievePasswordPolicy(ctx context.Context, policyName string) (*passwordPolicyConfig, error) {
|
|
|
|
storage := d.core.systemBarrierView.SubView(passwordPolicySubPath)
|
|
|
|
entry, err := storage.Get(ctx, policyName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
policyCfg := &passwordPolicyConfig{}
|
|
|
|
err = json.Unmarshal(entry.Value, &policyCfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to unmarshal stored data: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return policyCfg, nil
|
|
|
|
}
|