Skip to content

Commit

Permalink
Update assets from branch develop of pango repository
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianczech committed Apr 3, 2024
1 parent 04b5609 commit 204efb6
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 16 deletions.
2 changes: 2 additions & 0 deletions assets/errors/panos.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
var InvalidFilterError = stderr.New("filter is improperly formatted")
var NameNotSpecifiedError = stderr.New("name is not specified")
var NoLocationSpecifiedError = stderr.New("no location specified")
var RelativePositionWithRemoveEverythingElseError = stderr.New("cannot do relative positioning when removing all other rules")
var UnrecognizedOperatorError = stderr.New("unsupported filter operator")
var UnsupportedFilterTypeError = stderr.New("unsupported type for filtering")
var UuidNotSpecifiedError = stderr.New("uuid is not specified")

// Panos is an error returned from PAN-OS.
//
Expand Down
18 changes: 8 additions & 10 deletions assets/sdk/xmlapiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,14 +898,14 @@ func (c *XmlApiClient) ImportFile(ctx context.Context, cmd *xmlapi.Import, conte
}

// ExportFile retrieves a file from PAN-OS.
func (c *XmlApiClient) ExportFile(ctx context.Context, cmd *xmlapi.Export, ans any) (string, []byte, error) {
func (c *XmlApiClient) ExportFile(ctx context.Context, cmd *xmlapi.Export, ans any) (string, []byte, *http.Response, error) {
if cmd == nil {
return "", nil, fmt.Errorf("cmd is nil")
return "", nil, nil, fmt.Errorf("cmd is nil")
}

data, err := cmd.AsUrlValues()
if err != nil {
return "", nil, err
return "", nil, nil, err
}

if c.ApiKeyInRequest && c.ApiKey != "" && data.Get("key") == "" {
Expand All @@ -914,12 +914,12 @@ func (c *XmlApiClient) ExportFile(ctx context.Context, cmd *xmlapi.Export, ans a

req, err := http.NewRequestWithContext(ctx, "POST", c.api_url, strings.NewReader(data.Encode()))
if err != nil {
return "", nil, err
return "", nil, nil, err
}

b, resp, err := c.sendRequest(ctx, req, false, ans)
if err != nil {
return "", b, err
return "", b, resp, err
}

var filename string
Expand All @@ -928,7 +928,7 @@ func (c *XmlApiClient) ExportFile(ctx context.Context, cmd *xmlapi.Export, ans a
filename = params["filename"]
}

return filename, b, nil
return filename, b, resp, nil
}

// GetTechSupportFile returns the tech support file .tgz file.
Expand All @@ -950,7 +950,7 @@ func (c *XmlApiClient) GetTechSupportFile(ctx context.Context) (string, []byte,
for {
resp = util.BasicJob{}

if _, _, err = c.ExportFile(ctx, cmd, &resp); err != nil {
if _, _, _, err = c.ExportFile(ctx, cmd, &resp); err != nil {
return "", nil, err
}

Expand All @@ -974,7 +974,7 @@ func (c *XmlApiClient) GetTechSupportFile(ctx context.Context) (string, []byte,

cmd.Action = "get"

filename, b, err := c.ExportFile(ctx, cmd, nil)
filename, b, _, err := c.ExportFile(ctx, cmd, nil)
return filename, b, err
}

Expand Down Expand Up @@ -1036,8 +1036,6 @@ func (c *XmlApiClient) sendRequest(ctx context.Context, req *http.Request, strip
}
}

// log.Printf("REPLY: %s\n", string(body))

if ans == nil {
return body, resp, nil
}
Expand Down
44 changes: 41 additions & 3 deletions assets/util/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TargetsMatch(a, b map[string][]string) bool {
return true
}

func OptionalStringsMatch(a, b *string) bool {
func StringsMatch(a, b *string) bool {
if a == nil && b == nil {
return true
} else if a == nil || b == nil {
Expand All @@ -71,6 +71,44 @@ func OptionalStringsMatch(a, b *string) bool {
return *a == *b
}

func StringsMatch(a, b string) bool {
return a == b
func BoolsMatch(a, b *bool) bool {
if a == nil && b == nil {
return true
} else if a == nil || b == nil {
return false
}

return *a == *b
}

func FloatsMatch(a, b *float64) bool {
if a == nil && b == nil {
return true
} else if a == nil || b == nil {
return false
}

return *a == *b
}

func IntsMatch(a, b *int64) bool {
if a == nil && b == nil {
return true
} else if a == nil || b == nil {
return false
}

return *a == *b
}

func AnysMatch(a, b any) bool {
if a == nil && b == nil {
return true
}

if a == nil || b == nil {
return false
}

return true
}
2 changes: 1 addition & 1 deletion assets/util/pangoclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type PangoClient interface {
// Specialized communication functions around specific XPI API commands.
MultiConfig(context.Context, *xmlapi.MultiConfig, bool, url.Values) ([]byte, *http.Response, *xmlapi.MultiConfigResponse, error)
ImportFile(context.Context, *xmlapi.Import, string, string, string, bool, any) ([]byte, *http.Response, error)
ExportFile(context.Context, *xmlapi.Export, any) (string, []byte, error)
ExportFile(context.Context, *xmlapi.Export, any) (string, []byte, *http.Response, error)

// Operational functions in use by one or more resources / data sources / namespaces.
RequestPasswordHash(context.Context, string) (string, error)
Expand Down
23 changes: 23 additions & 0 deletions assets/util/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package util

// For reference: https://github.com/golang/go/issues/45624

// Bool returns a pointer to the given bool.
func Bool(v bool) *bool {
return &v
}

// Int returns a pointer to the given int64.
func Int(v int64) *int64 {
return &v
}

// Float returns a pointer to the given float64.
func Float(v float64) *float64 {
return &v
}

// String returns a pointer to the given string.
func String(v string) *string {
return &v
}
5 changes: 5 additions & 0 deletions assets/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func AsEntryXpath(vals []string) string {
return buf.String()
}

// AsUuidXpath returns an xpath segment as a UUID location.
func AsUuidXpath(v string) string {
return fmt.Sprintf("entry[@uuid='%s']", v)
}

// AsMemberXpath returns the given values as a member xpath segment.
func AsMemberXpath(vals []string) string {
var buf bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion pkg/translate/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func specMatchFunctionName(parent []string, param *properties.SpecParam) string
if param.Type == "list" {
return "util.OrderedListsMatch"
} else if param.Type == "string" {
return "util.OptionalStringsMatch"
return "util.StringsMatch"
} else {
return fmt.Sprintf("specMatch%s%s", strings.Join(parent, ""), param.Name.CamelCase)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/translate/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestSpecMatchesFunction(t *testing.T) {
calculatedSpecMatchFunctionListString := SpecMatchesFunction(&paramTypeListString)

// then
assert.Equal(t, "util.OptionalStringsMatch", calculatedSpecMatchFunctionString)
assert.Equal(t, "util.StringsMatch", calculatedSpecMatchFunctionString)
assert.Equal(t, "util.OrderedListsMatch", calculatedSpecMatchFunctionListString)
}

Expand Down

0 comments on commit 204efb6

Please sign in to comment.