added apikey to config
This commit is contained in:
parent
cd7bcd5d55
commit
2bd9177180
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
5
go.mod
5
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
|
||||
)
|
||||
|
2
go.sum
2
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=
|
||||
|
Loading…
Reference in New Issue
Block a user