aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/private/key.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/private/key.go b/modules/private/key.go
index ebc28eb871..40e1c492f8 100644
--- a/modules/private/key.go
+++ b/modules/private/key.go
@@ -6,6 +6,8 @@ package private
import (
"fmt"
+ "io/ioutil"
+ "net/http"
"code.gitea.io/gitea/modules/setting"
)
@@ -27,3 +29,26 @@ func UpdatePublicKeyInRepo(keyID, repoID int64) error {
}
return nil
}
+
+// AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part)
+// and returns public key found.
+func AuthorizedPublicKeyByContent(content string) (string, error) {
+ // Ask for running deliver hook and test pull request tasks.
+ reqURL := setting.LocalURL + fmt.Sprintf("api/internal/ssh/authorized_keys")
+ req := newInternalRequest(reqURL, "POST")
+ req.Param("content", content)
+ resp, err := req.Response()
+ if err != nil {
+ return "", err
+ }
+
+ defer resp.Body.Close()
+
+ // All 2XX status codes are accepted and others will return an error
+ if resp.StatusCode != http.StatusOK {
+ return "", fmt.Errorf("Failed to update public key: %s", decodeJSONError(resp).Err)
+ }
+ bs, err := ioutil.ReadAll(resp.Body)
+
+ return string(bs), err
+}