about summary refs log tree commit diff
path: root/ops
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-12-02T14·13+0300
committerVincent Ambo <mail@tazj.in>2021-12-02T14·13+0300
commitb679bb4034a4150a3e75eca789035e69231ba0a7 (patch)
tree5fee5527bfc55e92ba5e694290b751b1a978e984 /ops
parentdcb241098251a80d69557eb172f3b719cc4c9d30 (diff)
refactor(ops/besadii): Get config from home directory by default r/3137
Slightly more ergonomic in some setups.

Change-Id: I565f2d242852ffd299ef5d5740a47520187dd4b4
Diffstat (limited to 'ops')
-rw-r--r--ops/besadii/main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/ops/besadii/main.go b/ops/besadii/main.go
index 8bb4b34740cd..28695d5214f4 100644
--- a/ops/besadii/main.go
+++ b/ops/besadii/main.go
@@ -23,6 +23,7 @@ import (
 	"log/syslog"
 	"net/http"
 	"os"
+	"os/user"
 	"path"
 	"regexp"
 	"strconv"
@@ -96,10 +97,24 @@ type reviewInput struct {
 	Tag                            string         `json:"tag"`
 }
 
+func defaultConfigLocation() (string, error) {
+	usr, err := user.Current()
+	if err != nil {
+		return "", fmt.Errorf("failed to get current user: %w", err)
+	}
+
+	return path.Join(usr.HomeDir, "besadii.json"), nil
+}
+
 func loadConfig() (*config, error) {
 	configPath := os.Getenv("BESADII_CONFIG")
+
 	if configPath == "" {
-		configPath = "/etc/besadii/config.json"
+		var err error
+		configPath, err = defaultConfigLocation()
+		if err != nil {
+			return nil, fmt.Errorf("failed to get config location: %w", err)
+		}
 	}
 
 	configJson, err := ioutil.ReadFile(configPath)