Documentation
¶
Index ¶
- Variables
- type AuthenticationType
- type Client
- func (c *Client) GetAddress() string
- func (c *Client) GetModel() Model
- func (c *Client) IsAuthenticated() bool
- func (c *Client) Login(ctx context.Context, password string) error
- func (c *Client) LoginAuto(ctx context.Context) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) POE() *POEManager
- func (c *Client) Ports() *PortManager
- type ClientOption
- type EnvironmentPasswordManager
- type Error
- func NewAuthError(message string, cause error) *Error
- func NewError(errorType ErrorType, message string, cause error) *Error
- func NewModelError(message string, cause error) *Error
- func NewNetworkError(message string, cause error) *Error
- func NewOperationError(message string, cause error) *Error
- func NewParsingError(message string, cause error) *Error
- type ErrorType
- type FileTokenManager
- type MemoryTokenManager
- type Model
- type POELimitType
- type POEManager
- func (m *POEManager) CyclePower(ctx context.Context, portIDs ...int) error
- func (m *POEManager) DisablePort(ctx context.Context, portID int) error
- func (m *POEManager) EnablePort(ctx context.Context, portID int) error
- func (m *POEManager) GetPortSettings(ctx context.Context, portID int) (*POEPortSettings, error)
- func (m *POEManager) GetPortStatus(ctx context.Context, portID int) (*POEPortStatus, error)
- func (m *POEManager) GetSettings(ctx context.Context) ([]POEPortSettings, error)
- func (m *POEManager) GetStatus(ctx context.Context) ([]POEPortStatus, error)
- func (m *POEManager) SetPortMode(ctx context.Context, portID int, mode POEMode) error
- func (m *POEManager) SetPortPowerLimit(ctx context.Context, portID int, limitType POELimitType, limitW float64) error
- func (m *POEManager) SetPortPriority(ctx context.Context, portID int, priority POEPriority) error
- func (m *POEManager) UpdatePort(ctx context.Context, updates ...POEPortUpdate) error
- type POEMode
- type POEPortSettings
- type POEPortStatus
- type POEPortUpdate
- type POEPriority
- type PasswordManager
- type PortManager
- func (m *PortManager) DisablePort(ctx context.Context, portID int) error
- func (m *PortManager) EnablePort(ctx context.Context, portID int) error
- func (m *PortManager) GetPortSettings(ctx context.Context, portID int) (*PortSettings, error)
- func (m *PortManager) GetSettings(ctx context.Context) ([]PortSettings, error)
- func (m *PortManager) SetPortFlowControl(ctx context.Context, portID int, enabled bool) error
- func (m *PortManager) SetPortLimits(ctx context.Context, portID int, ingressLimit, egressLimit string) error
- func (m *PortManager) SetPortName(ctx context.Context, portID int, name string) error
- func (m *PortManager) SetPortSpeed(ctx context.Context, portID int, speed PortSpeed) error
- func (m *PortManager) UpdatePort(ctx context.Context, updates ...PortUpdate) error
- type PortSettings
- type PortSpeed
- type PortStatus
- type PortUpdate
- type SwitchConfig
- type TokenManager
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotAuthenticated = &Error{Type: ErrorTypeAuth, Message: "not authenticated"} ErrSessionExpired = &Error{Type: ErrorTypeAuth, Message: "session expired"} ErrModelNotSupported = &Error{Type: ErrorTypeModel, Message: "model not supported"} ErrModelNotDetected = &Error{Type: ErrorTypeModel, Message: "could not detect switch model"} ErrInvalidCredentials = &Error{Type: ErrorTypeAuth, Message: "invalid credentials"} ErrNetworkTimeout = &Error{Type: ErrorTypeNetwork, Message: "network timeout"} ErrInvalidResponse = &Error{Type: ErrorTypeParsing, Message: "invalid response format"} )
Sentinel errors
Functions ¶
This section is empty.
Types ¶
type AuthenticationType ¶
type AuthenticationType string
AuthenticationType represents the type of authentication used
const ( AuthTypeSession AuthenticationType = "session" // Cookie-based (30x series) AuthTypeGambit AuthenticationType = "gambit" // URL parameter-based (316 series) )
func GetAuthenticationType ¶
func GetAuthenticationType(model Model) AuthenticationType
GetAuthenticationType returns the authentication type for a model
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a connection to a Netgear switch
func NewClient ¶
func NewClient(address string, opts ...ClientOption) (*Client, error)
NewClient creates a new Netgear switch client
func (*Client) GetAddress ¶
GetAddress returns the switch address
func (*Client) IsAuthenticated ¶
IsAuthenticated returns true if the client has a valid token
func (*Client) Ports ¶
func (c *Client) Ports() *PortManager
Ports returns the port management interface
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client
func WithEnvironmentAuth ¶
func WithEnvironmentAuth(enabled bool) ClientOption
WithEnvironmentAuth enables/disables environment variable password lookup
func WithPasswordManager ¶
func WithPasswordManager(pm PasswordManager) ClientOption
WithPasswordManager sets a custom password manager
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the HTTP timeout
func WithTokenManager ¶
func WithTokenManager(tm TokenManager) ClientOption
WithTokenManager sets a custom token manager
type EnvironmentPasswordManager ¶
type EnvironmentPasswordManager struct {
// contains filtered or unexported fields
}
EnvironmentPasswordManager handles password resolution from environment variables
func NewEnvironmentPasswordManager ¶
func NewEnvironmentPasswordManager() *EnvironmentPasswordManager
NewEnvironmentPasswordManager creates a new environment-based password manager
func NewEnvironmentPasswordManagerWithVerbose ¶
func NewEnvironmentPasswordManagerWithVerbose(verbose bool) *EnvironmentPasswordManager
NewEnvironmentPasswordManagerWithVerbose creates a new environment-based password manager with verbose logging
func (*EnvironmentPasswordManager) GetPassword ¶
func (e *EnvironmentPasswordManager) GetPassword(address string) (string, bool)
GetPassword retrieves password from environment variables (backwards compatibility)
func (*EnvironmentPasswordManager) GetSwitchConfig ¶
func (e *EnvironmentPasswordManager) GetSwitchConfig(address string) (*SwitchConfig, bool)
GetSwitchConfig retrieves full switch configuration including optional model
func (*EnvironmentPasswordManager) SetVerbose ¶
func (e *EnvironmentPasswordManager) SetVerbose(verbose bool)
SetVerbose enables or disables verbose logging
type Error ¶
Error represents a netgear client error
func NewAuthError ¶
NewAuthError creates a new authentication error
func NewModelError ¶
NewModelError creates a new model error
func NewNetworkError ¶
NewNetworkError creates a new network error
func NewOperationError ¶
NewOperationError creates a new operation error
func NewParsingError ¶
NewParsingError creates a new parsing error
type FileTokenManager ¶
type FileTokenManager struct {
// contains filtered or unexported fields
}
FileTokenManager stores tokens in files (current behavior)
func NewFileTokenManager ¶
func NewFileTokenManager(dir string) *FileTokenManager
NewFileTokenManager creates a new file-based token manager
func (*FileTokenManager) DeleteToken ¶
func (m *FileTokenManager) DeleteToken(ctx context.Context, address string) error
DeleteToken removes a stored token file
func (*FileTokenManager) StoreToken ¶
func (m *FileTokenManager) StoreToken(ctx context.Context, address string, token string, model Model) error
StoreToken saves a token to file
type MemoryTokenManager ¶
type MemoryTokenManager struct {
// contains filtered or unexported fields
}
MemoryTokenManager stores tokens in memory
func NewMemoryTokenManager ¶
func NewMemoryTokenManager() *MemoryTokenManager
NewMemoryTokenManager creates a new in-memory token manager
func (*MemoryTokenManager) DeleteToken ¶
func (m *MemoryTokenManager) DeleteToken(ctx context.Context, address string) error
DeleteToken removes a stored token
func (*MemoryTokenManager) StoreToken ¶
func (m *MemoryTokenManager) StoreToken(ctx context.Context, address string, token string, model Model) error
StoreToken saves a token
type Model ¶
type Model string
Model represents a Netgear switch model
func (Model) IsModel30x ¶
IsModel30x returns true if the model is part of the 30x series
func (Model) IsModel316 ¶
IsModel316 returns true if the model is part of the 316 series
func (Model) IsSupported ¶
IsSupported returns true if the model is supported
type POELimitType ¶
type POELimitType string
POELimitType represents POE power limit type
const ( POELimitTypeNone POELimitType = "none" POELimitTypeClass POELimitType = "class" POELimitTypeUser POELimitType = "user" )
type POEManager ¶
type POEManager struct {
// contains filtered or unexported fields
}
POEManager handles POE-related operations
func (*POEManager) CyclePower ¶
func (m *POEManager) CyclePower(ctx context.Context, portIDs ...int) error
CyclePower performs a power cycle on specified ports
func (*POEManager) DisablePort ¶
func (m *POEManager) DisablePort(ctx context.Context, portID int) error
DisablePort disables POE on the specified port
func (*POEManager) EnablePort ¶
func (m *POEManager) EnablePort(ctx context.Context, portID int) error
EnablePort enables POE on the specified port
func (*POEManager) GetPortSettings ¶
func (m *POEManager) GetPortSettings(ctx context.Context, portID int) (*POEPortSettings, error)
GetPortSettings gets the POE settings for a specific port
func (*POEManager) GetPortStatus ¶
func (m *POEManager) GetPortStatus(ctx context.Context, portID int) (*POEPortStatus, error)
GetPortStatus gets the POE status for a specific port
func (*POEManager) GetSettings ¶
func (m *POEManager) GetSettings(ctx context.Context) ([]POEPortSettings, error)
GetSettings retrieves POE settings for all ports
func (*POEManager) GetStatus ¶
func (m *POEManager) GetStatus(ctx context.Context) ([]POEPortStatus, error)
GetStatus retrieves POE status for all ports
func (*POEManager) SetPortMode ¶
SetPortMode sets the POE mode for a specific port
func (*POEManager) SetPortPowerLimit ¶
func (m *POEManager) SetPortPowerLimit(ctx context.Context, portID int, limitType POELimitType, limitW float64) error
SetPortPowerLimit sets the power limit for a specific port
func (*POEManager) SetPortPriority ¶
func (m *POEManager) SetPortPriority(ctx context.Context, portID int, priority POEPriority) error
SetPortPriority sets the POE priority for a specific port
func (*POEManager) UpdatePort ¶
func (m *POEManager) UpdatePort(ctx context.Context, updates ...POEPortUpdate) error
UpdatePort updates settings for specific ports
type POEPortSettings ¶
type POEPortSettings struct {
PortID int `json:"port_id"`
PortName string `json:"port_name"`
Enabled bool `json:"enabled"`
Mode POEMode `json:"mode"`
Priority POEPriority `json:"priority"`
PowerLimitType POELimitType `json:"power_limit_type"`
PowerLimitW float64 `json:"power_limit_w"`
DetectionType string `json:"detection_type"`
LongerDetectionTime bool `json:"longer_detection_time"`
}
POEPortSettings represents POE port configuration
type POEPortStatus ¶
type POEPortStatus struct {
PortID int `json:"port_id"`
PortName string `json:"port_name"`
Status string `json:"status"`
PowerClass string `json:"power_class"`
VoltageV float64 `json:"voltage_v"`
CurrentMA float64 `json:"current_ma"`
PowerW float64 `json:"power_w"`
TemperatureC float64 `json:"temperature_c"`
ErrorStatus string `json:"error_status"`
}
POEPortStatus represents the status of a POE port
type POEPortUpdate ¶
type POEPortUpdate struct {
PortID int `json:"port_id"`
Enabled *bool `json:"enabled,omitempty"`
Mode *POEMode `json:"mode,omitempty"`
Priority *POEPriority `json:"priority,omitempty"`
PowerLimitType *POELimitType `json:"power_limit_type,omitempty"`
PowerLimitW *float64 `json:"power_limit_w,omitempty"`
DetectionType *string `json:"detection_type,omitempty"`
}
POEPortUpdate represents changes to apply to a POE port
type POEPriority ¶
type POEPriority string
POEPriority represents POE port priority
const ( POEPriorityLow POEPriority = "low" POEPriorityHigh POEPriority = "high" POEPriorityCritical POEPriority = "critical" )
type PasswordManager ¶
type PasswordManager interface {
GetPassword(address string) (string, bool)
GetSwitchConfig(address string) (*SwitchConfig, bool)
}
PasswordManager interface for password resolution
type PortManager ¶
type PortManager struct {
// contains filtered or unexported fields
}
PortManager handles port-related operations
func (*PortManager) DisablePort ¶
func (m *PortManager) DisablePort(ctx context.Context, portID int) error
DisablePort disables a specific port
func (*PortManager) EnablePort ¶
func (m *PortManager) EnablePort(ctx context.Context, portID int) error
EnablePort enables a specific port with auto speed
func (*PortManager) GetPortSettings ¶
func (m *PortManager) GetPortSettings(ctx context.Context, portID int) (*PortSettings, error)
GetPortSettings gets the settings for a specific port
func (*PortManager) GetSettings ¶
func (m *PortManager) GetSettings(ctx context.Context) ([]PortSettings, error)
GetSettings retrieves port settings
func (*PortManager) SetPortFlowControl ¶
SetPortFlowControl sets the flow control for a specific port
func (*PortManager) SetPortLimits ¶
func (m *PortManager) SetPortLimits(ctx context.Context, portID int, ingressLimit, egressLimit string) error
SetPortLimits sets the ingress and egress limits for a specific port
func (*PortManager) SetPortName ¶
SetPortName sets the name for a specific port
func (*PortManager) SetPortSpeed ¶
SetPortSpeed sets the speed for a specific port
func (*PortManager) UpdatePort ¶
func (m *PortManager) UpdatePort(ctx context.Context, updates ...PortUpdate) error
UpdatePort updates settings for specific ports
type PortSettings ¶
type PortSettings struct {
PortID int `json:"port_id"`
PortName string `json:"port_name"`
Speed PortSpeed `json:"speed"`
IngressLimit string `json:"ingress_limit"`
EgressLimit string `json:"egress_limit"`
FlowControl bool `json:"flow_control"`
Status PortStatus `json:"status"`
LinkSpeed string `json:"link_speed"`
}
PortSettings represents switch port configuration
type PortStatus ¶
type PortStatus string
PortStatus represents port status
const ( PortStatusAvailable PortStatus = "available" PortStatusConnected PortStatus = "connected" PortStatusDisabled PortStatus = "disabled" )
type PortUpdate ¶
type PortUpdate struct {
PortID int `json:"port_id"`
Name *string `json:"name,omitempty"`
Speed *PortSpeed `json:"speed,omitempty"`
IngressLimit *string `json:"ingress_limit,omitempty"`
EgressLimit *string `json:"egress_limit,omitempty"`
FlowControl *bool `json:"flow_control,omitempty"`
}
PortUpdate represents changes to apply to a port
type SwitchConfig ¶
SwitchConfig represents a switch configuration from environment variables
type TokenManager ¶
type TokenManager interface {
// GetToken retrieves a stored token
GetToken(ctx context.Context, address string) (token string, model Model, err error)
// StoreToken saves a token
StoreToken(ctx context.Context, address string, token string, model Model) error
// DeleteToken removes a stored token
DeleteToken(ctx context.Context, address string) error
}
TokenManager handles token persistence