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
|
|
|
|
2019-03-05 22:55:07 +03:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
requestCounterDatePathFormat = "2006/01"
|
2020-11-03 06:59:55 +03:00
|
|
|
|
|
|
|
// This storage path stores both the request counters in this file, and the activity log.
|
|
|
|
countersSubPath = "counters/"
|
2019-03-05 22:55:07 +03:00
|
|
|
)
|
|
|
|
|
2019-10-08 20:58:19 +03:00
|
|
|
// ActiveTokens contains the number of active tokens.
|
|
|
|
type ActiveTokens struct {
|
|
|
|
// ServiceTokens contains information about the number of active service
|
|
|
|
// tokens.
|
|
|
|
ServiceTokens TokenCounter `json:"service_tokens"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TokenCounter counts the number of tokens
|
|
|
|
type TokenCounter struct {
|
|
|
|
// Total is the total number of tokens
|
|
|
|
Total int `json:"total"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// countActiveTokens returns the number of active tokens
|
|
|
|
func (c *Core) countActiveTokens(ctx context.Context) (*ActiveTokens, error) {
|
|
|
|
// Get all of the namespaces
|
|
|
|
ns := c.collectNamespaces()
|
|
|
|
|
|
|
|
// Count the tokens under each namespace
|
|
|
|
total := 0
|
|
|
|
for i := 0; i < len(ns); i++ {
|
|
|
|
ids, err := c.tokenStore.idView(ns[i]).List(ctx, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
total += len(ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ActiveTokens{
|
|
|
|
ServiceTokens: TokenCounter{
|
|
|
|
Total: total,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ActiveEntities contains the number of active entities.
|
|
|
|
type ActiveEntities struct {
|
|
|
|
// Entities contains information about the number of active entities.
|
|
|
|
Entities EntityCounter `json:"entities"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// EntityCounter counts the number of entities
|
|
|
|
type EntityCounter struct {
|
|
|
|
// Total is the total number of entities
|
|
|
|
Total int `json:"total"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// countActiveEntities returns the number of active entities
|
|
|
|
func (c *Core) countActiveEntities(ctx context.Context) (*ActiveEntities, error) {
|
|
|
|
count, err := c.identityStore.countEntities()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ActiveEntities{
|
|
|
|
Entities: EntityCounter{
|
|
|
|
Total: count,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|