@@ -57,65 +57,47 @@ func (*Server) ServeRootEndpoint(c *gin.Context) {
5757}
5858
5959func (* Server ) PostRootEndpoint (c * gin.Context ) {
60- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
61- Message : "Only GET requests are supported." ,
62- })
60+ SetMethodNotAllowedJSONResponse (c )
6361}
6462
6563func (* Server ) PutRootEndpoint (c * gin.Context ) {
66- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
67- Message : "Only GET requests are supported." ,
68- })
64+ SetMethodNotAllowedJSONResponse (c )
6965}
7066
7167func (* Server ) DeleteRootEndpoint (c * gin.Context ) {
72- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
73- Message : "Only GET requests are supported." ,
74- })
68+ SetMethodNotAllowedJSONResponse (c )
7569}
7670
7771func (* Server ) ServeDevfileIndexV1 (c * gin.Context , params ServeDevfileIndexV1Params ) {
7872 ServeDevfileIndex (c , true , IndexParams (params ))
7973}
8074
8175func (* Server ) PostDevfileIndexV1 (c * gin.Context ) {
82- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
83- Message : "Only GET requests are supported." ,
84- })
76+ SetMethodNotAllowedJSONResponse (c )
8577}
8678
8779func (* Server ) PutDevfileIndexV1 (c * gin.Context ) {
88- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
89- Message : "Only GET requests are supported." ,
90- })
80+ SetMethodNotAllowedJSONResponse (c )
9181}
9282
9383func (* Server ) DeleteDevfileIndexV1 (c * gin.Context ) {
94- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
95- Message : "Only GET requests are supported." ,
96- })
84+ SetMethodNotAllowedJSONResponse (c )
9785}
9886
9987func (* Server ) ServeDevfileIndexV2 (c * gin.Context , params ServeDevfileIndexV2Params ) {
10088 ServeDevfileIndex (c , false , IndexParams (params ))
10189}
10290
10391func (* Server ) PostDevfileIndexV2 (c * gin.Context ) {
104- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
105- Message : "Only GET requests are supported." ,
106- })
92+ SetMethodNotAllowedJSONResponse (c )
10793}
10894
10995func (* Server ) PutDevfileIndexV2 (c * gin.Context ) {
110- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
111- Message : "Only GET requests are supported." ,
112- })
96+ SetMethodNotAllowedJSONResponse (c )
11397}
11498
11599func (* Server ) DeleteDevfileIndexV2 (c * gin.Context ) {
116- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
117- Message : "Only GET requests are supported." ,
118- })
100+ SetMethodNotAllowedJSONResponse (c )
119101}
120102
121103// ServeDevfileIndex serves the index.json file located in the container at `ServeDevfileIndex`
@@ -140,21 +122,15 @@ func (*Server) ServeDevfileIndexV1WithType(c *gin.Context, indexType string, par
140122}
141123
142124func (* Server ) PostDevfileIndexV1WithType (c * gin.Context , indexType string , params PostDevfileIndexV1WithTypeParams ){
143- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
144- Message : "Only GET requests are supported." ,
145- })
125+ SetMethodNotAllowedJSONResponse (c )
146126}
147127
148128func (* Server ) PutDevfileIndexV1WithType (c * gin.Context , indexType string , params PutDevfileIndexV1WithTypeParams ){
149- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
150- Message : "Only GET requests are supported." ,
151- })
129+ SetMethodNotAllowedJSONResponse (c )
152130}
153131
154132func (* Server ) DeleteDevfileIndexV1WithType (c * gin.Context , indexType string , params DeleteDevfileIndexV1WithTypeParams ){
155- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
156- Message : "Only GET requests are supported." ,
157- })
133+ SetMethodNotAllowedJSONResponse (c )
158134}
159135
160136func (* Server ) ServeDevfileIndexV2WithType (c * gin.Context , indexType string , params ServeDevfileIndexV2WithTypeParams ) {
@@ -164,21 +140,15 @@ func (*Server) ServeDevfileIndexV2WithType(c *gin.Context, indexType string, par
164140}
165141
166142func (* Server ) PostDevfileIndexV2WithType (c * gin.Context , indexType string , params PostDevfileIndexV2WithTypeParams ) {
167- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
168- Message : "Only GET requests are supported." ,
169- })
143+ SetMethodNotAllowedJSONResponse (c )
170144}
171145
172146func (* Server ) PutDevfileIndexV2WithType (c * gin.Context , indexType string , params PutDevfileIndexV2WithTypeParams ) {
173- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
174- Message : "Only GET requests are supported." ,
175- })
147+ SetMethodNotAllowedJSONResponse (c )
176148}
177149
178150func (* Server ) DeleteDevfileIndexV2WithType (c * gin.Context , indexType string , params DeleteDevfileIndexV2WithTypeParams ) {
179- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
180- Message : "Only GET requests are supported." ,
181- })
151+ SetMethodNotAllowedJSONResponse (c )
182152}
183153
184154// ServeHealthCheck serves endpoint `/health` for registry health check with GET request
@@ -189,21 +159,15 @@ func (*Server) ServeHealthCheck(c *gin.Context) {
189159}
190160// PostHealthCheck serves endpoint `/health` for registry health check with POST request
191161func (* Server ) PostHealthCheck (c * gin.Context ) {
192- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
193- Message : "Only GET requests are supported." ,
194- })
162+ SetMethodNotAllowedJSONResponse (c )
195163}
196164// PutHealthCheck serves endpoint `/health` for registry health check with PUT request
197165func (* Server ) PutHealthCheck (c * gin.Context ) {
198- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
199- Message : "Only GET requests are supported." ,
200- })
166+ SetMethodNotAllowedJSONResponse (c )
201167}
202168// DeleteHealthCheck serves endpoint `/health` for registry health check with DELETE request
203169func (* Server ) DeleteHealthCheck (c * gin.Context ) {
204- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
205- Message : "Only GET requests are supported." ,
206- })
170+ SetMethodNotAllowedJSONResponse (c )
207171}
208172
209173func (* Server ) ServeDevfileWithVersion (c * gin.Context , name string , version string ) {
@@ -235,21 +199,15 @@ func (*Server) ServeDevfileWithVersion(c *gin.Context, name string, version stri
235199}
236200
237201func (* Server ) PostDevfileWithVersion (c * gin.Context , name string , version string ){
238- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
239- Message : "Only GET requests are supported." ,
240- })
202+ SetMethodNotAllowedJSONResponse (c )
241203}
242204
243205func (* Server ) PutDevfileWithVersion (c * gin.Context , name string , version string ){
244- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
245- Message : "Only GET requests are supported." ,
246- })
206+ SetMethodNotAllowedJSONResponse (c )
247207}
248208
249209func (* Server ) DeleteDevfileWithVersion (c * gin.Context , name string , version string ){
250- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
251- Message : "Only GET requests are supported." ,
252- })
210+ SetMethodNotAllowedJSONResponse (c )
253211}
254212
255213// ServeDevfile returns the devfile content
@@ -259,21 +217,15 @@ func (s *Server) ServeDevfile(c *gin.Context, name string) {
259217}
260218
261219func (s * Server ) PostDevfile (c * gin.Context , name string ) {
262- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
263- Message : "Only GET requests are supported." ,
264- })
220+ SetMethodNotAllowedJSONResponse (c )
265221}
266222
267223func (s * Server ) PutDevfile (c * gin.Context , name string ) {
268- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
269- Message : "Only GET requests are supported." ,
270- })
224+ SetMethodNotAllowedJSONResponse (c )
271225}
272226
273227func (s * Server ) DeleteDevfile (c * gin.Context , name string ) {
274- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
275- Message : "Only GET requests are supported." ,
276- })
228+ SetMethodNotAllowedJSONResponse (c )
277229}
278230
279231// ServeDevfileStarterProject returns the starter project content for the devfile using default version
@@ -282,21 +234,15 @@ func (s *Server) ServeDevfileStarterProject(c *gin.Context, name string, starter
282234}
283235
284236func (s * Server ) PostDevfileStarterProject (c * gin.Context , name string , starterProject string ) {
285- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
286- Message : "Only GET requests are supported." ,
287- })
237+ SetMethodNotAllowedJSONResponse (c )
288238}
289239
290240func (s * Server ) PutDevfileStarterProject (c * gin.Context , name string , starterProject string ) {
291- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
292- Message : "Only GET requests are supported." ,
293- })
241+ SetMethodNotAllowedJSONResponse (c )
294242}
295243
296244func (s * Server ) DeleteDevfileStarterProject (c * gin.Context , name string , starterProject string ) {
297- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
298- Message : "Only GET requests are supported." ,
299- })
245+ SetMethodNotAllowedJSONResponse (c )
300246}
301247
302248// ServeDevfileStarterProject returns the starter project content for the devfile using specified version
@@ -486,21 +432,15 @@ func (*Server) ServeDevfileStarterProjectWithVersion(c *gin.Context, name string
486432}
487433
488434func (* Server ) PostDevfileStarterProjectWithVersion (c * gin.Context , name string , version string , starterProject string ){
489- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
490- Message : "Only GET requests are supported." ,
491- })
435+ SetMethodNotAllowedJSONResponse (c )
492436}
493437
494438func (* Server ) PutDevfileStarterProjectWithVersion (c * gin.Context , name string , version string , starterProject string ){
495- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
496- Message : "Only GET requests are supported." ,
497- })
439+ SetMethodNotAllowedJSONResponse (c )
498440}
499441
500442func (* Server ) DeleteDevfileStarterProjectWithVersion (c * gin.Context , name string , version string , starterProject string ){
501- c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
502- Message : "Only GET requests are supported." ,
503- })
443+ SetMethodNotAllowedJSONResponse (c )
504444}
505445
506446// ServeUI handles registry viewer proxy requests
@@ -862,3 +802,9 @@ func ServeOciProxy(c *gin.Context) {
862802
863803 proxy .ServeHTTP (c .Writer , c .Request )
864804}
805+
806+ func SetMethodNotAllowedJSONResponse (c * gin.Context ){
807+ c .JSON (http .StatusMethodNotAllowed , MethodNotAllowedResponse {
808+ Message : "Only GET requests are supported." ,
809+ })
810+ }
0 commit comments