deb.open-vault/vault/expiration_util.go

34 lines
856 B
Go
Raw Normal View History

2024-04-20 12:23:50 +00:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build !enterprise
package vault
import (
"fmt"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/sdk/logical"
)
func (m *ExpirationManager) leaseView(*namespace.Namespace) *BarrierView {
return m.idView
}
func (m *ExpirationManager) tokenIndexView(*namespace.Namespace) *BarrierView {
return m.tokenView
}
func (m *ExpirationManager) collectLeases() (map[*namespace.Namespace][]string, int, error) {
leaseCount := 0
existing := make(map[*namespace.Namespace][]string)
keys, err := logical.CollectKeys(m.quitContext, m.leaseView(namespace.RootNamespace))
if err != nil {
return nil, 0, fmt.Errorf("failed to scan for leases: %w", err)
}
existing[namespace.RootNamespace] = keys
leaseCount += len(keys)
return existing, leaseCount, nil
}