aboutsummaryrefslogtreecommitdiff
path: root/internal/utils/ssh_helpers.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-19 13:09:56 +0530
committerishaan <contact@ishaan.cc>2026-07-19 13:09:56 +0530
commit8a5de371fccb89635bc1a624d8b1aca52aa18da4 (patch)
tree89f3b2bec4e2425823534d4db46e3aecc2a15d91 /internal/utils/ssh_helpers.go
parent80b1c6deec723095f08de6aee289d4fb32ca9337 (diff)
better config (package)
Diffstat (limited to 'internal/utils/ssh_helpers.go')
-rw-r--r--internal/utils/ssh_helpers.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/utils/ssh_helpers.go b/internal/utils/ssh_helpers.go
new file mode 100644
index 0000000..9ffcf0a
--- /dev/null
+++ b/internal/utils/ssh_helpers.go
@@ -0,0 +1,38 @@
+package utils
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+ "strings"
+)
+
+func GetPubKeyFromService(username, service string) ([]byte, error) {
+ // TODO: Read custom services from config
+
+ 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"},
+ }
+
+ url := strings.TrimSuffix(services[service][0], "/") + "/" + username + services[service][1]
+
+ 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
+}
+