-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding user-id xmlapi command support
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |