From c32ad0be67e2b7d120786dfcb2c50e35c0d3deb9 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 21 Jan 2022 11:30:37 -0300 Subject: [PATCH] feat: improve handling of SOFT_SERVE_INITIAL_ADMIN_KEY (#65) Signed-off-by: Carlos A Becker --- internal/config/config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index c43e0a424..a0fc5e223 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,6 +5,7 @@ import ( "path/filepath" "strings" + "golang.org/x/crypto/ssh" "gopkg.in/yaml.v2" "fmt" @@ -53,6 +54,16 @@ func NewConfig(cfg *config.Config) (*Config, error) { host := cfg.Host port := cfg.Port pk := cfg.InitialAdminKey + + if bts, err := os.ReadFile(pk); err == nil { + // pk is a file, set its contents as pk + pk = string(bts) + } + // it is a valid ssh key, nothing to do + if _, _, _, _, err := ssh.ParseAuthorizedKey([]byte(pk)); err != nil { + return nil, fmt.Errorf("invalid initial admin key: %w", err) + } + rs := git.NewRepoSource(cfg.RepoPath) c := &Config{ Cfg: cfg,