mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-15 18:56:59 +00:00
[CLI] implement forgejo-cli actions register
(cherry picked from commit 2f95143000
)
This commit is contained in:
parent
e085d6d273
commit
42f2f8731e
9 changed files with 517 additions and 7 deletions
48
routers/private/forgejo.go
Normal file
48
routers/private/forgejo.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package private
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/private"
|
||||
)
|
||||
|
||||
func ActionsRunnerRegister(ctx *context.PrivateContext) {
|
||||
var registerRequest private.ActionsRunnerRegisterRequest
|
||||
rd := ctx.Req.Body
|
||||
defer rd.Close()
|
||||
|
||||
if err := json.NewDecoder(rd).Decode(®isterRequest); err != nil {
|
||||
log.Error("%v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
Err: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
owner, repo, err := parseScope(ctx, registerRequest.Scope)
|
||||
if err != nil {
|
||||
log.Error("%v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
Err: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
runner, err := actions_model.RegisterRunner(ctx, owner, repo, registerRequest.Token, registerRequest.Labels, registerRequest.Name, registerRequest.Version)
|
||||
if err != nil {
|
||||
err := fmt.Sprintf("error while registering runner: %v", err)
|
||||
log.Error("%v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
Err: err,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.PlainText(http.StatusOK, runner.UUID)
|
||||
}
|
|
@ -56,6 +56,7 @@ func Routes() *web.Route {
|
|||
// Since internal API will be sent only from Gitea sub commands and it's under control (checked by InternalToken), we can trust the headers.
|
||||
r.Use(chi_middleware.RealIP)
|
||||
|
||||
r.Post("/actions/register", ActionsRunnerRegister)
|
||||
r.Post("/ssh/authorized_keys", AuthorizedPublicKeyByContent)
|
||||
r.Post("/ssh/{id}/update/{repoid}", UpdatePublicKeyInRepo)
|
||||
r.Post("/ssh/log", bind(private.SSHLogOption{}), SSHLog)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue