Просмотр исходного кода

feature: entity filepaths are relative to the config dir

jamesread 2 лет назад
Родитель
Сommit
32cb8dd873
2 измененных файлов с 19 добавлено и 4 удалено
  1. 2 2
      config.yaml
  2. 17 2
      internal/entityfiles/entityfiles.go

+ 2 - 2
config.yaml

@@ -207,10 +207,10 @@ entities:
   # will load properly.
   #
   # Docs: https://docs.olivetin.app/entities.html
-  - file: /etc/OliveTin/entities/servers.yaml
+  - file: entities/servers.yaml
     name: server
 
-  - file: /etc/OliveTin/entities/containers.json
+  - file: entities/containers.json
     name: container
 
 # Dashboards are a way of taking actions from the default "actions" view, and

+ 17 - 2
internal/entityfiles/entityfiles.go

@@ -8,15 +8,30 @@ import (
 	sv "github.com/OliveTin/OliveTin/internal/stringvariables"
 	"github.com/fsnotify/fsnotify"
 	log "github.com/sirupsen/logrus"
+	"github.com/spf13/viper"
 	"gopkg.in/yaml.v3"
 	"io/ioutil"
+	"path/filepath"
 	"strings"
 )
 
 func SetupEntityFileWatchers(cfg *config.Config) {
+	configDir := filepath.Dir(viper.ConfigFileUsed())
+
 	for _, ef := range cfg.Entities {
-		go watch(ef.File, ef.Name)
-		loadEntityFile(ef.File, ef.Name)
+		p := ef.File
+
+		if !filepath.IsAbs(p) {
+			p = filepath.Join(configDir, p)
+
+			log.WithFields(log.Fields{
+				"entityFile": p,
+			}).Debugf("Adding config dir to entity file path")
+		}
+
+		go watch(p, ef.Name)
+
+		loadEntityFile(p, ef.Name)
 	}
 }