diff options
| author | ishaan <contact@ishaan.cc> | 2026-07-19 14:21:13 +0530 |
|---|---|---|
| committer | ishaan <contact@ishaan.cc> | 2026-07-19 14:21:13 +0530 |
| commit | d6449a232e6bd9eb46132c7403a05ac1a756b619 (patch) | |
| tree | a88c144f54557306caf69ed739de15857fc898d4 /internal/utils/ssh_helpers.go | |
| parent | 8a5de371fccb89635bc1a624d8b1aca52aa18da4 (diff) | |
feat: discover SSH keys from remote services (eg. bob@github fetches bob's keys from GitHub)
Diffstat (limited to 'internal/utils/ssh_helpers.go')
| -rw-r--r-- | internal/utils/ssh_helpers.go | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/internal/utils/ssh_helpers.go b/internal/utils/ssh_helpers.go index 9ffcf0a..903fc11 100644 --- a/internal/utils/ssh_helpers.go +++ b/internal/utils/ssh_helpers.go @@ -5,18 +5,34 @@ import ( "io" "net/http" "strings" + + "gitlab.com/whiteboardguy/eno/internal/config" ) -func GetPubKeyFromService(username, service string) ([]byte, error) { - // TODO: Read custom services from config +func pubkeyServiceURL(username, service string) (string, error) { + if url, ok := config.Conf.PubkeyServices[service]; ok { + return strings.ReplaceAll(url, "%s", username), nil + } services := map[string][2]string{ - "github" : [2]string{"https://github.com/", ".keys"}, - "gitlab" : [2]string{"https://gitlab.com/", ".keys"}, - "codeberg": [2]string{"https://codeberg.org", ".keys"}, + "github": {"https://github.com/", ".keys"}, + "gitlab": {"https://gitlab.com/", ".keys"}, + "codeberg": {"https://codeberg.org", ".keys"}, } - url := strings.TrimSuffix(services[service][0], "/") + "/" + username + services[service][1] + s, ok := services[service] + if !ok { + return "", fmt.Errorf("unknown service: %s", service) + } + + return strings.TrimSuffix(s[0], "/") + "/" + username + s[1], nil +} + +func GetPubKeyFromService(username, service string) ([]byte, error) { + url, err := pubkeyServiceURL(username, service) + if err != nil { + return nil, err + } resp, err := http.Get(url) if err != nil { @@ -35,4 +51,3 @@ func GetPubKeyFromService(username, service string) ([]byte, error) { return body, nil } - |