From 80b1c6deec723095f08de6aee289d4fb32ca9337 Mon Sep 17 00:00:00 2001 From: ishaan Date: Sun, 19 Jul 2026 12:51:29 +0530 Subject: add key discovery --- internal/utils/utils.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'internal/utils/utils.go') diff --git a/internal/utils/utils.go b/internal/utils/utils.go index cea00a3..a43b268 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -3,6 +3,8 @@ package utils import ( "crypto/rand" "fmt" + "io" + "net/http" "os" "os/signal" "strconv" @@ -100,3 +102,35 @@ func CheckFileAuthMode(notePath string) (crypt.AuthMode, error) { return headers.Auth, nil } + +func GetPubKeyFromService(username, service string) ([]byte, error) { + // TODO: Read custom services from config + + var url string + + switch service { + case "github": + url = "https://github.com/" + username + ".keys" + case "gitlab": + url = "https://gitlab.com/" + username + ".keys" + default: + return nil, fmt.Errorf("unknown service: %s", service) + } + + resp, err := http.Get(url) + if err != nil { + return nil, fmt.Errorf("failed to fetch key from %s: %w", service, err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("%s returned status %d", service, resp.StatusCode) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response from %s: %w", service, err) + } + + return body, nil +} -- cgit v1.3