mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
167 lines
4.4 KiB
167 lines
4.4 KiB
1 year ago
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
package org
|
||
|
|
||
|
import (
|
||
1 year ago
|
"errors"
|
||
1 year ago
|
"net/http"
|
||
|
|
||
1 year ago
|
"code.gitea.io/gitea/models/db"
|
||
1 year ago
|
secret_model "code.gitea.io/gitea/models/secret"
|
||
1 year ago
|
"code.gitea.io/gitea/modules/context"
|
||
|
api "code.gitea.io/gitea/modules/structs"
|
||
1 year ago
|
"code.gitea.io/gitea/modules/util"
|
||
1 year ago
|
"code.gitea.io/gitea/modules/web"
|
||
1 year ago
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||
1 year ago
|
secret_service "code.gitea.io/gitea/services/secrets"
|
||
1 year ago
|
)
|
||
|
|
||
|
// ListActionsSecrets list an organization's actions secrets
|
||
|
func ListActionsSecrets(ctx *context.APIContext) {
|
||
|
// swagger:operation GET /orgs/{org}/actions/secrets organization orgListActionsSecrets
|
||
|
// ---
|
||
|
// summary: List an organization's actions secrets
|
||
|
// produces:
|
||
|
// - application/json
|
||
|
// parameters:
|
||
|
// - name: org
|
||
|
// in: path
|
||
|
// description: name of the organization
|
||
|
// type: string
|
||
|
// required: true
|
||
|
// - name: page
|
||
|
// in: query
|
||
|
// description: page number of results to return (1-based)
|
||
|
// type: integer
|
||
|
// - name: limit
|
||
|
// in: query
|
||
|
// description: page size of results
|
||
|
// type: integer
|
||
|
// responses:
|
||
|
// "200":
|
||
|
// "$ref": "#/responses/SecretList"
|
||
1 year ago
|
// "404":
|
||
|
// "$ref": "#/responses/notFound"
|
||
1 year ago
|
|
||
1 year ago
|
opts := &secret_model.FindSecretsOptions{
|
||
1 year ago
|
OwnerID: ctx.Org.Organization.ID,
|
||
|
ListOptions: utils.GetListOptions(ctx),
|
||
|
}
|
||
|
|
||
1 year ago
|
secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts)
|
||
1 year ago
|
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)
|
||
|
}
|
||
1 year ago
|
|
||
1 year ago
|
// create or update one secret of the organization
|
||
1 year ago
|
func CreateOrUpdateSecret(ctx *context.APIContext) {
|
||
1 year ago
|
// swagger:operation PUT /orgs/{org}/actions/secrets/{secretname} organization updateOrgSecret
|
||
|
// ---
|
||
1 year ago
|
// summary: Create or Update a secret value in an organization
|
||
1 year ago
|
// consumes:
|
||
|
// - application/json
|
||
|
// produces:
|
||
|
// - application/json
|
||
|
// parameters:
|
||
|
// - name: org
|
||
|
// in: path
|
||
|
// description: name of organization
|
||
|
// type: string
|
||
|
// required: true
|
||
|
// - name: secretname
|
||
|
// in: path
|
||
|
// description: name of the secret
|
||
|
// type: string
|
||
|
// required: true
|
||
|
// - name: body
|
||
|
// in: body
|
||
|
// schema:
|
||
1 year ago
|
// "$ref": "#/definitions/CreateOrUpdateSecretOption"
|
||
1 year ago
|
// responses:
|
||
1 year ago
|
// "201":
|
||
|
// description: response when creating a secret
|
||
1 year ago
|
// "204":
|
||
1 year ago
|
// description: response when updating a secret
|
||
|
// "400":
|
||
|
// "$ref": "#/responses/error"
|
||
1 year ago
|
// "404":
|
||
|
// "$ref": "#/responses/notFound"
|
||
|
|
||
1 year ago
|
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
|
||
1 year ago
|
|
||
|
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Org.Organization.ID, 0, ctx.Params("secretname"), opt.Data)
|
||
1 year ago
|
if err != nil {
|
||
1 year ago
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||
|
ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err)
|
||
|
} else if errors.Is(err, util.ErrNotExist) {
|
||
|
ctx.Error(http.StatusNotFound, "CreateOrUpdateSecret", err)
|
||
|
} else {
|
||
|
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateSecret", err)
|
||
|
}
|
||
1 year ago
|
return
|
||
|
}
|
||
1 year ago
|
|
||
|
if created {
|
||
1 year ago
|
ctx.Status(http.StatusCreated)
|
||
1 year ago
|
} else {
|
||
|
ctx.Status(http.StatusNoContent)
|
||
1 year ago
|
}
|
||
|
}
|
||
|
|
||
1 year ago
|
// DeleteSecret delete one secret of the organization
|
||
|
func DeleteSecret(ctx *context.APIContext) {
|
||
1 year ago
|
// swagger:operation DELETE /orgs/{org}/actions/secrets/{secretname} organization deleteOrgSecret
|
||
|
// ---
|
||
|
// summary: Delete a secret in an organization
|
||
|
// consumes:
|
||
|
// - application/json
|
||
|
// produces:
|
||
|
// - application/json
|
||
|
// parameters:
|
||
|
// - name: org
|
||
|
// in: path
|
||
|
// description: name of organization
|
||
|
// type: string
|
||
|
// required: true
|
||
|
// - name: secretname
|
||
|
// in: path
|
||
|
// description: name of the secret
|
||
|
// type: string
|
||
|
// required: true
|
||
|
// responses:
|
||
|
// "204":
|
||
|
// description: delete one secret of the organization
|
||
1 year ago
|
// "400":
|
||
|
// "$ref": "#/responses/error"
|
||
|
// "404":
|
||
|
// "$ref": "#/responses/notFound"
|
||
|
|
||
|
err := secret_service.DeleteSecretByName(ctx, ctx.Org.Organization.ID, 0, ctx.Params("secretname"))
|
||
1 year ago
|
if err != nil {
|
||
1 year ago
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||
|
ctx.Error(http.StatusBadRequest, "DeleteSecret", err)
|
||
|
} else if errors.Is(err, util.ErrNotExist) {
|
||
|
ctx.Error(http.StatusNotFound, "DeleteSecret", err)
|
||
|
} else {
|
||
|
ctx.Error(http.StatusInternalServerError, "DeleteSecret", err)
|
||
|
}
|
||
1 year ago
|
return
|
||
|
}
|
||
|
|
||
|
ctx.Status(http.StatusNoContent)
|
||
|
}
|