@@ -9,16 +9,188 @@ import (
9
9
10
10
actions_model "code.gitea.io/gitea/models/actions"
11
11
"code.gitea.io/gitea/models/db"
12
+ secret_model "code.gitea.io/gitea/models/secret"
12
13
api "code.gitea.io/gitea/modules/structs"
13
14
"code.gitea.io/gitea/modules/util"
14
15
"code.gitea.io/gitea/modules/web"
16
+ "code.gitea.io/gitea/routers/api/v1/shared"
15
17
"code.gitea.io/gitea/routers/api/v1/utils"
16
18
actions_service "code.gitea.io/gitea/services/actions"
17
19
"code.gitea.io/gitea/services/context"
20
+ secret_service "code.gitea.io/gitea/services/secrets"
18
21
)
19
22
23
+ // ListActionsSecrets list an organization's actions secrets
24
+ func (Action ) ListActionsSecrets (ctx * context.APIContext ) {
25
+ // swagger:operation GET /orgs/{org}/actions/secrets organization orgListActionsSecrets
26
+ // ---
27
+ // summary: List an organization's actions secrets
28
+ // produces:
29
+ // - application/json
30
+ // parameters:
31
+ // - name: org
32
+ // in: path
33
+ // description: name of the organization
34
+ // type: string
35
+ // required: true
36
+ // - name: page
37
+ // in: query
38
+ // description: page number of results to return (1-based)
39
+ // type: integer
40
+ // - name: limit
41
+ // in: query
42
+ // description: page size of results
43
+ // type: integer
44
+ // responses:
45
+ // "200":
46
+ // "$ref": "#/responses/SecretList"
47
+ // "404":
48
+ // "$ref": "#/responses/notFound"
49
+
50
+ opts := & secret_model.FindSecretsOptions {
51
+ OwnerID : ctx .Org .Organization .ID ,
52
+ ListOptions : utils .GetListOptions (ctx ),
53
+ }
54
+
55
+ secrets , count , err := db .FindAndCount [secret_model.Secret ](ctx , opts )
56
+ if err != nil {
57
+ ctx .InternalServerError (err )
58
+ return
59
+ }
60
+
61
+ apiSecrets := make ([]* api.Secret , len (secrets ))
62
+ for k , v := range secrets {
63
+ apiSecrets [k ] = & api.Secret {
64
+ Name : v .Name ,
65
+ Created : v .CreatedUnix .AsTime (),
66
+ }
67
+ }
68
+
69
+ ctx .SetTotalCountHeader (count )
70
+ ctx .JSON (http .StatusOK , apiSecrets )
71
+ }
72
+
73
+ // create or update one secret of the organization
74
+ func (Action ) CreateOrUpdateSecret (ctx * context.APIContext ) {
75
+ // swagger:operation PUT /orgs/{org}/actions/secrets/{secretname} organization updateOrgSecret
76
+ // ---
77
+ // summary: Create or Update a secret value in an organization
78
+ // consumes:
79
+ // - application/json
80
+ // produces:
81
+ // - application/json
82
+ // parameters:
83
+ // - name: org
84
+ // in: path
85
+ // description: name of organization
86
+ // type: string
87
+ // required: true
88
+ // - name: secretname
89
+ // in: path
90
+ // description: name of the secret
91
+ // type: string
92
+ // required: true
93
+ // - name: body
94
+ // in: body
95
+ // schema:
96
+ // "$ref": "#/definitions/CreateOrUpdateSecretOption"
97
+ // responses:
98
+ // "201":
99
+ // description: response when creating a secret
100
+ // "204":
101
+ // description: response when updating a secret
102
+ // "400":
103
+ // "$ref": "#/responses/error"
104
+ // "404":
105
+ // "$ref": "#/responses/notFound"
106
+
107
+ opt := web .GetForm (ctx ).(* api.CreateOrUpdateSecretOption )
108
+
109
+ _ , created , err := secret_service .CreateOrUpdateSecret (ctx , ctx .Org .Organization .ID , 0 , ctx .Params ("secretname" ), opt .Data )
110
+ if err != nil {
111
+ if errors .Is (err , util .ErrInvalidArgument ) {
112
+ ctx .Error (http .StatusBadRequest , "CreateOrUpdateSecret" , err )
113
+ } else if errors .Is (err , util .ErrNotExist ) {
114
+ ctx .Error (http .StatusNotFound , "CreateOrUpdateSecret" , err )
115
+ } else {
116
+ ctx .Error (http .StatusInternalServerError , "CreateOrUpdateSecret" , err )
117
+ }
118
+ return
119
+ }
120
+
121
+ if created {
122
+ ctx .Status (http .StatusCreated )
123
+ } else {
124
+ ctx .Status (http .StatusNoContent )
125
+ }
126
+ }
127
+
128
+ // DeleteSecret delete one secret of the organization
129
+ func (Action ) DeleteSecret (ctx * context.APIContext ) {
130
+ // swagger:operation DELETE /orgs/{org}/actions/secrets/{secretname} organization deleteOrgSecret
131
+ // ---
132
+ // summary: Delete a secret in an organization
133
+ // consumes:
134
+ // - application/json
135
+ // produces:
136
+ // - application/json
137
+ // parameters:
138
+ // - name: org
139
+ // in: path
140
+ // description: name of organization
141
+ // type: string
142
+ // required: true
143
+ // - name: secretname
144
+ // in: path
145
+ // description: name of the secret
146
+ // type: string
147
+ // required: true
148
+ // responses:
149
+ // "204":
150
+ // description: delete one secret of the organization
151
+ // "400":
152
+ // "$ref": "#/responses/error"
153
+ // "404":
154
+ // "$ref": "#/responses/notFound"
155
+
156
+ err := secret_service .DeleteSecretByName (ctx , ctx .Org .Organization .ID , 0 , ctx .Params ("secretname" ))
157
+ if err != nil {
158
+ if errors .Is (err , util .ErrInvalidArgument ) {
159
+ ctx .Error (http .StatusBadRequest , "DeleteSecret" , err )
160
+ } else if errors .Is (err , util .ErrNotExist ) {
161
+ ctx .Error (http .StatusNotFound , "DeleteSecret" , err )
162
+ } else {
163
+ ctx .Error (http .StatusInternalServerError , "DeleteSecret" , err )
164
+ }
165
+ return
166
+ }
167
+
168
+ ctx .Status (http .StatusNoContent )
169
+ }
170
+
171
+ // https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization
172
+ // GetRegistrationToken returns the token to register org runners
173
+ func (Action ) GetRegistrationToken (ctx * context.APIContext ) {
174
+ // swagger:operation GET /orgs/{org}/actions/runners/registration-token organization orgGetRunnerRegistrationToken
175
+ // ---
176
+ // summary: Get an organization's actions runner registration token
177
+ // produces:
178
+ // - application/json
179
+ // parameters:
180
+ // - name: org
181
+ // in: path
182
+ // description: name of the organization
183
+ // type: string
184
+ // required: true
185
+ // responses:
186
+ // "200":
187
+ // "$ref": "#/responses/RegistrationToken"
188
+
189
+ shared .GetRegistrationToken (ctx , ctx .Org .Organization .ID , 0 )
190
+ }
191
+
20
192
// ListVariables list org-level variables
21
- func ListVariables (ctx * context.APIContext ) {
193
+ func ( Action ) ListVariables (ctx * context.APIContext ) {
22
194
// swagger:operation GET /orgs/{org}/actions/variables organization getOrgVariablesList
23
195
// ---
24
196
// summary: Get an org-level variables list
@@ -70,7 +242,7 @@ func ListVariables(ctx *context.APIContext) {
70
242
}
71
243
72
244
// GetVariable get an org-level variable
73
- func GetVariable (ctx * context.APIContext ) {
245
+ func ( Action ) GetVariable (ctx * context.APIContext ) {
74
246
// swagger:operation GET /orgs/{org}/actions/variables/{variablename} organization getOrgVariable
75
247
// ---
76
248
// summary: Get an org-level variable
@@ -119,7 +291,7 @@ func GetVariable(ctx *context.APIContext) {
119
291
}
120
292
121
293
// DeleteVariable delete an org-level variable
122
- func DeleteVariable (ctx * context.APIContext ) {
294
+ func ( Action ) DeleteVariable (ctx * context.APIContext ) {
123
295
// swagger:operation DELETE /orgs/{org}/actions/variables/{variablename} organization deleteOrgVariable
124
296
// ---
125
297
// summary: Delete an org-level variable
@@ -163,7 +335,7 @@ func DeleteVariable(ctx *context.APIContext) {
163
335
}
164
336
165
337
// CreateVariable create an org-level variable
166
- func CreateVariable (ctx * context.APIContext ) {
338
+ func ( Action ) CreateVariable (ctx * context.APIContext ) {
167
339
// swagger:operation POST /orgs/{org}/actions/variables/{variablename} organization createOrgVariable
168
340
// ---
169
341
// summary: Create an org-level variable
@@ -227,7 +399,7 @@ func CreateVariable(ctx *context.APIContext) {
227
399
}
228
400
229
401
// UpdateVariable update an org-level variable
230
- func UpdateVariable (ctx * context.APIContext ) {
402
+ func ( Action ) UpdateVariable (ctx * context.APIContext ) {
231
403
// swagger:operation PUT /orgs/{org}/actions/variables/{variablename} organization updateOrgVariable
232
404
// ---
233
405
// summary: Update an org-level variable
@@ -289,3 +461,13 @@ func UpdateVariable(ctx *context.APIContext) {
289
461
290
462
ctx .Status (http .StatusNoContent )
291
463
}
464
+
465
+ var _ actions_service.API = new (Action )
466
+
467
+ // Action implements actions_service.API
468
+ type Action struct {}
469
+
470
+ // NewAction creates a new Action service
471
+ func NewAction () actions_service.API {
472
+ return Action {}
473
+ }
0 commit comments