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
- Variables
- func CheckUID()
- func Convert(h *Config, n *Node) (models.Host, models.Node)
- func ConvertOldNode(netmakerNode *models.LegacyNode) (*Node, *Config)
- func ConvertToNetmakerNode(node *Node, server *Server, host *Config) *models.LegacyNode
- func DeleteClientNodes()
- func DeleteNode(k string)
- func DeleteNodes()
- func DeleteServer(k string)
- func DeleteServerHostPeerCfg()
- func FirewallHasChanged() bool
- func FormatBool(b bool) string
- func FormatName(name string) string
- func GetCurrServerCtxFromFile() (string, error)
- func GetNetclientInstallPath() string
- func GetNetclientPath() string
- func GetServers() (servers []string)
- func GetSystemNetworks() ([]string, error)
- func InCharSet(name string) bool
- func IsPidDead(pid int) bool
- func Lock(lockfile string) error
- func OldAuthenticate(node *Node, host *Config) (string, error)
- func ParseAccessToken(token string) (*models.AccessToken, error)
- func ParseBool(s string) bool
- func ReadNodeConfig() error
- func ReadServerConf() error
- func RemoveServerHostPeerCfg()
- func SaveServer(name string, server Server) error
- func SetCurrServerCtxInFile(server string) error
- func SetFirewall()
- func SetNodes(nodes []models.Node)
- func SetServerCtx()
- func SetVersion(ver string)
- func ToIPNet(cidr string) net.IPNet
- func ToUDPAddr(address string) *net.UDPAddr
- func Unlock(lockfile string) error
- func UpdateHost(host *models.Host) (resetInterface, restart, sendHostUpdate bool)
- func UpdateHostPeers(peers []wgtypes.PeerConfig)
- func UpdateNetclient(c Config)
- func UpdateNodeMap(k string, value Node)
- func UpdateServer(name string, server Server)
- func UpdateServerConfig(cfg *models.ServerConfig)
- func WriteNetclientConfig() error
- func WriteNodeConfig() error
- func WriteServerConfig() error
- type ClientConfig
- type Config
- type InitType
- type Node
- type NodeMap
- type OldNetmakerServerConfig
- type Server
- type TurnConfig
Constants ¶
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 )
const ( // DefaultHostID {0EF230F0-2EAD-4370-B0F9-AFC2D2A039E6} is a fixed string, // for creating the unique GUID. It's a meaningless unique GUID here to // make sure only one network profile is created. DefaultHostID = "0EF230F0-2EAD-4370-B0F9-AFC2D2A039E6" )
const NodeLockfile = "netclient-nodes.lck"
NodeLockFile is name of lockfile for controlling access to node config file on disk
const ServerLockfile = "netclient-servers.lck"
ServerLockFile is a lockfile for controlling access to the server map file on disk
Variables ¶
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 )
var CurrServer string
CurrServer - holds the value of current server of client
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 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 DeleteClientNodes ¶ added in v0.24.2
func DeleteClientNodes()
DeleteClientNodes - delete the nodes in client config
func DeleteNode ¶
func DeleteNode(k string)
DeleteNode deletes the node from the nodemap for the specified network
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 FormatName ¶
FormatName ensures name is in character set and is proper length Sets name to blank on failure
func GetCurrServerCtxFromFile ¶ added in v0.20.2
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 ¶
GetSystemNetworks - get networks for older version (pre v0.18.0) of netclient
func Lock ¶
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 OldAuthenticate ¶
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 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 ¶
SaveServer updates the server map with current server struct and writes map to disk
func SetCurrServerCtxInFile ¶ added in v0.20.2
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 SetServerCtx ¶ added in v0.20.2
func SetServerCtx()
SetServerCtx - sets netclient's server context
func Unlock ¶
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 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 ¶
UpdateNodeMap updates the in memory nodemap for the specified network
func UpdateServer ¶
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
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:"-" yaml:"-"` InitType InitType `json:"inittype" yaml:"inittype"` //for Internet gateway 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"` //for manage DNS DNSManagerType string `json:"dns_manager_type" yaml:"dns_manager_type"` NameServers []string `json:"name_servers" yaml:"name_servers"` DNSSearch string `json:"dns_search" yaml:"dns_search"` DNSOptions string `json:"dns_options" yaml:"dns_options"` }
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 ¶
ReadNetclientConfig reads the host configuration file and returns it as an instance.
type Node ¶
type Node struct {
models.CommonNode
}
Node provides configuration of a node
func ConvertNode ¶
ConvertNode accepts a netmaker node struct and converts to the structs used by netclient
func (*Node) PrimaryAddress ¶
PrimaryAddress returns the primary address of a node
type NodeMap ¶
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
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"` NameServers []string `json:"name_servers"` }
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
type TurnConfig ¶ added in v0.19.0
TurnConfig - struct to hold turn server config