-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add API endpoint to get token for registering runners for repos #23761
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package structs // import "code.gitea.io/gitea/modules/structs" | ||
|
||
// ActionRunnerToken represents an action runner token | ||
// swagger:model | ||
type ActionRunnerToken struct { | ||
ID int64 `json:"id"` | ||
Token string `json:"token"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1162,6 +1162,11 @@ func Routes(ctx gocontext.Context) *web.Route { | |
}, reqAnyRepoReader()) | ||
m.Get("/issue_templates", context.ReferencesGitRepo(), repo.GetIssueTemplates) | ||
m.Get("/languages", reqRepoReader(unit.TypeCode), repo.GetLanguages) | ||
|
||
// TODO: list runners | ||
// TODO: update runner | ||
// TODO: delete runner | ||
m.Put("/runners", reqToken(auth_model.AccessTokenScopeRepo), reqRepoWriter(unit.TypeActions), repo.GenerateRunnerToken) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, this route should probably be called |
||
}, repoAssignment()) | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
actions_model "code.gitea.io/gitea/models/actions" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/util" | ||
"code.gitea.io/gitea/services/convert" | ||
) | ||
|
||
// GenerateRunnerToken generate a new runner token for a repository. | ||
func GenerateRunnerToken(ctx *context.APIContext) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any checks to see if Actions are enabled for the instance/org/repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, we should probably check that. |
||
// swagger:operation PUT /repos/{owner}/{repo}/runners repository repoGenerateRunnerToken | ||
// --- | ||
// summary: Generate a new runner token for a repository. | ||
// 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/ActionRunnerToken" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about additionally returning a 404 or 403 in case actions are disabled? |
||
|
||
token, err := actions_model.GetUnactivatedRunnerToken(ctx, ctx.Repo.Owner.ID, ctx.Repo.Repository.ID) | ||
if errors.Is(err, util.ErrNotExist) { | ||
token, err = actions_model.NewRunnerToken(ctx, ctx.Repo.Owner.ID, ctx.Repo.Repository.ID) | ||
if err != nil { | ||
ctx.ServerError("CreateRunnerToken", err) | ||
return | ||
} | ||
} else if err != nil { | ||
ctx.ServerError("GetUnactivatedRunnerToken", err) | ||
return | ||
} | ||
ctx.JSON(http.StatusOK, convert.ToAPIActionRunnerToken(token)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package convert | ||
|
||
import ( | ||
actions_model "code.gitea.io/gitea/models/actions" | ||
api "code.gitea.io/gitea/modules/structs" | ||
) | ||
|
||
func ToAPIActionRunnerToken(token *actions_model.ActionRunnerToken) *api.ActionRunnerToken { | ||
return &api.ActionRunnerToken{ | ||
ID: token.ID, | ||
Token: token.Token, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that only
write
or evenadmin
?