Skip to content

Commit 9eb4a9e

Browse files
authored
feat(API): add secret deletion functionality for repository (#26808)
- Modify the `CreateOrUpdateSecret` function in `api.go` to include a `Delete` operation for the secret - Modify the `DeleteOrgSecret` function in `action.go` to include a `DeleteSecret` operation for the organization - Modify the `DeleteSecret` function in `action.go` to include a `DeleteSecret` operation for the repository - Modify the `v1_json.tmpl` template file to update the `operationId` and `summary` for the `deleteSecret` operation in both the organization and repository sections --------- Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent f01bed2 commit 9eb4a9e

File tree

4 files changed

+107
-4
lines changed

4 files changed

+107
-4
lines changed

routers/api/v1/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ func Routes() *web.Route {
935935
}, reqToken())
936936
m.Group("/actions/secrets", func() {
937937
m.Combo("/{secretname}").
938-
Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret)
938+
Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret).
939+
Delete(reqToken(), reqOwner(), repo.DeleteSecret)
939940
})
940941
m.Group("/hooks/git", func() {
941942
m.Combo("").Get(repo.ListGitHooks)
@@ -1306,7 +1307,7 @@ func Routes() *web.Route {
13061307
m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets)
13071308
m.Combo("/{secretname}").
13081309
Put(reqToken(), reqOrgOwnership(), bind(api.CreateOrUpdateSecretOption{}), org.CreateOrUpdateSecret).
1309-
Delete(reqToken(), reqOrgOwnership(), org.DeleteOrgSecret)
1310+
Delete(reqToken(), reqOrgOwnership(), org.DeleteSecret)
13101311
})
13111312
m.Group("/public_members", func() {
13121313
m.Get("", org.ListPublicMembers)

routers/api/v1/org/action.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
125125
ctx.Status(http.StatusNoContent)
126126
}
127127

128-
// DeleteOrgSecret delete one secret of the organization
129-
func DeleteOrgSecret(ctx *context.APIContext) {
128+
// DeleteSecret delete one secret of the organization
129+
func DeleteSecret(ctx *context.APIContext) {
130130
// swagger:operation DELETE /orgs/{org}/actions/secrets/{secretname} organization deleteOrgSecret
131131
// ---
132132
// summary: Delete a secret in an organization
@@ -151,6 +151,10 @@ func DeleteOrgSecret(ctx *context.APIContext) {
151151
// "403":
152152
// "$ref": "#/responses/forbidden"
153153
secretName := ctx.Params(":secretname")
154+
if err := actions.NameRegexMatch(secretName); err != nil {
155+
ctx.Error(http.StatusBadRequest, "DeleteSecret", err)
156+
return
157+
}
154158
err := secret_model.DeleteSecret(
155159
ctx, ctx.Org.Organization.ID, 0, secretName,
156160
)

routers/api/v1/repo/action.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,57 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
7373

7474
ctx.Status(http.StatusNoContent)
7575
}
76+
77+
// DeleteSecret delete one secret of the repository
78+
func DeleteSecret(ctx *context.APIContext) {
79+
// swagger:operation DELETE /repos/{owner}/{repo}/actions/secrets/{secretname} repository deleteRepoSecret
80+
// ---
81+
// summary: Delete a secret in a repository
82+
// consumes:
83+
// - application/json
84+
// produces:
85+
// - application/json
86+
// parameters:
87+
// - name: owner
88+
// in: path
89+
// description: owner of the repository
90+
// type: string
91+
// required: true
92+
// - name: repo
93+
// in: path
94+
// description: name of the repository
95+
// type: string
96+
// required: true
97+
// - name: secretname
98+
// in: path
99+
// description: name of the secret
100+
// type: string
101+
// required: true
102+
// responses:
103+
// "204":
104+
// description: delete one secret of the organization
105+
// "403":
106+
// "$ref": "#/responses/forbidden"
107+
108+
owner := ctx.Repo.Owner
109+
repo := ctx.Repo.Repository
110+
111+
secretName := ctx.Params(":secretname")
112+
if err := actions.NameRegexMatch(secretName); err != nil {
113+
ctx.Error(http.StatusBadRequest, "DeleteSecret", err)
114+
return
115+
}
116+
err := secret_model.DeleteSecret(
117+
ctx, owner.ID, repo.ID, secretName,
118+
)
119+
if secret_model.IsErrSecretNotFound(err) {
120+
ctx.NotFound(err)
121+
return
122+
}
123+
if err != nil {
124+
ctx.Error(http.StatusInternalServerError, "DeleteSecret", err)
125+
return
126+
}
127+
128+
ctx.Status(http.StatusNoContent)
129+
}

templates/swagger/v1_json.tmpl

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)