2023-03-15 19:00:52 +03:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2024-01-02 21:36:20 +03:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-15 19:00:52 +03:00
|
|
|
|
2022-01-05 21:02:03 +03:00
|
|
|
//go:build !enterprise
|
2021-05-13 16:55:46 +03: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
|
|
|
|
}
|