loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add get actions runner registration token for API routes, repo, org, user and global level (#27144)

Replace #23761

---------

Co-authored-by: Denys Konovalov <kontakt@denyskon.de>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>

authored by

Lunny Xiao
Denys Konovalov
techknowlogick
and committed by
GitHub
baf0d402 4c29c759

+285 -14
+26
routers/api/v1/admin/runners.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package admin 5 + 6 + import ( 7 + "code.gitea.io/gitea/modules/context" 8 + "code.gitea.io/gitea/routers/api/v1/shared" 9 + ) 10 + 11 + // https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization 12 + 13 + // GetRegistrationToken returns the token to register global runners 14 + func GetRegistrationToken(ctx *context.APIContext) { 15 + // swagger:operation GET /admin/runners/registration-token admin adminGetRunnerRegistrationToken 16 + // --- 17 + // summary: Get an global actions runner registration token 18 + // produces: 19 + // - application/json 20 + // parameters: 21 + // responses: 22 + // "200": 23 + // "$ref": "#/responses/RegistrationToken" 24 + 25 + shared.GetRegistrationToken(ctx, 0, 0) 26 + }
+35 -14
routers/api/v1/api.go
··· 948 948 Post(bind(api.CreateEmailOption{}), user.AddEmail). 949 949 Delete(bind(api.DeleteEmailOption{}), user.DeleteEmail) 950 950 951 - // create or update a user's actions secrets 952 - m.Group("/actions/secrets", func() { 953 - m.Combo("/{secretname}"). 954 - Put(bind(api.CreateOrUpdateSecretOption{}), user.CreateOrUpdateSecret). 955 - Delete(user.DeleteSecret) 951 + // manage user-level actions features 952 + m.Group("/actions", func() { 953 + m.Group("/secrets", func() { 954 + m.Combo("/{secretname}"). 955 + Put(bind(api.CreateOrUpdateSecretOption{}), user.CreateOrUpdateSecret). 956 + Delete(user.DeleteSecret) 957 + }) 958 + 959 + m.Group("/runners", func() { 960 + m.Get("/registration-token", reqToken(), user.GetRegistrationToken) 961 + }) 956 962 }) 957 963 958 964 m.Get("/followers", user.ListMyFollowers) ··· 1052 1058 m.Post("/accept", repo.AcceptTransfer) 1053 1059 m.Post("/reject", repo.RejectTransfer) 1054 1060 }, reqToken()) 1055 - m.Group("/actions/secrets", func() { 1056 - m.Combo("/{secretname}"). 1057 - Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret). 1058 - Delete(reqToken(), reqOwner(), repo.DeleteSecret) 1061 + m.Group("/actions", func() { 1062 + m.Group("/secrets", func() { 1063 + m.Combo("/{secretname}"). 1064 + Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret). 1065 + Delete(reqToken(), reqOwner(), repo.DeleteSecret) 1066 + }) 1067 + 1068 + m.Group("/runners", func() { 1069 + m.Get("/registration-token", reqToken(), reqOwner(), repo.GetRegistrationToken) 1070 + }) 1059 1071 }) 1060 1072 m.Group("/hooks/git", func() { 1061 1073 m.Combo("").Get(repo.ListGitHooks) ··· 1422 1434 m.Combo("/{username}").Get(reqToken(), org.IsMember). 1423 1435 Delete(reqToken(), reqOrgOwnership(), org.DeleteMember) 1424 1436 }) 1425 - m.Group("/actions/secrets", func() { 1426 - m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets) 1427 - m.Combo("/{secretname}"). 1428 - Put(reqToken(), reqOrgOwnership(), bind(api.CreateOrUpdateSecretOption{}), org.CreateOrUpdateSecret). 1429 - Delete(reqToken(), reqOrgOwnership(), org.DeleteSecret) 1437 + m.Group("/actions", func() { 1438 + m.Group("/secrets", func() { 1439 + m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets) 1440 + m.Combo("/{secretname}"). 1441 + Put(reqToken(), reqOrgOwnership(), bind(api.CreateOrUpdateSecretOption{}), org.CreateOrUpdateSecret). 1442 + Delete(reqToken(), reqOrgOwnership(), org.DeleteSecret) 1443 + }) 1444 + 1445 + m.Group("/runners", func() { 1446 + m.Get("/registration-token", reqToken(), reqOrgOwnership(), org.GetRegistrationToken) 1447 + }) 1430 1448 }) 1431 1449 m.Group("/public_members", func() { 1432 1450 m.Get("", org.ListPublicMembers) ··· 1517 1535 m.Combo("/{id}").Get(admin.GetHook). 1518 1536 Patch(bind(api.EditHookOption{}), admin.EditHook). 1519 1537 Delete(admin.DeleteHook) 1538 + }) 1539 + m.Group("/runners", func() { 1540 + m.Get("/registration-token", admin.GetRegistrationToken) 1520 1541 }) 1521 1542 }, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryAdmin), reqToken(), reqSiteAdmin()) 1522 1543
routers/api/v1/org/action.go routers/api/v1/org/secrets.go
+31
routers/api/v1/org/runners.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package org 5 + 6 + import ( 7 + "code.gitea.io/gitea/modules/context" 8 + "code.gitea.io/gitea/routers/api/v1/shared" 9 + ) 10 + 11 + // https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization 12 + 13 + // GetRegistrationToken returns the token to register org runners 14 + func GetRegistrationToken(ctx *context.APIContext) { 15 + // swagger:operation GET /orgs/{org}/actions/runners/registration-token organization orgGetRunnerRegistrationToken 16 + // --- 17 + // summary: Get an organization's actions runner registration token 18 + // produces: 19 + // - application/json 20 + // parameters: 21 + // - name: org 22 + // in: path 23 + // description: name of the organization 24 + // type: string 25 + // required: true 26 + // responses: 27 + // "200": 28 + // "$ref": "#/responses/RegistrationToken" 29 + 30 + shared.GetRegistrationToken(ctx, ctx.Org.Organization.ID, 0) 31 + }
+34
routers/api/v1/repo/runners.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package repo 5 + 6 + import ( 7 + "code.gitea.io/gitea/modules/context" 8 + "code.gitea.io/gitea/routers/api/v1/shared" 9 + ) 10 + 11 + // GetRegistrationToken returns the token to register repo runners 12 + func GetRegistrationToken(ctx *context.APIContext) { 13 + // swagger:operation GET /repos/{owner}/{repo}/runners/registration-token repository repoGetRunnerRegistrationToken 14 + // --- 15 + // summary: Get a repository's actions runner registration token 16 + // produces: 17 + // - application/json 18 + // parameters: 19 + // - name: owner 20 + // in: path 21 + // description: owner of the repo 22 + // type: string 23 + // required: true 24 + // - name: repo 25 + // in: path 26 + // description: name of the repo 27 + // type: string 28 + // required: true 29 + // responses: 30 + // "200": 31 + // "$ref": "#/responses/RegistrationToken" 32 + 33 + shared.GetRegistrationToken(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID) 34 + }
+32
routers/api/v1/shared/runners.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package shared 5 + 6 + import ( 7 + "errors" 8 + "net/http" 9 + 10 + actions_model "code.gitea.io/gitea/models/actions" 11 + "code.gitea.io/gitea/modules/context" 12 + "code.gitea.io/gitea/modules/util" 13 + ) 14 + 15 + // RegistrationToken is response related to registeration token 16 + // swagger:response RegistrationToken 17 + type RegistrationToken struct { 18 + Token string `json:"token"` 19 + } 20 + 21 + func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) { 22 + token, err := actions_model.GetLatestRunnerToken(ctx, ownerID, repoID) 23 + if errors.Is(err, util.ErrNotExist) || (token != nil && !token.IsActive) { 24 + token, err = actions_model.NewRunnerToken(ctx, ownerID, repoID) 25 + } 26 + if err != nil { 27 + ctx.InternalServerError(err) 28 + return 29 + } 30 + 31 + ctx.JSON(http.StatusOK, RegistrationToken{Token: token.Token}) 32 + }
+26
routers/api/v1/user/runners.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package user 5 + 6 + import ( 7 + "code.gitea.io/gitea/modules/context" 8 + "code.gitea.io/gitea/routers/api/v1/shared" 9 + ) 10 + 11 + // https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization 12 + 13 + // GetRegistrationToken returns the token to register user runners 14 + func GetRegistrationToken(ctx *context.APIContext) { 15 + // swagger:operation GET /user/actions/runners/registration-token user userGetRunnerRegistrationToken 16 + // --- 17 + // summary: Get an user's actions runner registration token 18 + // produces: 19 + // - application/json 20 + // parameters: 21 + // responses: 22 + // "200": 23 + // "$ref": "#/responses/RegistrationToken" 24 + 25 + shared.GetRegistrationToken(ctx, ctx.Doer.ID, 0) 26 + }
+101
templates/swagger/v1_json.tmpl
··· 392 392 } 393 393 } 394 394 }, 395 + "/admin/runners/registration-token": { 396 + "get": { 397 + "produces": [ 398 + "application/json" 399 + ], 400 + "tags": [ 401 + "admin" 402 + ], 403 + "summary": "Get an global actions runner registration token", 404 + "operationId": "adminGetRunnerRegistrationToken", 405 + "responses": { 406 + "200": { 407 + "$ref": "#/responses/RegistrationToken" 408 + } 409 + } 410 + } 411 + }, 395 412 "/admin/unadopted": { 396 413 "get": { 397 414 "produces": [ ··· 1558 1575 }, 1559 1576 "404": { 1560 1577 "$ref": "#/responses/notFound" 1578 + } 1579 + } 1580 + } 1581 + }, 1582 + "/orgs/{org}/actions/runners/registration-token": { 1583 + "get": { 1584 + "produces": [ 1585 + "application/json" 1586 + ], 1587 + "tags": [ 1588 + "organization" 1589 + ], 1590 + "summary": "Get an organization's actions runner registration token", 1591 + "operationId": "orgGetRunnerRegistrationToken", 1592 + "parameters": [ 1593 + { 1594 + "type": "string", 1595 + "description": "name of the organization", 1596 + "name": "org", 1597 + "in": "path", 1598 + "required": true 1599 + } 1600 + ], 1601 + "responses": { 1602 + "200": { 1603 + "$ref": "#/responses/RegistrationToken" 1561 1604 } 1562 1605 } 1563 1606 } ··· 12359 12402 } 12360 12403 } 12361 12404 }, 12405 + "/repos/{owner}/{repo}/runners/registration-token": { 12406 + "get": { 12407 + "produces": [ 12408 + "application/json" 12409 + ], 12410 + "tags": [ 12411 + "repository" 12412 + ], 12413 + "summary": "Get a repository's actions runner registration token", 12414 + "operationId": "repoGetRunnerRegistrationToken", 12415 + "parameters": [ 12416 + { 12417 + "type": "string", 12418 + "description": "owner of the repo", 12419 + "name": "owner", 12420 + "in": "path", 12421 + "required": true 12422 + }, 12423 + { 12424 + "type": "string", 12425 + "description": "name of the repo", 12426 + "name": "repo", 12427 + "in": "path", 12428 + "required": true 12429 + } 12430 + ], 12431 + "responses": { 12432 + "200": { 12433 + "$ref": "#/responses/RegistrationToken" 12434 + } 12435 + } 12436 + } 12437 + }, 12362 12438 "/repos/{owner}/{repo}/signing-key.gpg": { 12363 12439 "get": { 12364 12440 "produces": [ ··· 14513 14589 "responses": { 14514 14590 "200": { 14515 14591 "$ref": "#/responses/User" 14592 + } 14593 + } 14594 + } 14595 + }, 14596 + "/user/actions/runners/registration-token": { 14597 + "get": { 14598 + "produces": [ 14599 + "application/json" 14600 + ], 14601 + "tags": [ 14602 + "user" 14603 + ], 14604 + "summary": "Get an user's actions runner registration token", 14605 + "operationId": "userGetRunnerRegistrationToken", 14606 + "responses": { 14607 + "200": { 14608 + "$ref": "#/responses/RegistrationToken" 14516 14609 } 14517 14610 } 14518 14611 } ··· 23723 23816 "type": "array", 23724 23817 "items": { 23725 23818 "$ref": "#/definitions/Reference" 23819 + } 23820 + } 23821 + }, 23822 + "RegistrationToken": { 23823 + "description": "RegistrationToken is response related to registeration token", 23824 + "headers": { 23825 + "token": { 23826 + "type": "string" 23726 23827 } 23727 23828 } 23728 23829 },