nsupdate
This commit is contained in:
@@ -18,7 +18,7 @@ type structInfo struct {
|
||||
Tags reflect.StructTag
|
||||
Type reflect.Type
|
||||
DefaultValue interface{}
|
||||
Secret interface{}
|
||||
Secret bool
|
||||
}
|
||||
|
||||
func getEnv[t string | bool | int | int64 | float64](env string, def t) (t, error) {
|
||||
@@ -97,7 +97,7 @@ func getStructInfo(spec interface{}) ([]structInfo, error) {
|
||||
f = f.Elem()
|
||||
}
|
||||
|
||||
secret, err := typeConversion(ftype.Type.String(), ftype.Tag.Get("secret"))
|
||||
secret, err := strconv.ParseBool((ftype.Tag.Get("secret")))
|
||||
if err != nil {
|
||||
secret = false
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -32,6 +33,12 @@ func Init() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// check to see if nsupdate is installed
|
||||
cmd := "command -v nsupdate"
|
||||
if err := exec.Command("/usr/bin/sh", "-c", cmd).Run(); err != nil {
|
||||
panic("nsupdate is not installed")
|
||||
}
|
||||
|
||||
// print running config
|
||||
printRunningConfig(&Cfg, cfgInfo)
|
||||
}
|
||||
|
@@ -30,6 +30,12 @@ type Config struct {
|
||||
// cisa
|
||||
RemoteURL string `default:"https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json?sort_by=field_date_added" env:"remote_url"`
|
||||
RefreshSeconds int `default:"14400" env:"refresh_seconds"`
|
||||
|
||||
// nsupdate
|
||||
NSUKey string `env:"nsupdate-key" secret:"true"`
|
||||
NSUPort int `default:"53" env:"nsupdate-port"`
|
||||
NSUServer string `default:"ns1.example.com" env:"nsupdate-server"`
|
||||
NSUZone string `default:"example.com" env:"nsupdate-zone"`
|
||||
}
|
||||
|
||||
// New initializes the config variable for use with a prepared set of defaults.
|
||||
@@ -70,16 +76,20 @@ func setLogLevel(cfg *Config) {
|
||||
|
||||
func printRunningConfig(cfg *Config, cfgInfo []structInfo) {
|
||||
for _, info := range cfgInfo {
|
||||
switch info.Type.String() {
|
||||
case "string":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*string)
|
||||
cfg.Log.Debug("Running Configuration", info.Alt, *p)
|
||||
case "bool":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*bool)
|
||||
cfg.Log.Debug("Running Configuration", info.Alt, strconv.FormatBool(*p))
|
||||
case "int":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*int)
|
||||
cfg.Log.Debug("Running Configuration", info.Alt, strconv.FormatInt(int64(*p), 10))
|
||||
if info.Secret {
|
||||
cfg.Log.Debug("Running Configuration", info.Alt, "REDACTED")
|
||||
} else {
|
||||
switch info.Type.String() {
|
||||
case "string":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*string)
|
||||
cfg.Log.Debug("Running Configuration", info.Alt, *p)
|
||||
case "bool":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*bool)
|
||||
cfg.Log.Debug("Running Configuration", info.Alt, strconv.FormatBool(*p))
|
||||
case "int":
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*int)
|
||||
cfg.Log.Debug("Running Configuration", info.Alt, strconv.FormatInt(int64(*p), 10))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user