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.

serv.go 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package private
  4. import (
  5. "context"
  6. "fmt"
  7. "net/url"
  8. asymkey_model "code.gitea.io/gitea/models/asymkey"
  9. "code.gitea.io/gitea/models/perm"
  10. user_model "code.gitea.io/gitea/models/user"
  11. "code.gitea.io/gitea/modules/setting"
  12. )
  13. // KeyAndOwner is the response from ServNoCommand
  14. type KeyAndOwner struct {
  15. Key *asymkey_model.PublicKey `json:"key"`
  16. Owner *user_model.User `json:"user"`
  17. }
  18. // ServNoCommand returns information about the provided key
  19. func ServNoCommand(ctx context.Context, keyID int64) (*asymkey_model.PublicKey, *user_model.User, error) {
  20. reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/none/%d", keyID)
  21. req := newInternalRequest(ctx, reqURL, "GET")
  22. keyAndOwner, extra := requestJSONResp(req, &KeyAndOwner{})
  23. if extra.HasError() {
  24. return nil, nil, extra.Error
  25. }
  26. return keyAndOwner.Key, keyAndOwner.Owner, nil
  27. }
  28. // ServCommandResults are the results of a call to the private route serv
  29. type ServCommandResults struct {
  30. IsWiki bool
  31. DeployKeyID int64
  32. KeyID int64 // public key
  33. KeyName string // this field is ambiguous, it can be the name of DeployKey, or the name of the PublicKey
  34. UserName string
  35. UserEmail string
  36. UserID int64
  37. OwnerName string
  38. RepoName string
  39. RepoID int64
  40. }
  41. // ServCommand preps for a serv call
  42. func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, mode perm.AccessMode, verbs ...string) (*ServCommandResults, ResponseExtra) {
  43. reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s?mode=%d",
  44. keyID,
  45. url.PathEscape(ownerName),
  46. url.PathEscape(repoName),
  47. mode,
  48. )
  49. for _, verb := range verbs {
  50. if verb != "" {
  51. reqURL += fmt.Sprintf("&verb=%s", url.QueryEscape(verb))
  52. }
  53. }
  54. req := newInternalRequest(ctx, reqURL, "GET")
  55. return requestJSONResp(req, &ServCommandResults{})
  56. }