loading up the forgejo repo on tangled to test page performance
1// Copyright 2018 The Gitea Authors. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4package private
5
6import (
7 "net/http"
8
9 asymkey_model "forgejo.org/models/asymkey"
10 "forgejo.org/modules/private"
11 "forgejo.org/modules/timeutil"
12 "forgejo.org/services/context"
13)
14
15// UpdatePublicKeyInRepo update public key and deploy key updates
16func UpdatePublicKeyInRepo(ctx *context.PrivateContext) {
17 keyID := ctx.ParamsInt64(":id")
18 repoID := ctx.ParamsInt64(":repoid")
19 if err := asymkey_model.UpdatePublicKeyUpdated(ctx, keyID); err != nil {
20 ctx.JSON(http.StatusInternalServerError, private.Response{
21 Err: err.Error(),
22 })
23 return
24 }
25
26 deployKey, err := asymkey_model.GetDeployKeyByRepo(ctx, keyID, repoID)
27 if err != nil {
28 if asymkey_model.IsErrDeployKeyNotExist(err) {
29 ctx.PlainText(http.StatusOK, "success")
30 return
31 }
32 ctx.JSON(http.StatusInternalServerError, private.Response{
33 Err: err.Error(),
34 })
35 return
36 }
37 deployKey.UpdatedUnix = timeutil.TimeStampNow()
38 if err = asymkey_model.UpdateDeployKeyCols(ctx, deployKey, "updated_unix"); err != nil {
39 ctx.JSON(http.StatusInternalServerError, private.Response{
40 Err: err.Error(),
41 })
42 return
43 }
44
45 ctx.PlainText(http.StatusOK, "success")
46}
47
48// AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part)
49// and returns public key found.
50func AuthorizedPublicKeyByContent(ctx *context.PrivateContext) {
51 content := ctx.FormString("content")
52
53 publicKey, err := asymkey_model.SearchPublicKeyByContent(ctx, content)
54 if err != nil {
55 ctx.JSON(http.StatusInternalServerError, private.Response{
56 Err: err.Error(),
57 })
58 return
59 }
60 ctx.PlainText(http.StatusOK, publicKey.AuthorizedString())
61}