aboutsummaryrefslogtreecommitdiff
path: root/internal/utils/ssh_helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/utils/ssh_helpers.go')
-rw-r--r--internal/utils/ssh_helpers.go29
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
}
-