From d6449a232e6bd9eb46132c7403a05ac1a756b619 Mon Sep 17 00:00:00 2001 From: ishaan Date: Sun, 19 Jul 2026 14:21:13 +0530 Subject: feat: discover SSH keys from remote services (eg. bob@github fetches bob's keys from GitHub) --- internal/utils/ssh_helpers.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'internal/utils/ssh_helpers.go') 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 } - -- cgit v1.3