Skip to content

Commit

Permalink
Allow attaching posture checks to policy
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmmbaga committed Jan 9, 2024
1 parent cdb6394 commit ada0f67
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions management/server/http/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions management/server/http/policies_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion management/server/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ada0f67

Please sign in to comment.