aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/api.go3
-rw-r--r--routers/api/v1/org/action.go91
-rw-r--r--routers/api/v1/swagger/options.go3
3 files changed, 97 insertions, 0 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 9613bd610d..2d644507d5 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -1301,6 +1301,9 @@ func Routes() *web.Route {
m.Group("/actions/secrets", func() {
m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets)
m.Post("", reqToken(), reqOrgOwnership(), bind(api.CreateSecretOption{}), org.CreateOrgSecret)
+ m.Combo("/{secretname}").
+ Put(reqToken(), reqOrgOwnership(), bind(api.UpdateSecretOption{}), org.UpdateOrgSecret).
+ Delete(reqToken(), reqOrgOwnership(), org.DeleteOrgSecret)
})
m.Group("/public_members", func() {
m.Get("", org.ListPublicMembers)
diff --git a/routers/api/v1/org/action.go b/routers/api/v1/org/action.go
index 7659191946..9697a11363 100644
--- a/routers/api/v1/org/action.go
+++ b/routers/api/v1/org/action.go
@@ -103,6 +103,10 @@ func CreateOrgSecret(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
opt := web.GetForm(ctx).(*api.CreateSecretOption)
+ if err := actions.NameRegexMatch(opt.Name); err != nil {
+ ctx.Error(http.StatusBadRequest, "CreateOrgSecret", err)
+ return
+ }
s, err := secret_model.InsertEncryptedSecret(
ctx, ctx.Org.Organization.ID, 0, opt.Name, actions.ReserveLineBreakForTextarea(opt.Data),
)
@@ -113,3 +117,90 @@ func CreateOrgSecret(ctx *context.APIContext) {
ctx.JSON(http.StatusCreated, convert.ToSecret(s))
}
+
+// UpdateOrgSecret update one secret of the organization
+func UpdateOrgSecret(ctx *context.APIContext) {
+ // swagger:operation PUT /orgs/{org}/actions/secrets/{secretname} organization updateOrgSecret
+ // ---
+ // summary: Update a secret value 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
+ // - name: body
+ // in: body
+ // schema:
+ // "$ref": "#/definitions/UpdateSecretOption"
+ // responses:
+ // "204":
+ // description: update one secret of the organization
+ // "403":
+ // "$ref": "#/responses/forbidden"
+ secretName := ctx.Params(":secretname")
+ opt := web.GetForm(ctx).(*api.UpdateSecretOption)
+ err := secret_model.UpdateSecret(
+ ctx, ctx.Org.Organization.ID, 0, secretName, opt.Data,
+ )
+ if secret_model.IsErrSecretNotFound(err) {
+ ctx.NotFound(err)
+ return
+ }
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "UpdateSecret", err)
+ return
+ }
+
+ ctx.Status(http.StatusNoContent)
+}
+
+// DeleteOrgSecret delete one secret of the organization
+func DeleteOrgSecret(ctx *context.APIContext) {
+ // 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
+ // "403":
+ // "$ref": "#/responses/forbidden"
+ secretName := ctx.Params(":secretname")
+ err := secret_model.DeleteSecret(
+ ctx, ctx.Org.Organization.ID, 0, secretName,
+ )
+ if secret_model.IsErrSecretNotFound(err) {
+ ctx.NotFound(err)
+ return
+ }
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "DeleteSecret", err)
+ return
+ }
+
+ ctx.Status(http.StatusNoContent)
+}
diff --git a/routers/api/v1/swagger/options.go b/routers/api/v1/swagger/options.go
index 8e7e6ec3df..e41ee66776 100644
--- a/routers/api/v1/swagger/options.go
+++ b/routers/api/v1/swagger/options.go
@@ -190,4 +190,7 @@ type swaggerParameterBodies struct {
// in:body
CreateSecretOption api.CreateSecretOption
+
+ // in:body
+ UpdateSecretOption api.UpdateSecretOption
}