From 638262802beb8f9197bccda2cd5106438891d734 Mon Sep 17 00:00:00 2001 From: Garfield Lee Freeman Date: Fri, 8 Mar 2024 16:07:16 +0100 Subject: [PATCH] adding user-id xmlapi command support --- xmlapi/userid.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 xmlapi/userid.go diff --git a/xmlapi/userid.go b/xmlapi/userid.go new file mode 100644 index 0000000..73c0774 --- /dev/null +++ b/xmlapi/userid.go @@ -0,0 +1,50 @@ +package xmlapi + +import ( + "fmt" + "net/url" +) + +// UserId performs a type=user-id XML API action. +type UserId struct { + // The comamnd to execute. This can be a properly formatting XML string, + // a fmt.Stringer, or a struct that can mer marshalled into XML. + Command any + + // The vsys to send the command to. + Vsys string + + // The target, copied from the client connection. + Target string + + // Any extra params that need to be specified should be put here. + Extras url.Values +} + +// AsUrlValues returns the full API command as url.Values to send to PAN-OS. +func (c *UserId) AsUrlValues() (url.Values, error) { + if c.Command == nil { + return nil, fmt.Errorf("no command specified") + } + + data := url.Values{} + data.Set("type", "user-id") + + if err := addToData("cmd", c.Command, true, &data); err != nil { + return nil, err + } + + if c.Vsys != "" { + data.Set("vsys", c.Vsys) + } + + if c.Target != "" { + data.Set("target", c.Target) + } + + for key := range c.Extras { + data.Set(key, c.Extras.Get(key)) + } + + return data, nil +}