Skip to content

Commit

Permalink
Don't use partial XPath when sending "set" config operations
Browse files Browse the repository at this point in the history
Support for partial XPaths have been removed in PAN-OS 11.0.3-h3, and
full XPaths are supported across all PAN-OS versions we're targetting.
  • Loading branch information
kklimonda-cl committed Jul 29, 2024
1 parent 11eb059 commit 12be24f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
15 changes: 15 additions & 0 deletions assets/pango/xml/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package xml

import "bytes"

func StripEntryElement(data []byte) []byte {
if !bytes.HasPrefix(data, []byte("<entry")) || !bytes.HasSuffix(data, []byte("</entry>")) {
return data
}

var startIdx, endIdx int
startIdx = bytes.Index(data, []byte(">"))
endIdx = len(data) - len("</entry>")

return data[startIdx+1 : endIdx]
}
2 changes: 2 additions & 0 deletions pkg/translate/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ func RenderImports(templateTypes ...string) (string, error) {
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/version", "")
case "service":
manager.AddStandardImport("context", "")
manager.AddStandardImport("encoding/xml", "")
manager.AddStandardImport("fmt", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/errors", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/util", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/xmlapi", "")
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/xml", "pangoxml")
case "filtering":
manager.AddSdkImport("github.com/PaloAltoNetworks/pango/filtering", "")
case "audit":
Expand Down
15 changes: 12 additions & 3 deletions templates/sdk/service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ if err != nil {
return nil, err
}

data, err := xml.Marshal(createSpec)
if err != nil {
return nil, err
}

// Optionally remove top entry element from marshalled data to fullfill
// PAN-OS API requirements.
data = pangoxml.StripEntryElement(data)

cmd := &xmlapi.Config{
Action: "set",
Xpath: util.AsXpath(path[:len(path)-1]),
Element: createSpec,
Xpath: util.AsXpath(path),
Element: string(data),
Target: s.client.GetTarget(),
}

Expand Down Expand Up @@ -1302,4 +1311,4 @@ func (s *Service) RemoveFromImport(ctx context.Context, loc Location, entry Entr
return resp.Comments, nil
}
{{- end}}
{{- end}}
{{- end}}

0 comments on commit 12be24f

Please sign in to comment.