Skip to content

Commit

Permalink
Add clusterName to policies list (#3768)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samra10 authored Jun 7, 2023
1 parent 26409d4 commit f82e1f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions core/server/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ func policyToPolicyRespone(policyCRD pacv2beta2.Policy, clusterName string, full
policySpec := policyCRD.Spec

policy := &pb.PolicyObj{
Name: policySpec.Name,
Id: policySpec.ID,
Category: policySpec.Category,
Tags: policySpec.Tags,
Severity: policySpec.Severity,
CreatedAt: policyCRD.CreationTimestamp.Format(time.RFC3339),
Tenant: policyCRD.GetLabels()["toolkit.fluxcd.io/tenant"],
Modes: policyCRD.Status.Modes,
Name: policySpec.Name,
Id: policySpec.ID,
Category: policySpec.Category,
Tags: policySpec.Tags,
Severity: policySpec.Severity,
CreatedAt: policyCRD.CreationTimestamp.Format(time.RFC3339),
Tenant: policyCRD.GetLabels()["toolkit.fluxcd.io/tenant"],
Modes: policyCRD.Status.Modes,
ClusterName: clusterName,
}

if fullDetails {
Expand Down Expand Up @@ -131,7 +132,6 @@ func policyToPolicyRespone(policyCRD pacv2beta2.Policy, clusterName string, full
Labels: policyLabels,
}
policy.Parameters = policyParams
policy.ClusterName = clusterName
}

return policy, nil
Expand Down
2 changes: 2 additions & 0 deletions core/server/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestListPolicies(t *testing.T) {
g.Expect(len(res.Policies)).To(Equal(2))
g.Expect(res.Policies[0].Id).To(Equal(policy1.Spec.ID))
g.Expect(res.Policies[0].Severity).To(Equal(policy1.Spec.Severity))
g.Expect(res.Policies[0].ClusterName).To(Equal("Default"))
}

func TestGetPolicy(t *testing.T) {
Expand Down Expand Up @@ -105,6 +106,7 @@ func TestGetPolicy(t *testing.T) {
g.Expect(res.Policy.Name).To(Equal(policy.Spec.Name))
g.Expect(res.Policy.Severity).To(Equal(policy.Spec.Severity))
g.Expect(res.Policy.Code).To(Equal(policy.Spec.Code))
g.Expect(res.Policy.ClusterName).To(Equal("Default"))

// Test non existing policy
_, err = c.GetPolicy(ctx, &pb.GetPolicyRequest{
Expand Down

0 comments on commit f82e1f6

Please sign in to comment.