Documentation ¶
Index ¶
- type Driver
- func (d *Driver) AcquirePriv(target string) error
- func (d *Driver) Close() error
- func (d *Driver) Open() error
- func (d *Driver) SendCommand(command string, opts ...util.Option) (*response.Response, error)
- func (d *Driver) SendCommands(commands []string, opts ...util.Option) (*response.MultiResponse, error)
- func (d *Driver) SendCommandsFromFile(f string, opts ...util.Option) (*response.MultiResponse, error)
- func (d *Driver) SendConfig(config string, opts ...util.Option) (*response.Response, error)
- func (d *Driver) SendConfigs(configs []string, opts ...util.Option) (*response.MultiResponse, error)
- func (d *Driver) SendConfigsFromFile(f string, opts ...util.Option) (*response.MultiResponse, error)
- func (d *Driver) SendInteractive(events []*channel.SendInteractiveEvent, opts ...util.Option) (*response.Response, error)
- func (d *Driver) UpdatePrivileges()
- type OperationOptions
- type PrivilegeLevel
- type PrivilegeLevels
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct { *generic.Driver AuthSecondary string PrivilegeLevels map[string]*PrivilegeLevel DefaultDesiredPriv string CurrentPriv string OnOpen func(d *Driver) error OnClose func(d *Driver) error // contains filtered or unexported fields }
Driver embeds generic.Driver and adds "network" centric functionality including privilege level understanding and escalation/deescalation.
func NewDriver ¶ added in v1.0.0
NewDriver returns an instance of Driver for the provided host with the given options set. Any options in the driver/options package may be passed to this function -- those options may be applied at the network.Driver, generic.Driver, channel.Channel, or Transport depending on the specific option.
func (*Driver) AcquirePriv ¶
AcquirePriv acquires the privilege level target. This method will handle any escalation or deescalation necessary to acquire the requested privilege level including any authentication that may be required.
func (*Driver) Close ¶
Close closes the underlying generic.Driver and by extension the channel.Channel and Transport objects.
func (*Driver) Open ¶
Open opens the underlying generic.Driver, and by extension the channel.Channel and Transport objects. This should be called prior to executing any SendX methods of the Driver.
func (*Driver) SendCommand ¶
SendCommand sends the command string to the device and returns a response.Response object. This method will always ensure that the Driver CurrentPriv value is the DefaultDesiredPriv before sending any command. If the privilege level is *not* the DefaultDesiredPriv (which is typically "privilege-exec" or "exec"), AcquirePriv will be called with a target privilege level of DefaultDesiredPriv.
func (*Driver) SendCommands ¶
func (d *Driver) SendCommands( commands []string, opts ...util.Option, ) (*response.MultiResponse, error)
SendCommands sends the command strings to the device and returns a response.MultiResponse object. This method will always ensure that the Driver CurrentPriv value is the DefaultDesiredPriv before sending any command. If the privilege level is *not* the DefaultDesiredPriv (which is typically "privilege-exec" or "exec"), AcquirePriv will be called with a target privilege level of DefaultDesiredPriv.
func (*Driver) SendCommandsFromFile ¶
func (d *Driver) SendCommandsFromFile( f string, opts ...util.Option, ) (*response.MultiResponse, error)
SendCommandsFromFile is a convenience wrapper to send each line of file f as a command via the SendCommands method.
func (*Driver) SendConfig ¶
SendConfig is a convenience wrapper around SendConfigs. This method accepts a config string which is split on new lines and sent as configLines to SendConfigs. The resulting response.MultiResponse is then collapsed into a single response.Response object.
func (*Driver) SendConfigs ¶
func (d *Driver) SendConfigs( configs []string, opts ...util.Option, ) (*response.MultiResponse, error)
SendConfigs sends a list of configs to the device. This method will auto acquire the "configuration" privilege level. If your device does *not* have a "configuration" privilege level this will fail. If your device has multiple "flavors" of configuration level (i.e. exclusive or private) you can acquire that target privilege level for the configuration option by passing the opoptions.WithPrivilegeLevel with the requested privilege level set.
func (*Driver) SendConfigsFromFile ¶
func (d *Driver) SendConfigsFromFile( f string, opts ...util.Option, ) (*response.MultiResponse, error)
SendConfigsFromFile is a convenience wrapper that sends the lines of file f as config lines via SendConfigs.
func (*Driver) SendInteractive ¶
func (d *Driver) SendInteractive( events []*channel.SendInteractiveEvent, opts ...util.Option, ) (*response.Response, error)
SendInteractive sends a slice of channel.SendInteractiveEvent to the device. This method wraps the generic driver level SendInteractive but handles acquiring the desired privilege level prior to returning the generic driver method.
func (*Driver) UpdatePrivileges ¶ added in v1.0.0
func (d *Driver) UpdatePrivileges()
UpdatePrivileges refreshes the Driver's internal privilege map, the map that is used to determine appropriate next steps during privilege escalation/deescalation. Any time a user modifies the Driver PrivilegeLevels this method should be called as it will regenerate the base channel.Channel prompt pattern to include all privilege level patterns in the PrivilegeLevels map, thus ensuring we can always "find" a prompt.
type OperationOptions ¶ added in v1.0.0
type OperationOptions struct {
PrivilegeLevel string
}
OperationOptions is a struct containing "operation" options that are relevant to the network Driver, for example providing a target privilege level for a SendInteractive operation.
func NewOperation ¶ added in v1.0.0
func NewOperation(options ...util.Option) (*OperationOptions, error)
NewOperation returns a new OperationOptions object with the defaults set and any provided options applied.
type PrivilegeLevel ¶ added in v1.0.0
type PrivilegeLevel struct { Name string `yaml:"name"` Pattern string `yaml:"pattern"` NotContains []string `yaml:"not-contains"` PreviousPriv string `yaml:"previous-priv"` Deescalate string `yaml:"deescalate"` Escalate string `yaml:"escalate"` EscalateAuth bool `yaml:"escalate-auth"` EscalatePrompt string `yaml:"escalate-prompt"` // contains filtered or unexported fields }
PrivilegeLevel defines a privilege level, including a name, the pattern used to match a prompt output to the privilege level, as well as information about how to escalate into and deescalate out of this privilege level.
type PrivilegeLevels ¶ added in v1.0.0
type PrivilegeLevels map[string]*PrivilegeLevel
PrivilegeLevels is a type alias for the map of privilege levels that gets assigned to a network Driver object.