You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

key.go 1.1KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package private
  4. import (
  5. "context"
  6. "fmt"
  7. "code.gitea.io/gitea/modules/setting"
  8. )
  9. // UpdatePublicKeyInRepo update public key and if necessary deploy key updates
  10. func UpdatePublicKeyInRepo(ctx context.Context, keyID, repoID int64) error {
  11. // Ask for running deliver hook and test pull request tasks.
  12. reqURL := setting.LocalURL + fmt.Sprintf("api/internal/ssh/%d/update/%d", keyID, repoID)
  13. req := newInternalRequest(ctx, reqURL, "POST")
  14. _, extra := requestJSONResp(req, &responseText{})
  15. return extra.Error
  16. }
  17. // AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part)
  18. // and returns public key found.
  19. func AuthorizedPublicKeyByContent(ctx context.Context, content string) (string, ResponseExtra) {
  20. // Ask for running deliver hook and test pull request tasks.
  21. reqURL := setting.LocalURL + "api/internal/ssh/authorized_keys"
  22. req := newInternalRequest(ctx, reqURL, "POST")
  23. req.Param("content", content)
  24. resp, extra := requestJSONResp(req, &responseText{})
  25. return resp.Text, extra
  26. }