diff --git a/routers/hat/hat.go b/routers/hat/hat.go index ca9a3b5..55218ef 100644 --- a/routers/hat/hat.go +++ b/routers/hat/hat.go @@ -133,6 +133,7 @@ func Routers() *web.Route { m.Get("/code", context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode), repo.Code) m.Combo("").Delete(reqToken(), reqOwner(), repo.Delete) m.Group("/actions", func() { + m.Get("/secrets", context.ReferencesGitRepo(), actions.ListActionsSecrets) m.Get("", context.ReferencesGitRepo(), actions.ListActions) m.Post("/disable", reqAdmin(), actions.DisableWorkflowFile) m.Post("/enable", reqAdmin(), actions.EnableWorkflowFile) diff --git a/routers/hat/repo/actions/actions.go b/routers/hat/repo/actions/actions.go index c9de5a9..b44e472 100644 --- a/routers/hat/repo/actions/actions.go +++ b/routers/hat/repo/actions/actions.go @@ -2,18 +2,20 @@ package actions import ( "bytes" - "code.gitea.io/gitea/modules/timeutil" "errors" "fmt" "net/http" "strings" "time" + "code.gitea.io/gitea/modules/timeutil" + stdCtx "context" actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" + secret_model "code.gitea.io/gitea/models/secret" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/actions" @@ -22,8 +24,10 @@ import ( "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" + "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/web/repo" actions_service "code.gitea.io/gitea/services/actions" "code.gitea.io/gitea/services/convert" @@ -33,6 +37,36 @@ import ( "xorm.io/builder" ) +func ListActionsSecrets(ctx *context.APIContext) { + opts := &secret_model.FindSecretsOptions{ + RepoID: ctx.Repo.Repository.ID, + ListOptions: utils.GetListOptions(ctx), + } + + count, err := secret_model.CountSecrets(ctx, opts) + if err != nil { + ctx.InternalServerError(err) + return + } + + secrets, err := secret_model.FindSecrets(ctx, *opts) + if err != nil { + ctx.InternalServerError(err) + return + } + + apiSecrets := make([]*api.Secret, len(secrets)) + for k, v := range secrets { + apiSecrets[k] = &api.Secret{ + Name: v.Name, + Created: v.CreatedUnix.AsTime(), + } + } + + ctx.SetTotalCountHeader(count) + ctx.JSON(http.StatusOK, apiSecrets) +} + func Run(ctx *context.APIContext) { workflow := ctx.FormString("workflow") ref := ctx.FormString("ref")