netgear

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (c *Client) GetAddress() string

GetAddress returns the switch address

func (*Client) GetModel

func (c *Client) GetModel() Model

GetModel returns the detected switch model

func (*Client) IsAuthenticated

func (c *Client) IsAuthenticated() bool

IsAuthenticated returns true if the client has a valid token

func (*Client) Login

func (c *Client) Login(ctx context.Context, password string) error

Login authenticates with the switch

func (*Client) LoginAuto

func (c *Client) LoginAuto(ctx context.Context) error

LoginAuto performs automatic authentication using environment variables

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout clears the authentication token

func (*Client) POE

func (c *Client) POE() *POEManager

POE returns the POE management interface

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

func WithVerbose

func WithVerbose(verbose bool) ClientOption

WithVerbose enables verbose logging

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

type Error struct {
	Type    ErrorType
	Message string
	Cause   error
}

Error represents a netgear client error

func NewAuthError

func NewAuthError(message string, cause error) *Error

NewAuthError creates a new authentication error

func NewError

func NewError(errorType ErrorType, message string, cause error) *Error

NewError creates a new netgear error

func NewModelError

func NewModelError(message string, cause error) *Error

NewModelError creates a new model error

func NewNetworkError

func NewNetworkError(message string, cause error) *Error

NewNetworkError creates a new network error

func NewOperationError

func NewOperationError(message string, cause error) *Error

NewOperationError creates a new operation error

func NewParsingError

func NewParsingError(message string, cause error) *Error

NewParsingError creates a new parsing error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorType

type ErrorType string

ErrorType represents the category of error

const (
	ErrorTypeAuth      ErrorType = "authentication"
	ErrorTypeNetwork   ErrorType = "network"
	ErrorTypeParsing   ErrorType = "parsing"
	ErrorTypeModel     ErrorType = "model"
	ErrorTypeOperation ErrorType = "operation"
)

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) GetToken

func (m *FileTokenManager) GetToken(ctx context.Context, address string) (string, Model, error)

GetToken retrieves a stored token from 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) GetToken

func (m *MemoryTokenManager) GetToken(ctx context.Context, address string) (string, Model, error)

GetToken retrieves 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

const (
	ModelGS305EP  Model = "GS305EP"
	ModelGS305EPP Model = "GS305EPP"
	ModelGS308EP  Model = "GS308EP"
	ModelGS308EPP Model = "GS308EPP"
	ModelGS316EP  Model = "GS316EP"
	ModelGS316EPP Model = "GS316EPP"
	ModelGS30xEPx Model = "GS30xEPx"
)

func (Model) IsModel30x

func (m Model) IsModel30x() bool

IsModel30x returns true if the model is part of the 30x series

func (Model) IsModel316

func (m Model) IsModel316() bool

IsModel316 returns true if the model is part of the 316 series

func (Model) IsSupported

func (m Model) IsSupported() bool

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

func (m *POEManager) SetPortMode(ctx context.Context, portID int, mode POEMode) error

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 POEMode

type POEMode string

POEMode represents POE power mode

const (
	POEMode8023af    POEMode = "802.3af"
	POEMode8023at    POEMode = "802.3at"
	POEModeLegacy    POEMode = "legacy"
	POEModePre8023at POEMode = "pre-802.3at"
)

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

func (m *PortManager) SetPortFlowControl(ctx context.Context, portID int, enabled bool) error

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

func (m *PortManager) SetPortName(ctx context.Context, portID int, name string) error

SetPortName sets the name for a specific port

func (*PortManager) SetPortSpeed

func (m *PortManager) SetPortSpeed(ctx context.Context, portID int, speed PortSpeed) error

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 PortSpeed

type PortSpeed string

PortSpeed represents port speed configuration

const (
	PortSpeedAuto     PortSpeed = "auto"
	PortSpeed10MHalf  PortSpeed = "10M half"
	PortSpeed10MFull  PortSpeed = "10M full"
	PortSpeed100MHalf PortSpeed = "100M half"
	PortSpeed100MFull PortSpeed = "100M full"
	PortSpeedDisable  PortSpeed = "disable"
)

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

type SwitchConfig struct {
	Host     string
	Password string
	Model    string // optional
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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