Merge pull request #8 from cure/relative-paths-in-config
Handle relative paths in private_key_path and derp_map_path
This commit is contained in:
commit
328f6ea455
2 changed files with 18 additions and 4 deletions
|
@ -5,6 +5,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hako/durafmt"
|
"github.com/hako/durafmt"
|
||||||
|
@ -280,8 +282,20 @@ func main() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func absPath(path string) string {
|
||||||
|
// If a relative path is provided, prefix it with the the directory where
|
||||||
|
// the config file was found.
|
||||||
|
if !strings.HasPrefix(path, "/") {
|
||||||
|
dir, _ := filepath.Split(viper.ConfigFileUsed())
|
||||||
|
if dir != "" {
|
||||||
|
path = dir + "/" + path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
func getHeadscaleApp() (*headscale.Headscale, error) {
|
func getHeadscaleApp() (*headscale.Headscale, error) {
|
||||||
derpMap, err := loadDerpMap(viper.GetString("derp_map_path"))
|
derpMap, err := loadDerpMap(absPath(viper.GetString("derp_map_path")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Could not load DERP servers map file: %s", err)
|
log.Printf("Could not load DERP servers map file: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -289,7 +303,7 @@ func getHeadscaleApp() (*headscale.Headscale, error) {
|
||||||
cfg := headscale.Config{
|
cfg := headscale.Config{
|
||||||
ServerURL: viper.GetString("server_url"),
|
ServerURL: viper.GetString("server_url"),
|
||||||
Addr: viper.GetString("listen_addr"),
|
Addr: viper.GetString("listen_addr"),
|
||||||
PrivateKeyPath: viper.GetString("private_key_path"),
|
PrivateKeyPath: absPath(viper.GetString("private_key_path")),
|
||||||
DerpMap: derpMap,
|
DerpMap: derpMap,
|
||||||
|
|
||||||
DBhost: viper.GetString("db_host"),
|
DBhost: viper.GetString("db_host"),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"server_url": "http://192.168.1.12:8000",
|
"server_url": "http://192.168.1.12:8000",
|
||||||
"listen_addr": "0.0.0.0:8000",
|
"listen_addr": "0.0.0.0:8000",
|
||||||
"private_key_path": "private.key",
|
"private_key_path": "private.key",
|
||||||
"derp_map_path": "./derp.yaml",
|
"derp_map_path": "derp.yaml",
|
||||||
"db_host": "localhost",
|
"db_host": "localhost",
|
||||||
"db_port": 5432,
|
"db_port": 5432,
|
||||||
"db_name": "headscale",
|
"db_name": "headscale",
|
||||||
|
|
Loading…
Reference in a new issue