-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API route to list org secrets #26485
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a1ac892
feat: add new functions and files related to secrets management
appleboy 3fd8201
feat: add API endpoint for listing organization's actions secrets
appleboy ae362b5
Update models/secret/secret.go
appleboy 8a502a2
Update modules/structs/secret.go
appleboy b54742d
Update routers/api/v1/org/action.go
appleboy 9f48dfc
feat: add support for Swagger secret list in API v1
appleboy bdf18bb
Merge branch 'api' of https://github.com/appleboy/gitea into api
appleboy e6c2a01
refactor: consolidate function names for counting secrets
appleboy ab59235
backup
appleboy 473b027
Merge branch 'main' into api
appleboy 5dc1f25
Update routers/api/v1/api.go
appleboy ff80b03
refactor: refactor `Secret` struct field name to `created_at`
appleboy dba1714
Merge branch 'main' into api
appleboy d72bcee
refactor: refactor property name in User object
appleboy 50ce300
Merge branch 'main' into api
appleboy f5e05f8
Merge branch 'main' into api
appleboy 26beefd
refactor: refactor code for checking organization membership and admi…
appleboy 3e162be
Merge branch 'api' of https://github.com/appleboy/gitea into api
appleboy 1a829f8
Merge branch 'main' into api
appleboy f15ad0e
Merge branch 'main' into api
GiteaBot 4c7efe4
Merge branch 'main' into api
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package structs | ||
|
||
import "time" | ||
|
||
// User represents a secret | ||
// swagger:model | ||
type Secret struct { | ||
// the secret's name | ||
Name string `json:"name"` | ||
// swagger:strfmt date-time | ||
Created time.Time `json:"created_at"` | ||
} |
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,72 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package org | ||
|
||
import ( | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/models/secret" | ||
"code.gitea.io/gitea/modules/context" | ||
api "code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/routers/api/v1/utils" | ||
) | ||
|
||
// 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" | ||
|
||
listActionsSecrets(ctx) | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// listActionsSecrets list an organization's actions secrets | ||
func listActionsSecrets(ctx *context.APIContext) { | ||
opts := &secret.FindSecretsOptions{ | ||
OwnerID: ctx.Org.Organization.ID, | ||
ListOptions: utils.GetListOptions(ctx), | ||
} | ||
|
||
count, err := secret.CountSecrets(ctx, opts) | ||
if err != nil { | ||
ctx.InternalServerError(err) | ||
return | ||
} | ||
|
||
secrets, err := secret.FindSecrets(ctx, *opts) | ||
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) | ||
} |
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,13 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package swagger | ||
|
||
import api "code.gitea.io/gitea/modules/structs" | ||
|
||
// SecretList | ||
// swagger:response SecretList | ||
type swaggerResponseSecretList struct { | ||
// in:body | ||
Body []api.Secret `json:"body"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erm… User secrets exist too already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That and we were not sure if we keep them action-only.
I think it is better to omit the
actions/
part from the URL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you explicitly only want to return the action secrets here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just following the spec: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#list-organization-secrets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what do we do in this case?
Deviate from the GitHub standard?
Add extra routes, and mark this one as deprecated with a comment
only for compatibility with the GitHub API
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry if my previous response was unclear. Please provide more details or elaborate on what you want me to explain. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/orgs/{org}/secrets
//users/{user}/secrets
insteadThat leaves the question what to do with the missing URL.
I suggest adding three routes in this PR: The two mentioned above, and the one you already implemented.
However, as the third should only be used by existing scripts and nothing else, I recommend marking this route as
// deprecated: true
with a comment that it is only intended for GitHub API compatibility and that our routes are the other two above instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said in #24200 (comment) , we can provide other API routes for more purposes but share the data table.
So LGTM.