-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
348 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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,103 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package admin | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/modules/context" | ||
api "code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/util" | ||
"code.gitea.io/gitea/modules/web" | ||
secret_service "code.gitea.io/gitea/services/secrets" | ||
) | ||
|
||
// CreateOrUpdateSecret create or update one secret in instance scope | ||
func CreateOrUpdateSecret(ctx *context.APIContext) { | ||
// swagger:operation PUT /admin/actions/secrets/{secretname} admin updateAdminSecret | ||
// --- | ||
// summary: Create or Update a secret value in instance scope | ||
// consumes: | ||
// - application/json | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: secretname | ||
// in: path | ||
// description: name of the secret | ||
// type: string | ||
// required: true | ||
// - name: body | ||
// in: body | ||
// schema: | ||
// "$ref": "#/definitions/CreateOrUpdateSecretOption" | ||
// responses: | ||
// "201": | ||
// description: secret created | ||
// "204": | ||
// description: secret updated | ||
// "400": | ||
// "$ref": "#/responses/error" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
|
||
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption) | ||
|
||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, 0, 0, ctx.Params("secretname"), opt.Data) | ||
if err != nil { | ||
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) | ||
} | ||
return | ||
} | ||
|
||
if created { | ||
ctx.Status(http.StatusCreated) | ||
} else { | ||
ctx.Status(http.StatusNoContent) | ||
} | ||
} | ||
|
||
// DeleteSecret delete one secret in instance scope | ||
func DeleteSecret(ctx *context.APIContext) { | ||
// swagger:operation DELETE /admin/actions/secrets/{secretname} admin deleteAdminSecret | ||
// --- | ||
// summary: Delete a secret in instance scope | ||
// consumes: | ||
// - application/json | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: secretname | ||
// in: path | ||
// description: name of the secret | ||
// type: string | ||
// required: true | ||
// responses: | ||
// "204": | ||
// description: secret deleted | ||
// "400": | ||
// "$ref": "#/responses/error" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
|
||
err := secret_service.DeleteSecretByName(ctx, 0, 0, ctx.Params("secretname")) | ||
if err != nil { | ||
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) | ||
} | ||
return | ||
} | ||
|
||
ctx.Status(http.StatusNoContent) | ||
} |
This file contains 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 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 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 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 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 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 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 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
Oops, something went wrong.