util

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2024 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

Package util contains various shared structs and functions used across the pango package.

Index

Constants

View Source
const (
	Rulebase     = "rulebase"
	PreRulebase  = "pre-rulebase"
	PostRulebase = "post-rulebase"
)

Rulebase constants for various policies.

View Source
const (
	InterfaceImport     = "interface"
	VirtualRouterImport = "virtual-router"
	VirtualWireImport   = "virtual-wire"
	VlanImport          = "vlan"
)

Valid values to use for VsysImport() or VsysUnimport().

View Source
const (
	MoveSkip = iota
	MoveBefore
	MoveDirectlyBefore
	MoveAfter
	MoveDirectlyAfter
	MoveTop
	MoveBottom
)

These constants are valid move locations to pass to various movement functions (aka - policy management).

View Source
const (
	Get  = "get"
	Show = "show"
)

Valid values to use for any function expecting a pango query type `qt`.

View Source
const (
	EmptyString = ""
	EntryV1     = "entry_v1"
)

Values of general application constants

View Source
const PanosTimeWithoutTimezoneFormat = "2006/01/02 15:04:05"

PanosTimeWithoutTimezoneFormat is a time (missing the timezone) that PAN-OS will give sometimes. Combining this with `Clock()` to get a usable time. report that does not contain

Variables

This section is empty.

Functions

func AsBool

func AsBool(val string) bool

AsBool returns true on yes, else false.

func AsEntryXpath

func AsEntryXpath(vals []string) string

AsEntryXpath returns the given values as an entry xpath segment.

func AsMemberXpath

func AsMemberXpath(vals []string) string

AsMemberXpath returns the given values as a member xpath segment.

func AsXpath

func AsXpath(i interface{}) string

AsXpath makes an xpath out of the given interface.

func CleanRawXml

func CleanRawXml(v string) string

CleanRawXml removes extra XML attributes from RawXml objects without requiring us to have to parse everything.

func CopyStringSlice

func CopyStringSlice(v []string) []string

func CopyTargets

func CopyTargets(v map[string][]string) map[string][]string

func DeviceGroupXpathPrefix

func DeviceGroupXpathPrefix(dg string) []string

DeviceGroupXpathPrefix returns a device group xpath prefix. If the device group is empty, then the default is "shared".

func EntToOneStr

func EntToOneStr(e *EntryType) string

EntToOneStr normalizes an EntryType pointer for a max_items=1 XML node into a string.

func EntToStr

func EntToStr(e *EntryType) []string

EntToStr normalizes an EntryType pointer into a list of strings.

func LogCollectorGroupDeviceXpathPrefix added in v0.10.5

func LogCollectorGroupDeviceXpathPrefix(logcollectorgroup, device string) []string

LogCollectorGroupDeviceXpathPrefix returns the logcollector xpath prefix of the given logcollector name.

func LogCollectorGroupXpathPrefix added in v0.10.5

func LogCollectorGroupXpathPrefix(logcollectorgroup string) []string

LogCollectorGroupXpathPrefix returns the logcollector xpath prefix of the given logcollector name.

func LogCollectorXpathPrefix added in v0.10.5

func LogCollectorXpathPrefix(logcollector string) []string

LogCollectorXpathPrefix returns the logcollector xpath prefix of the given logcollector name.

func MemToOneStr

func MemToOneStr(e *MemberType) string

MemToOneStr normalizes a MemberType pointer for a max_items=1 XML node into a string.

func MemToStr

func MemToStr(e *MemberType) []string

MemToStr normalizes a MemberType pointer into a list of strings.

func NewHitCountRequest

func NewHitCountRequest(rulebase, vsys string, rules []string) interface{}

NewHitCountRequest returns a new hit count request struct.

If the rules param is nil, then the hit count for all rules is returned.

func OrderedListsMatch

func OrderedListsMatch(a, b []string) bool

func PanoramaXpathPrefix

func PanoramaXpathPrefix() []string

PanoramaXpathPrefix returns the panorama xpath prefix.

func RefactorElement added in v0.11.0

func RefactorElement(str string) string

RefactorElement for removing default struct tag name in case it was auto append

func RelativeMovement

func RelativeMovement(v int) bool

RelativeMovement returns if the movement constant is a relative movement.

func StripPanosPackaging

func StripPanosPackaging(input []byte, tag string) []byte

StripPanosPackaging removes the response / result and an optional third containing XML tag from the given byte slice.

func TargetsMatch

func TargetsMatch(a, b map[string][]string) bool

func TemplateXpathPrefix

func TemplateXpathPrefix(tmpl, ts string) []string

TemplateXpathPrefix returns the template xpath prefix of the given template name.

func UnorderedListsMatch

func UnorderedListsMatch(a, b []string) bool

func ValidMovement

func ValidMovement(v int) bool

ValidMovement returns if the movement constant is valid or not.

func ValidateRulebase

func ValidateRulebase(dg, base string) error

ValidateRulebase validates the device group and rulebase pairing for Panorama policies.

func VsysEntToMap

func VsysEntToMap(ve *VsysEntryType) map[string][]string

VsysEntToMap normalizes a VsysEntryType pointer into a map.

func VsysXpathPrefix

func VsysXpathPrefix(vsys string) []string

VsysXpathPrefix returns a vsys xpath prefix.

func YesNo

func YesNo(v bool) string

YesNo returns "yes" on true, "no" on false.

Types

type Actioner

type Actioner interface {
	Action() string
}

type BasicJob

type BasicJob struct {
	XMLName     xml.Name        `xml:"response"`
	Result      string          `xml:"result>job>result"`
	Progress    uint            `xml:"-"`
	Details     BasicJobDetails `xml:"result>job>details"`
	Devices     []devJob        `xml:"result>job>devices>entry"`
	Status      string          `xml:"result>job>status"` // For log retrieval jobs.
	ProgressRaw string          `xml:"result>job>progress"`
}

BasicJob is a struct for parsing minimal information about a submitted job to PANOS.

func (*BasicJob) UnmarshalXML

func (o *BasicJob) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type BasicJobDetails

type BasicJobDetails struct {
	Lines []LineOrCdata `xml:"line"`
}

func (*BasicJobDetails) String

func (o *BasicJobDetails) String() string

type BulkElement

type BulkElement struct {
	XMLName xml.Name
	Data    []interface{}
}

BulkElement is a generic bulk container for bulk operations.

func (BulkElement) Config

func (o BulkElement) Config() interface{}

Config returns an interface to be Marshaled.

type CdataText

type CdataText struct {
	Text string `xml:",cdata"`
}

CdataText is for getting CDATA contents of XML docs.

type Elementer

type Elementer interface {
	Element() interface{}
}

Elementer is an interface for commits.

type Entry

type Entry struct {
	XMLName xml.Name `xml:"entry"`
	Value   string   `xml:"name,attr"`
}

Entry is a standalone entry struct.

type EntryType

type EntryType struct {
	Entries []Entry `xml:"entry"`
}

EntryType defines an entry config node used for sending and receiving XML from PAN-OS.

func OneStrToEnt

func OneStrToEnt(e string) *EntryType

OneStrToEnt converts a string into an EntryType pointer for a max_items=1 XML node.

func StrToEnt

func StrToEnt(e []string) *EntryType

StrToEnt converts a list of strings into an EntryType pointer.

type HitCount

type HitCount struct {
	Name                      string `xml:"name,attr"`
	Latest                    string `xml:"latest"`
	HitCount                  uint   `xml:"hit-count"`
	LastHitTimestamp          int    `xml:"last-hit-timestamp"`
	LastResetTimestamp        int    `xml:"last-reset-timestamp"`
	FirstHitTimestamp         int    `xml:"first-hit-timestamp"`
	RuleCreationTimestamp     int    `xml:"rule-creation-timestamp"`
	RuleModificationTimestamp int    `xml:"rule-modification-timestamp"`
}

HitCount is the hit count data for a specific rule.

type HitCountResponse

type HitCountResponse struct {
	XMLName xml.Name   `xml:"response"`
	Results []HitCount `xml:"result>rule-hit-count>vsys>entry>rule-base>entry>rules>entry"`
}

HitCountResponse is the hit count response struct.

type JobResponse

type JobResponse struct {
	XMLName xml.Name `xml:"response"`
	Id      uint     `xml:"result>job"`
}

JobResponse parses a XML response that includes a job ID.

type License

type License struct {
	XMLName     xml.Name `xml:"entry"`
	Feature     string   `xml:"feature"`
	Description string   `xml:"description"`
	Serial      string   `xml:"serial"`
	Issued      string   `xml:"issued"`
	Expires     string   `xml:"expires"`
	Expired     string   `xml:"expired"`
	AuthCode    string   `xml:"authcode"`
}

License defines a license entry.

type LineOrCdata

type LineOrCdata struct {
	Cdata *string `xml:",cdata"`
	Text  *string `xml:",chardata"`
}

type Lock

type Lock struct {
	XMLName  xml.Name  `xml:"entry"`
	Owner    string    `xml:"name,attr"`
	Name     string    `xml:"name"`
	Type     string    `xml:"type"`
	LoggedIn string    `xml:"loggedin"`
	Comment  CdataText `xml:"comment"`
}

Lock represents either a config lock or a commit lock.

type Member

type Member struct {
	XMLName xml.Name `xml:"member"`
	Value   string   `xml:",chardata"`
}

Member defines a member config node used for sending and receiving XML from PANOS.

type MemberType

type MemberType struct {
	Members []Member `xml:"member"`
}

MemberType defines a member config node used for sending and receiving XML from PAN-OS.

func OneStrToMem

func OneStrToMem(e string) *MemberType

OneStrToMem converts a string into a MemberType pointer for a max_items=1 XML node.

func StrToMem

func StrToMem(e []string) *MemberType

StrToMem converts a list of strings into a MemberType pointer.

type RawXml

type RawXml struct {
	Text string `xml:",innerxml"`
}

RawXml is what allows the use of Edit commands on a XPATH without truncating any other child objects that may be attached to it.

type Retriever

type Retriever func(interface{}, interface{}, interface{}) ([]byte, error)

Retriever is a type that is intended to act as a stand-in for using either the Get or Show pango Client functions.

type VsysEntry

type VsysEntry struct {
	XMLName xml.Name   `xml:"entry"`
	Serial  string     `xml:"name,attr"`
	Vsys    *EntryType `xml:"vsys"`
}

VsysEntry defines the "vsys" xpath node under a VsysEntryType config node.

type VsysEntryType

type VsysEntryType struct {
	Entries []VsysEntry `xml:"entry"`
}

VsysEntryType defines an entry config node with vsys entries underneath.

func MapToVsysEnt

func MapToVsysEnt(e map[string][]string) *VsysEntryType

MapToVsysEnt converts a map into a VsysEntryType pointer.

This struct is used for "Target" information on Panorama when dealing with various policies. Maps are unordered, but FWICT Panorama doesn't seem to order anything anyways when doing things in the GUI, so hopefully this is ok...?

type XapiClient

type XapiClient interface {
	String() string
	Versioning() version.Number
	Plugins() []plugin.Info

	// Logging functions.
	LogAction(string, ...interface{})
	LogQuery(string, ...interface{})
	LogOp(string, ...interface{})
	LogUid(string, ...interface{})
	LogLog(string, ...interface{})
	LogExport(string, ...interface{})
	LogImport(string, ...interface{})

	// PAN-OS API calls.
	Op(interface{}, string, interface{}, interface{}) ([]byte, error)
	Show(interface{}, interface{}, interface{}) ([]byte, error)
	Get(interface{}, interface{}, interface{}) ([]byte, error)
	Delete(interface{}, interface{}, interface{}) ([]byte, error)
	Set(interface{}, interface{}, interface{}, interface{}) ([]byte, error)
	Edit(interface{}, interface{}, interface{}, interface{}) ([]byte, error)
	Move(interface{}, string, string, interface{}, interface{}) ([]byte, error)
	Log(string, string, string, string, int, int, interface{}, interface{}) ([]byte, error)
	Export(string, time.Duration, interface{}, interface{}) (string, []byte, error)
	Import(string, string, string, string, time.Duration, interface{}, interface{}) ([]byte, error)
	Commit(interface{}, string, interface{}) (uint, []byte, error)
	Uid(interface{}, string, interface{}, interface{}) ([]byte, error)

	// Vsys importables.
	VsysImport(string, string, string, string, []string) error
	VsysUnimport(string, string, string, []string) error

	// Extras.
	EntryListUsing(Retriever, []string) ([]string, error)
	MemberListUsing(Retriever, []string) ([]string, error)
	RequestPasswordHash(string) (string, error)
	WaitForJob(uint, time.Duration, interface{}, interface{}) error
	WaitForLogs(uint, time.Duration, time.Duration, interface{}) ([]byte, error)
	Clock() (time.Time, error)
	PositionFirstEntity(int, string, string, []string, []string) error
	ConfigTree() *XmlNode
}

XapiClient is the interface that describes an pango.Client.

type XmlNode

type XmlNode struct {
	XMLName    xml.Name
	Attributes []xml.Attr `xml:",any,attr"`
	Text       []byte     `xml:",innerxml"`
	Nodes      []XmlNode  `xml:",any"`
}

XmlNode is a generic XML node.

func FindXmlNodeInTree

func FindXmlNodeInTree(path []string, elm *XmlNode) *XmlNode

FindXmlNodeInTree finds a given path in the specified XmlNode tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL