Documentation ¶
Overview ¶
Package config with the global hub configuration struct and methods
Index ¶
Constants ¶
const ( DefaultMqttPortUnpw = 8883 DefaultMqttPortCert = 8884 DefaultMqttPortWS = 8885 )
Default ports for connecting to the MQTT server
const DefaultBinFolder = "./bin"
DefaultBinFolder is the location of application binaries wrt installation folder
const DefaultCertsFolder = "./certs"
DefaultCertsFolder with the location of certificates
const DefaultConfigFolder = "./config"
DefaultConfigFolder is the location of config files wrt installation folder
const DefaultHubConfigName = "hub.yaml"
DefaultHubConfigName with the configuration file name of the hub
const DefaultLogFolder = "./log"
DefaultLogFolder is the location of log files wrt installation folder
const DefaultMqttTimeout = 3
const DefaultThingZone = "local"
DefaultThingZone is the zone the hub's things are published in.
Variables ¶
This section is empty.
Functions ¶
func LoadYamlConfig ¶
LoadYamlConfig loads a yaml configuration from file and substitutes keywords variables with values from the provided map.
This function doesn't really care what a keyword looks like but as convention "${name}" is used. If the keyword is not present in the given map then it will remain unchanged in the configFile.
configFile path to yaml configuration file config interface to typed structure matching the config. Must have yaml tags substituteMap map to substitude keys with value from map, nil to ignore
Returns nil if successful
func SubstituteText ¶
SubstituteText substitutes template strings in the text This substitutes configuration values in the format ${name} with the given variable from the map. This format is compatible with JS templates. This is kept simple by requiring the full template keyword in the replacement map, eg use "${name}" and not "name" as the key in the map.
text to substitude template strings, eg "hello ${name}" substituteMap with replacement keywords, eg {"${destination}":"world"}
Returns text with template strings replaced
Types ¶
type HubConfig ¶
type HubConfig struct { // Server address of auth, idprov, mqtt, directory services. The default "" is the outbound IP address // If DNS is used override this with the server domain name. // Clients that use the hubconfig must override this with the discovered server address as provided by idprov Address string `yaml:"address,omitempty"` // MQTT TLS port for certificate based authentication. Default is DefaultMqttPortCert MqttPortCert int `yaml:"mqttPortCert,omitempty"` // MQTT TLS port for login/password authentication. Default is DefaultMqttPortUnpw MqttPortUnpw int `yaml:"mqttPortUnpw,omitempty"` // Websocket TLS port for login/password authentication. Default is DefaultMqttPortWS MqttPortWS int `yaml:"mqttPortWS,omitempty"` // plugin mqtt connection timeout in seconds. 0 for indefinite. Default is DefaultMqttTimeout (3 sec) MqttTimeout int `yaml:"mqttTimeout,omitempty"` // Zone that published Things belong to. Default is 'local' // Zones are useful for separating devices from Hubs on large networks. Normally 'local' is sufficient. // // When Things are bridged, the bridge can be configured to replace the zone by that of the bridge. // This is intended for access control to Things from a different zone. Zone string `yaml:"zone"` // Files and Folders Loglevel string `yaml:"logLevel"` // debug, info, warning, error. Default is warning LogFolder string `yaml:"logFolder"` // location of log files LogFile string `yaml:"logFile"` // log filename is pluginID.log HomeFolder string `yaml:"homeFolder"` // Folder containing the application installation BinFolder string `yaml:"binFolder"` // Folder containing plugin binaries, default is {homeFolder}/bin CertsFolder string `yaml:"certsFolder"` // Folder containing certificates, default is {homeFolder}/certsclient // ConfigFolder the location of additional configuration files. Default is {homeFolder}/config ConfigFolder string `yaml:"configFolder"` // Keep server certificate on startup. Default is false // enable to keep using access tokens between restarts KeepServerCertOnStartup bool `yaml:"keepServerCertOnStartup"` // path to CA certificate in PEM format. Default is homeFolder/certs/caCert.pem CaCertFile string `yaml:"caCertFile"` // path to client x509 certificate in PEM format. Default is homeFolder/certs/{clientID}Cert.pem ClientCertFile string `yaml:"clientCertFile"` // path to client private key in PEM format. Default is homeFolder/certs/{clientID}Key.pem ClientKeyFile string `yaml:"clientKeyFile"` // path to plugin client x509 certificate in PEM format. Default is homeFolder/certs/PluginCert.pem PluginCertFile string `yaml:"pluginCertFile"` // path to plugin client private key in PEM format. Default is homeFolder/certs/PluginKey.pem PluginKeyFile string `yaml:"pluginKeyFile"` // CaCert contains the loaded CA certificate needed for establishing trusted connections to the // MQTT message bus and other services. Loading takes place in LoadHubConfig() CaCert *x509.Certificate // ClientCert contains the loaded TLS client certificate and key if available. // Loading takes place in LoadHubConfig() // * For plugins this is the plugin certificate and private key // * For servers this is the server certificate and private key // * For devices this is the provisioned device certificate and private key ClientCert *tls.Certificate // PluginCert contains the TLS client certificate for use by plugins // Intended for use by plugin clients. This is nil of the plugin certificate is not available or accessible // Loading takes place in LoadHubConfig() PluginCert *tls.Certificate }
HubConfig contains the global configuration for using the Hub by its clients.
Intended for use by:
- Hub plugins that needs to know the location of files, certificates and service address and ports
- Remote devices or services that uses a local copy of the hub config for manual configuration of certificates MQTT server address and ports.
func CreateHubConfig ¶
CreateHubConfig creates the HubConfig with default values
homeFolder is the hub installation folder and home to plugins, logs and configuration folders.
Use "" for default: parent of application binary When relative path is given, it is relative to the current working directory (commandline use)
See also LoadHubConfig to load the actual configuration including certificates.
func LoadAllConfig ¶
func LoadAllConfig(args []string, homeFolder string, clientID string, clientConfig interface{}) (*HubConfig, error)
LoadAllConfig is a helper to load all configuration from commandline, hubconfig and client config This:
Determine application defaults
parse commandline arguments for options -c hub.yaml -a appFolder or -h
Load the hub global configuration file hub.yaml, if found
Load the client configuration file {clientID}.yaml, if found
args is the os.argv list. Use nil to ignore commandline args homeFolder is the installation folder, "" for default parent folder of app binary clientID is the server, plugin or device instance ID. Used when connecting to servers clientConfig is an instance of the client's configuration object
This returns the hub global configuration with an error if something went wrong
func (*HubConfig) AsMap ¶
AsMap returns a key-value map of the HubConfig This simply converts the yaml to a map
func (*HubConfig) Load ¶
Load loads and validates the configuration from file.
If an error is returned then the default configuration is returned.
The following variables can be used in this file:
{clientID} is the device or plugin instance ID. Used for logfile and client cert {homeFolder} is the default application folder (parent of application binary) {certsFolder} is the default certificate folder {configFolder} is the default configuration folder {logFolder} is the default logging folder configFile is optional. The default is hub.yaml in the default config folder. clientID is the device or plugin instance ID. Used for logfile and client cert name.
Returns the hub configuration and error code