ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplify error handling for SSH key loading (#516)

* Simplify error handling for SSH key loading

Removed handling for missing SSH key file.

* don't error on idenities not found

---------

Co-authored-by: paul miller <paul.miller>

authored by

Paul Miller
paul miller
and committed by
GitHub
40cfe7f5 cbacbbf5

+21 -15
+21 -15
internal/config/envload.go
··· 26 26 } 27 27 } 28 28 29 + // TODO make this settable with env var :) 29 30 if err := loadEncryptedEnv("secrets/envtest"); err != nil { 30 31 loadErr = err 31 32 } ··· 36 37 func loadEncryptedEnv(path string) error { 37 38 identities, err := loadSSHIdentities() 38 39 if err != nil { 39 - if errors.Is(err, os.ErrNotExist) { 40 - return nil 41 - } 42 40 return fmt.Errorf("load ssh identity for %q: %w", path, err) 41 + } 42 + if len(identities) == 0 { 43 + // should we log 44 + return nil 43 45 } 44 46 45 47 return decryptDotEnv(path, identities) ··· 80 82 if err != nil || home == "" { 81 83 return []age.Identity{}, nil 82 84 } 83 - path := filepath.Join(home, ".ssh", "id_ed25519") 84 - 85 - key, err := os.ReadFile(path) 86 - if err != nil { 87 - if errors.Is(err, os.ErrNotExist) { 88 - return []age.Identity{}, nil 85 + // should we try others 86 + paths := []string{filepath.Join(home, ".ssh", "id_ed25519")} 87 + var identities []age.Identity 88 + for _, path := range paths { 89 + key, err := os.ReadFile(path) 90 + if err != nil { 91 + if os.IsNotExist(err) { 92 + continue 93 + } 94 + return nil, err 89 95 } 90 - return nil, err 91 - } 92 96 93 - identity, err := agessh.ParseIdentity(key) 94 - if err != nil { 95 - return nil, fmt.Errorf("parse ssh identity %q: %w", path, err) 97 + identity, err := agessh.ParseIdentity(key) 98 + if err != nil { 99 + return nil, fmt.Errorf("parse ssh identity %q: %w", path, err) 100 + } 101 + identities = append(identities, identity) 96 102 } 97 103 98 - return []age.Identity{identity}, nil 104 + return identities, nil 99 105 }