config

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package config provides code for working with both the wirelink command line arguments and its configuration file.

Index

Constants

View Source
const (
	// RouterFlag is the name of the flag to set router mode
	RouterFlag = "router"
	// IfaceFlag is the name of the flag to set the wireguard interface to use
	IfaceFlag = "iface"
	// DumpConfigFlag is the name of the flag to request config dumping
	DumpConfigFlag = "dump"
	// VersionFlag is the name of the flag to request printing the program version
	VersionFlag = "version"
	// HelpFlag is the name of the flag to request printing program usage
	HelpFlag = "help"
	// ConfigPathFlag is the name of the setting for the config file base path
	ConfigPathFlag = "config-path"
	// DebugFlag enables debug logging
	DebugFlag = "debug"
	// ChattyFlag is the name of the setting to enable chatty mode
	ChattyFlag = "chatty"
)

Variables

This section is empty.

Functions

func CreateTrustEvaluator

func CreateTrustEvaluator(peers Peers) trust.Evaluator

CreateTrustEvaluator maps a peer config map into an evaluator that returns the configured trust levels

func Init added in v0.3.0

func Init(args []string) (flags *pflag.FlagSet, vcfg *viper.Viper)

Init sets up the config flags and other parsing setup

Types

type Peer

type Peer struct {
	Name          string
	Trust         *trust.Level
	FactExchanger bool
	Endpoints     []PeerEndpoint
	AllowedIPs    []net.IPNet
	Basic         bool
}

Peer represents the parsed info about a peer read from the config file

func (*Peer) String

func (p *Peer) String() string

type PeerData

type PeerData struct {
	PublicKey     string
	Name          string
	Trust         string
	FactExchanger bool
	Endpoints     []string
	AllowedIPs    []string
	Basic         bool
}

PeerData represents the raw data to configure a peer read from the config file

func (*PeerData) Parse

func (p *PeerData) Parse() (key wgtypes.Key, peer Peer, err error)

Parse validates the info in the PeerData and returns the parsed tuple + error

type PeerEndpoint added in v0.7.1

type PeerEndpoint struct {
	// Host may be either an IP or a hostname
	Host string
	Port int
}

PeerEndpoint represents a single endpoint (possibly by hostname) for a peer

type Peers

type Peers map[wgtypes.Key]*Peer

Peers represents a set of peer configs, with handy access methods that avoid boiler plate for peers that are not configured

func (Peers) AllowedIPs added in v0.7.1

func (p Peers) AllowedIPs(peer wgtypes.Key) []net.IPNet

AllowedIPs returns the array of AllowedIPs explicitly configured for the peer, if any

func (Peers) AnyTrustedAt added in v0.9.0

func (p Peers) AnyTrustedAt(level trust.Level) bool

AnyTrustedAt returns whether any peer is configured with a trust level of at least the given level

func (Peers) Endpoints added in v0.7.1

func (p Peers) Endpoints(peer wgtypes.Key) []PeerEndpoint

Endpoints returns the array of Endpoints explicitly configured for the peer, if any

func (Peers) Has added in v0.9.0

func (p Peers) Has(peer wgtypes.Key) bool

Has checks if the given peer key has any configuration data

func (Peers) IsBasic added in v0.5.0

func (p Peers) IsBasic(peer wgtypes.Key) bool

IsBasic returns true if the peer is explicitly configured as a basic peer, or false otherwise

func (Peers) IsFactExchanger added in v0.3.1

func (p Peers) IsFactExchanger(peer wgtypes.Key) bool

IsFactExchanger returns true if the peer is configured as a FactExchanger

func (Peers) Name

func (p Peers) Name(peer wgtypes.Key) string

Name returns the name of the peer, if configured, or else the empty string

func (Peers) Trust

func (p Peers) Trust(peer wgtypes.Key, def trust.Level) trust.Level

Trust returns the configured trust level (if present and valid) or else the provided default

type Server

type Server struct {
	Iface  string
	Port   int
	Chatty bool

	AutoDetectRouter bool
	IsRouterNow      bool

	ReportIfaces []string
	HideIfaces   []string

	Peers Peers

	Debug bool
}

Server describes the configuration for the server, after parsing from various sources

func (*Server) ShouldReportIface added in v0.8.1

func (s *Server) ShouldReportIface(name string) bool

ShouldReportIface checks a given local network interface name against the config for whether we should tell other peers about our configuration on it

type ServerData added in v0.3.0

type ServerData struct {
	Iface  string
	Port   int
	Router *bool
	Chatty bool

	Peers []PeerData

	ReportIfaces []string
	HideIfaces   []string

	Debug   bool
	Dump    bool
	Help    bool
	Version bool

	// Deprecated: this prop is here for compat, but is ignored because it's how we find the
	// config file, so the config file can't use it to point at a different config.
	// with newer versions of mapstructure, can't get away with making this an un-exported member.
	ConfigPath string `mapstructure:"config-path"`
}

ServerData represents the raw data from the config for the server, before it is cleaned up into a `Server` config object.

func Parse added in v0.3.0

func Parse(flags *pflag.FlagSet, vcfg *viper.Viper, args []string) (ret *ServerData, err error)

Parse reads flags and configs

func (*ServerData) Parse added in v0.3.0

func (s *ServerData) Parse(vcfg *viper.Viper, _ internal.WgClient) (ret *Server, err error)

Parse converts the raw configuration data into a ready to use server config.

Jump to

Keyboard shortcuts

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