Skip to content

Commit

Permalink
Fix bug where ssh key cannot be written on Windows
Browse files Browse the repository at this point in the history
Resolves #33.
  • Loading branch information
meowgorithm committed Dec 13, 2021
1 parent de9cf14 commit 4d1fd7d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"log"
"path/filepath"

"github.com/meowgorithm/babyenv"
)
Expand All @@ -15,14 +16,27 @@ type Callbacks interface {

// Config is the configuration for Soft Serve.
type Config struct {
Host string `env:"SOFT_SERVE_HOST" default:""`
Port int `env:"SOFT_SERVE_PORT" default:"23231"`
KeyPath string `env:"SOFT_SERVE_KEY_PATH" default:".ssh/soft_serve_server_ed25519"`
RepoPath string `env:"SOFT_SERVE_REPO_PATH" default:".repos"`
InitialAdminKey string `env:"SOFT_SERVE_INITIAL_ADMIN_KEY" default:""`
Host string `env:"SOFT_SERVE_HOST"`
Port int `env:"SOFT_SERVE_PORT"`
KeyPath string `env:"SOFT_SERVE_KEY_PATH"`
RepoPath string `env:"SOFT_SERVE_REPO_PATH"`
InitialAdminKey string `env:"SOFT_SERVE_INITIAL_ADMIN_KEY"`
Callbacks Callbacks
}

func (c *Config) applyDefaults() {
if c.Port == 0 {
c.Port = 23231
}
if c.KeyPath == "" {
// NB: cross-platform-compatible path
c.KeyPath = filepath.Join(".ssh", "soft_serve_server_ed25519")
}
if c.RepoPath == "" {
c.RepoPath = ".repos"
}
}

// DefaultConfig returns a Config with the values populated with the defaults
// or specified environment variables.
func DefaultConfig() *Config {
Expand All @@ -31,6 +45,7 @@ func DefaultConfig() *Config {
if err != nil {
log.Fatalln(err)
}
scfg.applyDefaults()
return scfg.WithCallbacks(nil)
}

Expand Down

0 comments on commit 4d1fd7d

Please sign in to comment.