-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add API routes to get runner registration token #27144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
eec5ed0
Add get actions runner registration token for API routes, repo, org a…
lunny 3754b65
update swagger
lunny 177ca7c
Fix lint
lunny e805e66
Fix lint
lunny b796adf
Fix comments
lunny aaaf6a3
Merge branch 'main' into lunny/api_registration_token
lunny 1277bae
Merge branch 'main' into lunny/api_registration_token
lunny 5bd1717
Merge branch 'main' into lunny/api_registration_token
lunny df47c02
Fix bug
lunny 31e5b84
Merge branch 'lunny/api_registration_token' of github.com:lunny/gitea…
lunny 0e49627
Merge branch 'main' into lunny/api_registration_token
GiteaBot d1c14f9
Apply suggestions from code review
lunny 36c6559
Merge branch 'main' into lunny/api_registration_token
lunny 3becab2
Fix swagger
lunny 1a50dfe
Merge branch 'lunny/api_registration_token' of github.com:lunny/gitea…
lunny bba250f
Add missed user runners
lunny 1eb1b24
Update api.go
techknowlogick 2e669a1
Merge branch 'main' into lunny/api_registration_token
lunny 0b2924d
Merge branch 'lunny/api_registration_token' of github.com:lunny/gitea…
lunny 963afb5
Merge branch 'main' into lunny/api_registration_token
lunny c8a0f26
Merge branch 'main' into lunny/api_registration_token
GiteaBot f0e7edf
Merge branch 'main' into lunny/api_registration_token
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package admin | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/routers/api/v1/shared" | ||
) | ||
|
||
// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization | ||
|
||
// GetRegistrationToken returns the token to register global runners | ||
func GetRegistrationToken(ctx *context.APIContext) { | ||
// swagger:operation GET /admin/runners/registration-token admin adminGetRunnerRegistrationToken | ||
// --- | ||
// summary: Get an global actions runner registration token | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/RegistrationToken" | ||
|
||
shared.GetRegistrationToken(ctx, 0, 0) | ||
} |
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package org | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/routers/api/v1/shared" | ||
) | ||
|
||
// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization | ||
|
||
// GetRegistrationToken returns the token to register org runners | ||
func GetRegistrationToken(ctx *context.APIContext) { | ||
// swagger:operation GET /orgs/{org}/actions/runners/registration-token organization orgGetRunnerRegistrationToken | ||
// --- | ||
// summary: Get an organization's actions runner registration token | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: org | ||
// in: path | ||
// description: name of the organization | ||
// type: string | ||
// required: true | ||
// responses: | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// "200": | ||
// "$ref": "#/responses/RegistrationToken" | ||
|
||
shared.GetRegistrationToken(ctx, ctx.Org.Organization.ID, 0) | ||
} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/routers/api/v1/shared" | ||
) | ||
|
||
// GetRegistrationToken returns the token to register repo runners | ||
func GetRegistrationToken(ctx *context.APIContext) { | ||
// swagger:operation GET /repos/{owner}/{repo}/runners/registration-token repository repoGetRunnerRegistrationToken | ||
// --- | ||
// summary: Get a repository's actions runner registration token | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: owner | ||
// in: path | ||
// description: owner of the repo | ||
// type: string | ||
// required: true | ||
// - name: repo | ||
// in: path | ||
// description: name of the repo | ||
// type: string | ||
// required: true | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/RegistrationToken" | ||
|
||
shared.GetRegistrationToken(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package shared | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
actions_model "code.gitea.io/gitea/models/actions" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
||
// RegistrationToken is response related to registeration token | ||
// swagger:response RegistrationToken | ||
type RegistrationToken struct { | ||
Token string `json:"token"` | ||
} | ||
|
||
func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) { | ||
token, err := actions_model.GetLatestRunnerToken(ctx, ownerID, repoID) | ||
if errors.Is(err, util.ErrNotExist) || (token != nil && !token.IsActive) { | ||
token, err = actions_model.NewRunnerToken(ctx, ownerID, repoID) | ||
} | ||
if err != nil { | ||
ctx.InternalServerError(err) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, RegistrationToken{Token: token.Token}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package user | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/routers/api/v1/shared" | ||
) | ||
|
||
// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization | ||
|
||
// GetRegistrationToken returns the token to register user runners | ||
func GetRegistrationToken(ctx *context.APIContext) { | ||
// swagger:operation GET /user/actions/runners/registration-token user userGetRunnerRegistrationToken | ||
// --- | ||
// summary: Get an user's actions runner registration token | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/RegistrationToken" | ||
|
||
shared.GetRegistrationToken(ctx, ctx.Doer.ID, 0) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.