From 16c174dbc409ed863b6a8b5eb3a185610063f101 Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Wed, 17 Sep 2025 17:25:38 +0200 Subject: [PATCH] fix(codegen): Make audit comment code generation optional based on locations That's still temporary solution, but will allow us to implement panos_default_security_policy resource --- pkg/properties/normalized.go | 12 ++++++++++++ templates/sdk/service.tmpl | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/properties/normalized.go b/pkg/properties/normalized.go index e25b7cfa..af855fe8 100644 --- a/pkg/properties/normalized.go +++ b/pkg/properties/normalized.go @@ -1562,6 +1562,18 @@ func (spec *Normalization) HasEntryName() bool { return spec.Entry != nil } +func (spec *Normalization) HasAuditComments() bool { + var hasVsysLocation bool + for _, location := range spec.Locations { + if location.Name.CamelCase == "Vsys" { + hasVsysLocation = true + break + } + } + + return hasVsysLocation && spec.HasEntryUuid() +} + func (spec *Normalization) HasEntryUuid() bool { _, found := spec.Spec.Params["uuid"] return found diff --git a/templates/sdk/service.tmpl b/templates/sdk/service.tmpl index c25f43f5..7efcdafa 100644 --- a/templates/sdk/service.tmpl +++ b/templates/sdk/service.tmpl @@ -2,13 +2,21 @@ package {{packageName .GoSdkPath}} {{- if .Entry}} {{- if $.Imports}} {{- if $.Spec.Params.uuid}} + {{- if $.HasAuditComments }} {{renderImports "service" "filtering" "sync" "audit" "rule" "version" "movement"}} + {{- else }} + {{renderImports "service" "filtering" "sync" "rule" "version" "movement"}} + {{- end }} {{- else}} {{renderImports "service" "filtering" "sync"}} {{- end}} {{- else}} {{- if $.Spec.Params.uuid}} + {{- if $.HasAuditComments }} {{renderImports "service" "filtering" "audit" "movement"}} + {{- else }} + {{renderImports "service" "filtering" "movement"}} + {{- end }} {{- else}} {{renderImports "service" "filtering"}} {{- end}} @@ -793,7 +801,7 @@ func (s *Service) filterEntriesByLocation(location Location, entries []*Entry) [ return filtered } -{{- if $.Spec.Params.uuid}} +{{- if $.Spec.Params.uuid }} // MoveGroup arranges the given rules in the order specified. // Any rule with a UUID specified is ignored. // Only the rule names are considered for the purposes of the rule placement. @@ -853,7 +861,7 @@ func (s *Service) MoveGroup(ctx context.Context, loc Location, position movement return nil } - + {{- if $.HasAuditComments }} // HITCOUNT returns the hit count for the given rule. func (s *Service) HitCount(ctx context.Context, loc Location, rules ...string) ([]util.HitCount, error) { switch { @@ -873,7 +881,7 @@ func (s *Service) MoveGroup(ctx context.Context, loc Location, position movement return nil, fmt.Errorf("unsupported location") } - + // SetAuditComment sets the given audit comment for the given rule. func (s *Service) SetAuditComment(ctx context.Context, loc Location, name, comment string) error { if name == "" { @@ -989,6 +997,7 @@ func (s *Service) MoveGroup(ctx context.Context, loc Location, position movement } return resp.Comments, nil - } + } {{- end}} + {{- end }} {{- end}}