diff options
author | zeripath <art27@cantab.net> | 2019-12-17 01:49:07 +0000 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-12-16 20:49:07 -0500 |
commit | d1a49977b089afefc40172711d02eb795d2234de (patch) | |
tree | b32acdcdf6b93a64f766e4fafeb70f75a881a1ab /modules/private/key.go | |
parent | 1707f59966df7fa4375235dbf43326d382eeaf97 (diff) | |
download | gitea-d1a49977b089afefc40172711d02eb795d2234de.tar.gz gitea-d1a49977b089afefc40172711d02eb795d2234de.zip |
AuthorizedKeysCommand should not query db directly (#9371)
* AuthorizedKeysCommand should not query db directly
* Update routers/private/internal.go
* Fix import order
Diffstat (limited to 'modules/private/key.go')
-rw-r--r-- | modules/private/key.go | 25 |
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 +} |