mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Add API route to list org secrets (#26485)
- Add a new function `CountOrgSecrets` in the file `models/secret/secret.go` - Add a new file `modules/structs/secret.go` - Add a new function `ListActionsSecrets` in the file `routers/api/v1/api.go` - Add a new file `routers/api/v1/org/action.go` - Add a new function `listActionsSecrets` in the file `routers/api/v1/org/action.go` go-sdk: https://gitea.com/gitea/go-sdk/pulls/629 --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
		
							
								
								
									
										72
									
								
								routers/api/v1/org/action.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								routers/api/v1/org/action.go
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user