mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
VAULT-35527 add control groups metrics (#30733)
* oss patch * oss patch update
This commit is contained in:
parent
f1c83954f6
commit
f444e37f10
1 changed files with 37 additions and 0 deletions
|
|
@ -1118,3 +1118,40 @@ func (c *Core) GetAuditExclusionStanzaCount() int {
|
|||
|
||||
return exclusionsCount
|
||||
}
|
||||
|
||||
func (c *Core) GetControlGroupCount() (int, error) {
|
||||
policyStore := c.policyStore
|
||||
|
||||
if policyStore == nil {
|
||||
return 0, fmt.Errorf("could not find a policy store")
|
||||
}
|
||||
|
||||
namespaces := c.collectNamespaces()
|
||||
controlGroupCount := 0
|
||||
|
||||
for _, ns := range namespaces {
|
||||
nsCtx := namespace.ContextWithNamespace(context.Background(), ns)
|
||||
|
||||
// get the names of all the ACL policies from on this namespace
|
||||
policyNames, err := policyStore.ListPolicies(nsCtx, PolicyTypeACL)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
for _, name := range policyNames {
|
||||
policy, err := policyStore.GetPolicy(nsCtx, name, PolicyTypeACL)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// check for control groups inside the path rules of the policy
|
||||
for _, pathPolicy := range policy.Paths {
|
||||
if pathPolicy.ControlGroupHCL != nil {
|
||||
controlGroupCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return controlGroupCount, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue