From fb226d910c56d5e64fa55c43c83562db89c68d07 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Date: Thu, 23 Jun 2022 18:01:44 +0200 Subject: [PATCH] Reuse agent filtering method to get all policies --- internal/dump/agentpolicies.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/internal/dump/agentpolicies.go b/internal/dump/agentpolicies.go index b789c8932..4d8fae1fc 100644 --- a/internal/dump/agentpolicies.go +++ b/internal/dump/agentpolicies.go @@ -70,24 +70,11 @@ func (d *AgentPoliciesDumper) DumpByName(ctx context.Context, dir, name string) func (d *AgentPoliciesDumper) getAllAgentPolicies(ctx context.Context) ([]AgentPolicy, error) { if len(d.policies) == 0 { - policies, err := d.client.ListRawPolicy() - + policies, err := d.getAgentPoliciesFilteredByPackage(ctx, "") if err != nil { return nil, err } - - var policyName struct { - ID string `json:"id"` - } - - for _, policy := range policies { - err = json.Unmarshal(policy, &policyName) - if err != nil { - return nil, fmt.Errorf("failed to get Agent Policy ID: %w", err) - } - agentPolicy := AgentPolicy{name: policyName.ID, raw: policy} - d.policies = append(d.policies, agentPolicy) - } + d.policies = policies } return d.policies, nil } @@ -128,9 +115,11 @@ func (d *AgentPoliciesDumper) getAgentPoliciesFilteredByPackage(ctx context.Cont if err != nil { return nil, fmt.Errorf("failed to get Agent Policy ID: %w", err) } - packageNames := getPackagesUsingAgentPolicy(policyPackages.PackagePolicies) - if !common.StringSliceContains(packageNames, packageName) { - continue + if packageName != "" { + packageNames := getPackagesUsingAgentPolicy(policyPackages.PackagePolicies) + if !common.StringSliceContains(packageNames, packageName) { + continue + } } agentPolicy := AgentPolicy{name: policyPackages.ID, raw: policy}