diff --git a/config/config.go b/config/config.go index e15cf56..cec0706 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,7 @@ package config import ( "fmt" "git.binarythought.com/cdramey/alrm/alarm" + "github.com/denisbrodbeck/machineid" "time" ) @@ -12,6 +13,7 @@ type Config struct { Interval time.Duration Listen string Path string + APIKey string } func NewConfig() *Config { @@ -71,5 +73,13 @@ func ReadConfig(fn string, debuglvl int) (*Config, error) { if err != nil { return nil, err } + if config.APIKey == "" { + key, err := machineid.ProtectedID("alrm") + if err != nil { + return nil, fmt.Errorf("could not generate machine id for api key") + } + config.APIKey = key + } + return config, nil } diff --git a/config/parser.go b/config/parser.go index b2510b4..adef262 100644 --- a/config/parser.go +++ b/config/parser.go @@ -72,6 +72,8 @@ func (p *Parser) Parse(fn string) (*Config, error) { } case "listen": config.Listen = value + case "apikey": + config.APIKey = value default: return nil, fmt.Errorf("unknown key for set in %s, line %d: \"%s\"", fn, tok.Line(), tk, diff --git a/go.mod b/go.mod index fc0d00d..0b03fb8 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module git.binarythought.com/cdramey/alrm go 1.15 -require golang.org/x/net v0.0.0-20201224014010-6772e930b67b +require ( + github.com/denisbrodbeck/machineid v1.0.1 + golang.org/x/net v0.0.0-20201224014010-6772e930b67b +) diff --git a/go.sum b/go.sum index 89bc358..e737d59 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= +github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=