Skip to content

Commit

Permalink
fix: skip parsing empty initial admin keys
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 8, 2022
1 parent f290a82 commit 078761f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ func NewConfig(cfg *config.Config) (*Config, error) {
host := cfg.BindAddr
port := cfg.Port

pks := make([]string, 0, len(cfg.InitialAdminKeys))
pks := make([]string, 0)
for _, k := range cfg.InitialAdminKeys {
var pk = strings.TrimSpace(k)
if bts, err := os.ReadFile(k); err == nil {
// pk is a file, set its contents as pk
pk = string(bts)
if pk != "" {
if bts, err := os.ReadFile(k); 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 %q: %w", k, err)
}
pks = append(pks, pk)
}
// 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 %q: %w", k, err)
}
pks = append(pks, pk)
}

rs := git.NewRepoSource(cfg.RepoPath)
Expand Down

0 comments on commit 078761f

Please sign in to comment.