4d1fd7dd79ea87ee74deea584b8921ab1e8237a5

Author
Christian Rocha <christian@rocha.is>
Committer
Christian Rocha <christian@rocha.is>
Date

Message

Fix bug where ssh key cannot be written on Windows

Resolves #33.

Diff

 1diff --git a/config/config.go b/config/config.go
 2index 0a28e783f2bbfc5d7f23edc3f4f00b02464426f1..3180492f39c2ba6e3062f5b587d7039fdd92816f 100644
 3--- a/config/config.go
 4+++ b/config/config.go
 5@@ -2,6 +2,7 @@ package config
 6 
 7 import (
 8 	"log"
 9+	"path/filepath"
10 
11 	"github.com/meowgorithm/babyenv"
12 )
13@@ -15,14 +16,27 @@ type Callbacks interface {
14 
15 // Config is the configuration for Soft Serve.
16 type Config struct {
17-	Host            string `env:"SOFT_SERVE_HOST" default:""`
18-	Port            int    `env:"SOFT_SERVE_PORT" default:"23231"`
19-	KeyPath         string `env:"SOFT_SERVE_KEY_PATH" default:".ssh/soft_serve_server_ed25519"`
20-	RepoPath        string `env:"SOFT_SERVE_REPO_PATH" default:".repos"`
21-	InitialAdminKey string `env:"SOFT_SERVE_INITIAL_ADMIN_KEY" default:""`
22+	Host            string `env:"SOFT_SERVE_HOST"`
23+	Port            int    `env:"SOFT_SERVE_PORT"`
24+	KeyPath         string `env:"SOFT_SERVE_KEY_PATH"`
25+	RepoPath        string `env:"SOFT_SERVE_REPO_PATH"`
26+	InitialAdminKey string `env:"SOFT_SERVE_INITIAL_ADMIN_KEY"`
27 	Callbacks       Callbacks
28 }
29 
30+func (c *Config) applyDefaults() {
31+	if c.Port == 0 {
32+		c.Port = 23231
33+	}
34+	if c.KeyPath == "" {
35+		// NB: cross-platform-compatible path
36+		c.KeyPath = filepath.Join(".ssh", "soft_serve_server_ed25519")
37+	}
38+	if c.RepoPath == "" {
39+		c.RepoPath = ".repos"
40+	}
41+}
42+
43 // DefaultConfig returns a Config with the values populated with the defaults
44 // or specified environment variables.
45 func DefaultConfig() *Config {
46@@ -31,6 +45,7 @@ func DefaultConfig() *Config {
47 	if err != nil {
48 		log.Fatalln(err)
49 	}
50+	scfg.applyDefaults()
51 	return scfg.WithCallbacks(nil)
52 }
53