|
| 1 | +// Copyright 2023 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package org |
| 5 | + |
| 6 | +import ( |
| 7 | + "net/http" |
| 8 | + |
| 9 | + "code.gitea.io/gitea/models/secret" |
| 10 | + "code.gitea.io/gitea/modules/context" |
| 11 | + api "code.gitea.io/gitea/modules/structs" |
| 12 | + "code.gitea.io/gitea/routers/api/v1/utils" |
| 13 | +) |
| 14 | + |
| 15 | +// ListActionsSecrets list an organization's actions secrets |
| 16 | +func ListActionsSecrets(ctx *context.APIContext) { |
| 17 | + // swagger:operation GET /orgs/{org}/actions/secrets organization orgListActionsSecrets |
| 18 | + // --- |
| 19 | + // summary: List an organization's actions secrets |
| 20 | + // produces: |
| 21 | + // - application/json |
| 22 | + // parameters: |
| 23 | + // - name: org |
| 24 | + // in: path |
| 25 | + // description: name of the organization |
| 26 | + // type: string |
| 27 | + // required: true |
| 28 | + // - name: page |
| 29 | + // in: query |
| 30 | + // description: page number of results to return (1-based) |
| 31 | + // type: integer |
| 32 | + // - name: limit |
| 33 | + // in: query |
| 34 | + // description: page size of results |
| 35 | + // type: integer |
| 36 | + // responses: |
| 37 | + // "200": |
| 38 | + // "$ref": "#/responses/SecretList" |
| 39 | + |
| 40 | + listActionsSecrets(ctx) |
| 41 | +} |
| 42 | + |
| 43 | +// listActionsSecrets list an organization's actions secrets |
| 44 | +func listActionsSecrets(ctx *context.APIContext) { |
| 45 | + opts := &secret.FindSecretsOptions{ |
| 46 | + OwnerID: ctx.Org.Organization.ID, |
| 47 | + ListOptions: utils.GetListOptions(ctx), |
| 48 | + } |
| 49 | + |
| 50 | + count, err := secret.CountSecrets(ctx, opts) |
| 51 | + if err != nil { |
| 52 | + ctx.InternalServerError(err) |
| 53 | + return |
| 54 | + } |
| 55 | + |
| 56 | + secrets, err := secret.FindSecrets(ctx, *opts) |
| 57 | + if err != nil { |
| 58 | + ctx.InternalServerError(err) |
| 59 | + return |
| 60 | + } |
| 61 | + |
| 62 | + apiSecrets := make([]*api.Secret, len(secrets)) |
| 63 | + for k, v := range secrets { |
| 64 | + apiSecrets[k] = &api.Secret{ |
| 65 | + Name: v.Name, |
| 66 | + Created: v.CreatedUnix.AsTime(), |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + ctx.SetTotalCountHeader(count) |
| 71 | + ctx.JSON(http.StatusOK, apiSecrets) |
| 72 | +} |
0 commit comments