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 Aug 19, 2024
1 parent 1b483a1 commit ebcb1d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 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 @@ -30,10 +30,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
23 changes: 18 additions & 5 deletions templates/sdk/service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ return nil, err

{{- if .Entry}}
path, err := loc.XpathWithEntryName(vn, entry.Name)
if err != nil {
return nil, err
}
{{- else}}
path, err := loc.Xpath(vn)
if err != nil {
return nil, err
}
path = path[:len(path)-1]
{{- end}}
if err != nil {
return nil, err
}

{{- if .Entry}}
createSpec, err := specifier(entry)
Expand All @@ -72,10 +76,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

0 comments on commit ebcb1d9

Please sign in to comment.