Skip to content

Commit

Permalink
feat(alzlib): add ordered output for policy assignment default vals (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF authored Oct 3, 2024
1 parent 0fe3d7a commit 59b345f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
28 changes: 27 additions & 1 deletion defaultPolicyAssignmentValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

package alzlib

import mapset "github.com/deckarep/golang-set/v2"
import (
"maps"
"slices"

mapset "github.com/deckarep/golang-set/v2"
)

// PolicyAssignmentsParameterValues is a map of default names to DefaultPolicyAssignmentValuesValue.
// It is used to map a single value to multiple policy assignments.
Expand Down Expand Up @@ -47,3 +52,24 @@ func (d DefaultPolicyAssignmentValuesValue) copy() DefaultPolicyAssignmentValues
}
return newVal
}

// Assignments returns a sorted list of assignment names.
func (d DefaultPolicyAssignmentValuesValue) Assignments() []string {
result := make([]string, 0, len(d))
for s := range maps.Keys(d) {
result = append(result, s)
}
slices.Sort(result)
return result
}

// Assignments returns a sorted list of parameter names.
func (d DefaultPolicyAssignmentValuesValue) AssignmentParameters(name string) []string {
if _, ok := d[name]; !ok {
return nil
}
v := d[name]
s := v.ToSlice()
slices.Sort(s)
return s
}
7 changes: 4 additions & 3 deletions internal/doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ func alzlibReadmeMdPolicyDefaultValues(md *markdown.Markdown, az *alzlib.AlzLib)
if len(pdvs) == 0 {
return md
}
slices.Sort(pdvs)

md = md.H2("Policy Default Values").LF().PlainText("The following policy default values are available in this library:").LF()
for _, pdv := range pdvs {
md = md.H3("default name `" + pdv + "`").LF()
for assignment, params := range az.PolicyDefaultValue(pdv) {
for _, assignment := range az.PolicyDefaultValue(pdv).Assignments() {
params := az.PolicyDefaultValue(pdv).AssignmentParameters(assignment)
md = md.H4("assignment `"+assignment+"`").LF().
Details(fmt.Sprintf("%d parameter names", params.Cardinality()), "\n- "+strings.Join(params.ToSlice(), "\n- ")).LF()
Details(fmt.Sprintf("%d parameter names", len(params)), "\n- "+strings.Join(params, "\n- ")).LF()
}
}
return md
Expand Down

0 comments on commit 59b345f

Please sign in to comment.