diff --git a/management/server/http/api/openapi.yml b/management/server/http/api/openapi.yml index 11865fc0532..4b85eb1853a 100644 --- a/management/server/http/api/openapi.yml +++ b/management/server/http/api/openapi.yml @@ -779,6 +779,12 @@ components: - $ref: '#/components/schemas/PolicyMinimum' - type: object properties: + source_posture_checks: + description: Posture checks ID's applied to policy source groups + type: array + items: + type: string + example: "chacbco6lnnbn6cg5s91" rules: description: Policy rule object for policy UI editor type: array diff --git a/management/server/http/api/types.gen.go b/management/server/http/api/types.gen.go index 69d53b65ff1..4f056c04f75 100644 --- a/management/server/http/api/types.gen.go +++ b/management/server/http/api/types.gen.go @@ -740,6 +740,9 @@ type PolicyUpdate struct { // Rules Policy rule object for policy UI editor Rules []PolicyRuleUpdate `json:"rules"` + + // SourcePostureChecks Posture checks ID's applied to policy source groups + SourcePostureChecks *[]string `json:"source_posture_checks,omitempty"` } // PostureCheck defines model for PostureCheck. diff --git a/management/server/http/policies_handler.go b/management/server/http/policies_handler.go index 7f2c5720baa..e163e63b95e 100644 --- a/management/server/http/policies_handler.go +++ b/management/server/http/policies_handler.go @@ -206,6 +206,10 @@ func (h *Policies) savePolicy( policy.Rules = append(policy.Rules, &pr) } + if req.SourcePostureChecks != nil { + policy.SourcePostureChecks = sourcePostureChecksToStrings(account, *req.SourcePostureChecks) + } + if err := h.accountManager.SavePolicy(account.Id, user.Id, &policy); err != nil { util.WriteError(err, w) return @@ -352,3 +356,17 @@ func groupMinimumsToStrings(account *server.Account, gm []string) []string { } return result } + +func sourcePostureChecksToStrings(account *server.Account, postureChecksIds []string) []string { + result := make([]string, 0, len(postureChecksIds)) + for _, id := range postureChecksIds { + for _, postureCheck := range account.PostureChecks { + if id == postureCheck.ID { + result = append(result, id) + continue + } + } + + } + return result +} diff --git a/management/server/policy.go b/management/server/policy.go index a32b7a618f1..294d699c796 100644 --- a/management/server/policy.go +++ b/management/server/policy.go @@ -163,11 +163,12 @@ func (p *Policy) Copy() *Policy { Description: p.Description, Enabled: p.Enabled, Rules: make([]*PolicyRule, len(p.Rules)), - SourcePostureChecks: p.SourcePostureChecks, + SourcePostureChecks: make([]string, len(p.SourcePostureChecks)), } for i, r := range p.Rules { c.Rules[i] = r.Copy() } + copy(c.SourcePostureChecks, p.SourcePostureChecks) return c }