@@ -13,6 +13,7 @@ import (
13
13
api "code.gitea.io/gitea/modules/structs"
14
14
"code.gitea.io/gitea/modules/timeutil"
15
15
"code.gitea.io/gitea/modules/web"
16
+ auth_service "code.gitea.io/gitea/services/auth"
16
17
"code.gitea.io/gitea/services/auth/source/ldap"
17
18
"code.gitea.io/gitea/services/auth/source/oauth2"
18
19
"code.gitea.io/gitea/services/auth/source/pam"
@@ -47,6 +48,37 @@ func ListAuthSources(ctx *context.APIContext) {
47
48
ctx .JSON (http .StatusOK , result )
48
49
}
49
50
51
+ // GetAuthSource get an authentication source by id
52
+ func GetAuthSource (ctx * context.APIContext ) {
53
+ // swagger:operation GET /admin/auths/{id} admin adminGetAuthSource
54
+ // ---
55
+ // summary: Get an authentication source
56
+ // produces:
57
+ // - application/json
58
+ // parameters:
59
+ // - name: id
60
+ // in: path
61
+ // description: id of the authentication source to get
62
+ // type: integer
63
+ // format: int64
64
+ // required: true
65
+ // responses:
66
+ // "200":
67
+ // "$ref": "#/responses/AuthSource"
68
+
69
+ source , err := auth .GetSourceByID (ctx .ParamsInt64 (":id" ))
70
+ if err != nil {
71
+ ctx .ServerError ("auth.GetSourceByID" , err )
72
+ return
73
+ }
74
+ result , err := convert .ToAuthSource (source )
75
+ if err != nil {
76
+ ctx .Error (http .StatusInternalServerError , "convert.ToAuthSource" , err )
77
+ return
78
+ }
79
+ ctx .JSON (http .StatusOK , result )
80
+ }
81
+
50
82
// CreateAuthSource creates new authentication source
51
83
func CreateAuthSource (ctx * context.APIContext ) {
52
84
// swagger:operation POST /admin/auths admin adminCreateAuthSource
@@ -118,3 +150,38 @@ func CreateAuthSource(ctx *context.APIContext) {
118
150
}
119
151
ctx .JSON (http .StatusCreated , result )
120
152
}
153
+
154
+ // DeleteAuthSource delete an authentication source
155
+ func DeleteAuthSource (ctx * context.APIContext ) {
156
+ // swagger:operation DELETE /admin/auths/{id} admin adminDeleteAuthSource
157
+ // ---
158
+ // summary: Delete an authentication source
159
+ // produces:
160
+ // - application/json
161
+ // parameters:
162
+ // - name: id
163
+ // in: path
164
+ // description: id of the authentication source to delete
165
+ // type: integer
166
+ // format: int64
167
+ // required: true
168
+ // responses:
169
+ // "204":
170
+ // "$ref": "#/responses/empty"
171
+
172
+ source , err := auth .GetSourceByID (ctx .ParamsInt64 (":id" ))
173
+ if err != nil {
174
+ ctx .ServerError ("auth.GetSourceByID" , err )
175
+ return
176
+ }
177
+
178
+ if err = auth_service .DeleteSource (source ); err != nil {
179
+ if auth .IsErrSourceInUse (err ) {
180
+ ctx .Error (http .StatusInternalServerError , "auth_service.DeleteSource" , err )
181
+ } else {
182
+ ctx .Error (http .StatusInternalServerError , "auth_service.DeleteSource" , err )
183
+ }
184
+ return
185
+ }
186
+ ctx .Status (http .StatusNoContent )
187
+ }
0 commit comments