config

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Overview

Package config provides functions for reading the config.

Package config provides functions for reading the config.

Package config provides functions for reading the config.

Index

Constants

View Source
const (
	// LinuxAppDataPath - linux path
	LinuxAppDataPath = "/etc/netclient/"
	// MacAppDataPath - mac path
	MacAppDataPath = "/Applications/Netclient/"
	// WindowsAppDataPath - windows path
	WindowsAppDataPath = "C:\\Program Files (x86)\\Netclient\\"
	// Timeout timelimit for obtaining/releasing lockfile
	Timeout = time.Second * 5
	// ConfigLockfile lockfile to control access to config file
	ConfigLockfile = "config.lck"
	// MaxNameLength maximum length of a node name
	MaxNameLength = 62
	// DefaultListenPort default port for wireguard
	DefaultListenPort = 51821
	// DefaultMTU default MTU for wireguard
	DefaultMTU = 1420
)
View Source
const NodeLockfile = "netclient-nodes.lck"

NodeLockFile is name of lockfile for controlling access to node config file on disk

View Source
const ServerLockfile = "netclient-servers.lck"

ServerLockFile is a lockfile for controlling access to the server map file on disk

Variables

View Source
var (

	// Version - default version string
	Version = "dev"
	// FwClose - firewall manager shutdown func
	FwClose func() = func() {}
	// WgPublicListenPort - host's wireguard public listen port
	WgPublicListenPort int
	// HostPublicIP - host's public ipv4 endpoint
	HostPublicIP net.IP
	// HostPublicIP6 - host's public ipv6 endpoint
	HostPublicIP6 net.IP
	// HostNatType - host's NAT type
	HostNatType string
)
View Source
var CurrServer string

CurrServer - holds the value of current server of client

View Source
var Servers map[string]Server

Servers is map of servers indexed by server name

Functions

func CheckUID added in v0.20.5

func CheckUID()

CheckUID - Checks to make sure user has root privileges

func Convert

func Convert(h *Config, n *Node) (models.Host, models.Node)

Convert converts netclient host/node struct to netmaker host/node structs

func ConvertOldNode

func ConvertOldNode(netmakerNode *models.LegacyNode) (*Node, *Config)

ConvertOldNode accepts a netmaker node struct and converts to the structs used by netclient

func ConvertToNetmakerNode

func ConvertToNetmakerNode(node *Node, server *Server, host *Config) *models.LegacyNode

ConvertToNetmakerNode converts a netclient node to a netmaker node

func DeleteNode

func DeleteNode(k string)

DeleteNode deletes the node from the nodemap for the specified network

func DeleteNodes added in v0.22.0

func DeleteNodes()

DeleteNodes - removes all nodes

func DeleteServer

func DeleteServer(k string)

DeleteServer deletes the specified server name from the server map

func DeleteServerHostPeerCfg

func DeleteServerHostPeerCfg()

DeleteServerHostPeerCfg - deletes the host peers for the server

func FirewallHasChanged added in v0.19.0

func FirewallHasChanged() bool

FirewallHasChanged - checks if the firewall has changed

func FormatBool

func FormatBool(b bool) string

FormatBool converts a boolean to a [yes|no] string

func FormatName

func FormatName(name string) string

FormatName ensures name is in character set and is proper length Sets name to blank on failure

func GetCurrServerCtxFromFile added in v0.20.2

func GetCurrServerCtxFromFile() (string, error)

GetCurrServerCtxFromFile - gets current server context from file

func GetNetclientInstallPath

func GetNetclientInstallPath() string

GetNetclientInstallPath returns the full path where netclient should be installed based on OS

func GetNetclientPath

func GetNetclientPath() string

GetNetclientPath - returns path to netclient config directory

func GetServers

func GetServers() (servers []string)

GetServers - gets all the server names host has registered to.

func GetSystemNetworks

func GetSystemNetworks() ([]string, error)

GetSystemNetworks - get networks for older version (pre v0.18.0) of netclient

func InCharSet

func InCharSet(name string) bool

InCharSet verifies if all chars in string are part of defined charset

func IsPidDead

func IsPidDead(pid int) bool

IsPidDead checks if given pid is not running

func Lock

func Lock(lockfile string) error

Lock creates a lockfile with pid as contents if lockfile exists but belongs to defunct process the existing lockfile will be deleted and new one created if unable to create within TIMEOUT returns error

func ModPort

func ModPort(host *Config) error

ModPort - Change Node Port if ListenPort is not free

func OldAuthenticate

func OldAuthenticate(node *Node, host *Config) (string, error)

OldAuthenticate authenticates with netmaker api to permit subsequent interactions with the api

func ParseAccessToken

func ParseAccessToken(token string) (*models.AccessToken, error)

ParseAccessToken - decodes base64 encoded access token

func ParseBool

func ParseBool(s string) bool

ParseBool parses a [yes|no] string to boolean value

func ReadNodeConfig

func ReadNodeConfig() error

ReadNodeConfig reads node configuration from disk

func ReadServerConf

func ReadServerConf() error

ReadServerConf reads the servers configuration file and populates the server map

func RemoveServerHostPeerCfg added in v0.18.4

func RemoveServerHostPeerCfg()

RemoveServerHostPeerCfg - sets remove flag for all peers on the given server peers

func SaveServer

func SaveServer(name string, server Server) error

SaveServer updates the server map with current server struct and writes map to disk

func SetCurrServerCtxInFile added in v0.20.2

func SetCurrServerCtxInFile(server string) error

SetCurrServerCtxInFile - sets the current server context in the file

func SetFirewall added in v0.19.0

func SetFirewall()

setFirewall - determine and record firewall in use

func SetNodes added in v0.20.2

func SetNodes(nodes []models.Node)

SetNodes - sets server nodes in client config

func SetServerCtx added in v0.20.2

func SetServerCtx()

SetServerCtx - sets netclient's server context

func SetVersion

func SetVersion(ver string)

SetVersion - sets version for use by other packages

func ToIPNet

func ToIPNet(cidr string) net.IPNet

ToIPNet parses a cidr string and returns a net.IPNet

func ToUDPAddr

func ToUDPAddr(address string) *net.UDPAddr

ToUDPAddr parses and ip address string to return a pointer to net.UDPAddr

func Unlock

func Unlock(lockfile string) error

Unlock removes a lockfile if contents of lockfile match current pid also removes lockfile if owner process is no longer running will return TIMEOUT error if timeout exceeded

func UpdateHost added in v0.18.4

func UpdateHost(host *models.Host) (resetInterface, restart, sendHostUpdate bool)

func UpdateHostPeers

func UpdateHostPeers(peers []wgtypes.PeerConfig)

UpdateHostPeers - updates host peer map in the netclient config

func UpdateNetclient

func UpdateNetclient(c Config)

UpdateNetclient updates the in memory version of the host configuration

func UpdateNodeMap

func UpdateNodeMap(k string, value Node)

UpdateNodeMap updates the in memory nodemap for the specified network

func UpdateServer

func UpdateServer(name string, server Server)

UpdateServer updates the in-memory server map

func UpdateServerConfig

func UpdateServerConfig(cfg *models.ServerConfig)

UpdateServerConfig updates the in memory server map with values provided from netmaker server

func WriteNetclientConfig

func WriteNetclientConfig() error

WriteNetclientConfiig writes the in memory host configuration to disk

func WriteNodeConfig

func WriteNodeConfig() error

WriteNodeConfig writes the node map to disk

func WriteServerConfig

func WriteServerConfig() error

WriteServerConfig writes server map to disk

Types

type ClientConfig

type ClientConfig struct {
	Server          OldNetmakerServerConfig `yaml:"server"`
	Node            models.LegacyNode       `yaml:"node"`
	NetworkSettings models.Network          `yaml:"networksettings"`
	Network         string                  `yaml:"network"`
	Daemon          string                  `yaml:"daemon"`
	OperatingSystem string                  `yaml:"operatingsystem"`
	AccessKey       string                  `yaml:"accesskey"`
	PublicIPService string                  `yaml:"publicipservice"`
	SsoServer       string                  `yaml:"sso"`
}

ClientConfig - struct for dealing with client configuration

func ReadConfig

func ReadConfig(network string) (*ClientConfig, error)

ReadConfig - reads a config of a older version of client from disk for specified network

type Config

type Config struct {
	models.Host
	PrivateKey               wgtypes.Key          `json:"privatekey" yaml:"privatekey"`
	TrafficKeyPrivate        []byte               `json:"traffickeyprivate" yaml:"traffickeyprivate"`
	HostPeers                []wgtypes.PeerConfig `json:"host_peers" yaml:"-"`
	InitType                 InitType             `json:"inittype" yaml:"inittype"`
	OriginalDefaultGatewayIp net.IP               `json:"original_default_gateway_ip_old" yaml:"original_default_gateway_ip_old"`
	CurrGwNmIP               net.IP               `json:"curr_gw_nm_ip" yaml:"curr_gw_nm_ip"`
}

Config configuration for netclient and host as a whole

func Netclient

func Netclient() *Config

Netclient returns a pointer to the im memory version of the host configuration

func ReadNetclientConfig

func ReadNetclientConfig() (*Config, error)

ReadNetclientConfig reads the host configuration file and returns it as an instance.

type InitType added in v0.20.5

type InitType int

Initype - the type of init system in use

const (
	UnKnown InitType = iota
	Systemd
	SysVInit
	Runit
	OpenRC
	Initd
)

func (InitType) String added in v0.20.5

func (i InitType) String() string

String - returns the string representation of the init type

type Node

type Node struct {
	models.CommonNode
}

Node provides configuration of a node

func ConvertNode

func ConvertNode(nodeGet *models.NodeGet) *Node

ConvertNode accepts a netmaker node struct and converts to the structs used by netclient

func GetNode

func GetNode(k string) Node

GetNode returns returns the node configuation of the specified network name

func (*Node) PrimaryAddress

func (node *Node) PrimaryAddress() net.IPNet

PrimaryAddress returns the primary address of a node

type NodeMap

type NodeMap map[string]Node

NodeMap is an in memory map of the all nodes indexed by network name

var Nodes NodeMap

Nodes provides a map of node configurations indexed by network name

func GetNodes

func GetNodes() NodeMap

GetNodes returns a copy of the NodeMap

type OldNetmakerServerConfig

type OldNetmakerServerConfig struct {
	CoreDNSAddr string `yaml:"corednsaddr"`
	API         string `yaml:"api"`
	APIPort     string `yaml:"apiport"`
	ClientMode  string `yaml:"clientmode"`
	DNSMode     string `yaml:"dnsmode"`
	Version     string `yaml:"version"`
	MQPort      string `yaml:"mqport"`
	Server      string `yaml:"server"`
	Is_EE       bool   `yaml:"isee"`
}

OldNetmakerServerConfig - pre v0.18.0 server configuration

type Server

type Server struct {
	models.ServerConfig
	Name      string          `json:"name" yaml:"name"`
	MQID      uuid.UUID       `json:"mqid" yaml:"mqid"`
	Nodes     map[string]bool `json:"nodes" yaml:"nodes"`
	AccessKey string          `json:"accesskey" yaml:"accesskey"`
}

Server represents a server configuration

func ConvertOldServerCfg

func ConvertOldServerCfg(cfg *models.ServerConfig) *Server

ConvertOldServerCfg converts a netmaker ServerConfig to netclient server struct

func ConvertServerCfg

func ConvertServerCfg(cfg *OldNetmakerServerConfig) *Server

ConvertServerCfg converts a netmaker ServerConfig to netclient server struct

func GetServer

func GetServer(name string) *Server

GetServer returns the server struct for the given server name

type TurnConfig added in v0.19.0

type TurnConfig struct {
	Server string
	Domain string
	Port   int
}

TurnConfig - struct to hold turn server config

Jump to

Keyboard shortcuts

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