Changing implementation for url to align with spec
[ric-plt/a1.git] / pkg / restapi / operations / a1_api.go
1 /*
2 ==================================================================================
3   Copyright (c) 2021 Samsung
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17    This source code is part of the near-RT RIC (RAN Intelligent Controller)
18    platform project (RICP).
19 ==================================================================================
20 */
21 // Code generated by go-swagger; DO NOT EDIT.
22
23 package operations
24
25 // This file was generated by the swagger tool.
26 // Editing this file might prove futile when you re-run the swagger generate command
27
28 import (
29         "fmt"
30         "net/http"
31         "strings"
32
33         "github.com/go-openapi/errors"
34         "github.com/go-openapi/loads"
35         "github.com/go-openapi/runtime"
36         "github.com/go-openapi/runtime/middleware"
37         "github.com/go-openapi/runtime/security"
38         "github.com/go-openapi/spec"
39         "github.com/go-openapi/strfmt"
40         "github.com/go-openapi/swag"
41
42         "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_e_i_data_delivery"
43         "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator"
44 )
45
46 // NewA1API creates a new A1 instance
47 func NewA1API(spec *loads.Document) *A1API {
48         return &A1API{
49                 handlers:            make(map[string]map[string]http.Handler),
50                 formats:             strfmt.Default,
51                 defaultConsumes:     "application/json",
52                 defaultProduces:     "application/json",
53                 customConsumers:     make(map[string]runtime.Consumer),
54                 customProducers:     make(map[string]runtime.Producer),
55                 PreServerShutdown:   func() {},
56                 ServerShutdown:      func() {},
57                 spec:                spec,
58                 useSwaggerUI:        false,
59                 ServeError:          errors.ServeError,
60                 BasicAuthenticator:  security.BasicAuth,
61                 APIKeyAuthenticator: security.APIKeyAuth,
62                 BearerAuthenticator: security.BearerAuth,
63
64                 JSONConsumer: runtime.JSONConsumer(),
65
66                 JSONProducer: runtime.JSONProducer(),
67
68                 A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler: a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerCreateOrReplacePolicyInstanceParams) middleware.Responder {
69                         return middleware.NotImplemented("operation a1_mediator.A1ControllerCreateOrReplacePolicyInstance has not yet been implemented")
70                 }),
71                 A1MediatorA1ControllerCreatePolicyTypeHandler: a1_mediator.A1ControllerCreatePolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerCreatePolicyTypeParams) middleware.Responder {
72                         return middleware.NotImplemented("operation a1_mediator.A1ControllerCreatePolicyType has not yet been implemented")
73                 }),
74                 A1eiDataDeliveryA1ControllerDataDeliveryHandler: a1_e_i_data_delivery.A1ControllerDataDeliveryHandlerFunc(func(params a1_e_i_data_delivery.A1ControllerDataDeliveryParams) middleware.Responder {
75                         return middleware.NotImplemented("operation a1_e_i_data_delivery.A1ControllerDataDelivery has not yet been implemented")
76                 }),
77                 A1MediatorA1ControllerDeletePolicyInstanceHandler: a1_mediator.A1ControllerDeletePolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerDeletePolicyInstanceParams) middleware.Responder {
78                         return middleware.NotImplemented("operation a1_mediator.A1ControllerDeletePolicyInstance has not yet been implemented")
79                 }),
80                 A1MediatorA1ControllerDeletePolicyTypeHandler: a1_mediator.A1ControllerDeletePolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerDeletePolicyTypeParams) middleware.Responder {
81                         return middleware.NotImplemented("operation a1_mediator.A1ControllerDeletePolicyType has not yet been implemented")
82                 }),
83                 A1MediatorA1ControllerGetAllInstancesForTypeHandler: a1_mediator.A1ControllerGetAllInstancesForTypeHandlerFunc(func(params a1_mediator.A1ControllerGetAllInstancesForTypeParams) middleware.Responder {
84                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetAllInstancesForType has not yet been implemented")
85                 }),
86                 A1MediatorA1ControllerGetAllPolicyTypesHandler: a1_mediator.A1ControllerGetAllPolicyTypesHandlerFunc(func(params a1_mediator.A1ControllerGetAllPolicyTypesParams) middleware.Responder {
87                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetAllPolicyTypes has not yet been implemented")
88                 }),
89                 A1MediatorA1ControllerGetHealthcheckHandler: a1_mediator.A1ControllerGetHealthcheckHandlerFunc(func(params a1_mediator.A1ControllerGetHealthcheckParams) middleware.Responder {
90                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetHealthcheck has not yet been implemented")
91                 }),
92                 A1MediatorA1ControllerGetPolicyInstanceHandler: a1_mediator.A1ControllerGetPolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyInstanceParams) middleware.Responder {
93                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetPolicyInstance has not yet been implemented")
94                 }),
95                 A1MediatorA1ControllerGetPolicyInstanceStatusHandler: a1_mediator.A1ControllerGetPolicyInstanceStatusHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyInstanceStatusParams) middleware.Responder {
96                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetPolicyInstanceStatus has not yet been implemented")
97                 }),
98                 A1MediatorA1ControllerGetPolicyTypeHandler: a1_mediator.A1ControllerGetPolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyTypeParams) middleware.Responder {
99                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetPolicyType has not yet been implemented")
100                 }),
101         }
102 }
103
104 /*A1API the a1 API */
105 type A1API struct {
106         spec            *loads.Document
107         context         *middleware.Context
108         handlers        map[string]map[string]http.Handler
109         formats         strfmt.Registry
110         customConsumers map[string]runtime.Consumer
111         customProducers map[string]runtime.Producer
112         defaultConsumes string
113         defaultProduces string
114         Middleware      func(middleware.Builder) http.Handler
115         useSwaggerUI    bool
116
117         // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
118         // It has a default implementation in the security package, however you can replace it for your particular usage.
119         BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
120
121         // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
122         // It has a default implementation in the security package, however you can replace it for your particular usage.
123         APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
124
125         // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
126         // It has a default implementation in the security package, however you can replace it for your particular usage.
127         BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
128
129         // JSONConsumer registers a consumer for the following mime types:
130         //   - application/json
131         JSONConsumer runtime.Consumer
132
133         // JSONProducer registers a producer for the following mime types:
134         //   - application/json
135         JSONProducer runtime.Producer
136
137         // A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler sets the operation handler for the a1 controller create or replace policy instance operation
138         A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandler
139         // A1MediatorA1ControllerCreatePolicyTypeHandler sets the operation handler for the a1 controller create policy type operation
140         A1MediatorA1ControllerCreatePolicyTypeHandler a1_mediator.A1ControllerCreatePolicyTypeHandler
141         // A1eiDataDeliveryA1ControllerDataDeliveryHandler sets the operation handler for the a1 controller data delivery operation
142         A1eiDataDeliveryA1ControllerDataDeliveryHandler a1_e_i_data_delivery.A1ControllerDataDeliveryHandler
143         // A1MediatorA1ControllerDeletePolicyInstanceHandler sets the operation handler for the a1 controller delete policy instance operation
144         A1MediatorA1ControllerDeletePolicyInstanceHandler a1_mediator.A1ControllerDeletePolicyInstanceHandler
145         // A1MediatorA1ControllerDeletePolicyTypeHandler sets the operation handler for the a1 controller delete policy type operation
146         A1MediatorA1ControllerDeletePolicyTypeHandler a1_mediator.A1ControllerDeletePolicyTypeHandler
147         // A1MediatorA1ControllerGetAllInstancesForTypeHandler sets the operation handler for the a1 controller get all instances for type operation
148         A1MediatorA1ControllerGetAllInstancesForTypeHandler a1_mediator.A1ControllerGetAllInstancesForTypeHandler
149         // A1MediatorA1ControllerGetAllPolicyTypesHandler sets the operation handler for the a1 controller get all policy types operation
150         A1MediatorA1ControllerGetAllPolicyTypesHandler a1_mediator.A1ControllerGetAllPolicyTypesHandler
151         // A1MediatorA1ControllerGetHealthcheckHandler sets the operation handler for the a1 controller get healthcheck operation
152         A1MediatorA1ControllerGetHealthcheckHandler a1_mediator.A1ControllerGetHealthcheckHandler
153         // A1MediatorA1ControllerGetPolicyInstanceHandler sets the operation handler for the a1 controller get policy instance operation
154         A1MediatorA1ControllerGetPolicyInstanceHandler a1_mediator.A1ControllerGetPolicyInstanceHandler
155         // A1MediatorA1ControllerGetPolicyInstanceStatusHandler sets the operation handler for the a1 controller get policy instance status operation
156         A1MediatorA1ControllerGetPolicyInstanceStatusHandler a1_mediator.A1ControllerGetPolicyInstanceStatusHandler
157         // A1MediatorA1ControllerGetPolicyTypeHandler sets the operation handler for the a1 controller get policy type operation
158         A1MediatorA1ControllerGetPolicyTypeHandler a1_mediator.A1ControllerGetPolicyTypeHandler
159
160         // ServeError is called when an error is received, there is a default handler
161         // but you can set your own with this
162         ServeError func(http.ResponseWriter, *http.Request, error)
163
164         // PreServerShutdown is called before the HTTP(S) server is shutdown
165         // This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic
166         PreServerShutdown func()
167
168         // ServerShutdown is called when the HTTP(S) server is shut down and done
169         // handling all active connections and does not accept connections any more
170         ServerShutdown func()
171
172         // Custom command line argument groups with their descriptions
173         CommandLineOptionsGroups []swag.CommandLineOptionsGroup
174
175         // User defined logger function.
176         Logger func(string, ...interface{})
177 }
178
179 // UseRedoc for documentation at /docs
180 func (o *A1API) UseRedoc() {
181         o.useSwaggerUI = false
182 }
183
184 // UseSwaggerUI for documentation at /docs
185 func (o *A1API) UseSwaggerUI() {
186         o.useSwaggerUI = true
187 }
188
189 // SetDefaultProduces sets the default produces media type
190 func (o *A1API) SetDefaultProduces(mediaType string) {
191         o.defaultProduces = mediaType
192 }
193
194 // SetDefaultConsumes returns the default consumes media type
195 func (o *A1API) SetDefaultConsumes(mediaType string) {
196         o.defaultConsumes = mediaType
197 }
198
199 // SetSpec sets a spec that will be served for the clients.
200 func (o *A1API) SetSpec(spec *loads.Document) {
201         o.spec = spec
202 }
203
204 // DefaultProduces returns the default produces media type
205 func (o *A1API) DefaultProduces() string {
206         return o.defaultProduces
207 }
208
209 // DefaultConsumes returns the default consumes media type
210 func (o *A1API) DefaultConsumes() string {
211         return o.defaultConsumes
212 }
213
214 // Formats returns the registered string formats
215 func (o *A1API) Formats() strfmt.Registry {
216         return o.formats
217 }
218
219 // RegisterFormat registers a custom format validator
220 func (o *A1API) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
221         o.formats.Add(name, format, validator)
222 }
223
224 // Validate validates the registrations in the A1API
225 func (o *A1API) Validate() error {
226         var unregistered []string
227
228         if o.JSONConsumer == nil {
229                 unregistered = append(unregistered, "JSONConsumer")
230         }
231
232         if o.JSONProducer == nil {
233                 unregistered = append(unregistered, "JSONProducer")
234         }
235
236         if o.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler == nil {
237                 unregistered = append(unregistered, "a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandler")
238         }
239         if o.A1MediatorA1ControllerCreatePolicyTypeHandler == nil {
240                 unregistered = append(unregistered, "a1_mediator.A1ControllerCreatePolicyTypeHandler")
241         }
242         if o.A1eiDataDeliveryA1ControllerDataDeliveryHandler == nil {
243                 unregistered = append(unregistered, "a1_e_i_data_delivery.A1ControllerDataDeliveryHandler")
244         }
245         if o.A1MediatorA1ControllerDeletePolicyInstanceHandler == nil {
246                 unregistered = append(unregistered, "a1_mediator.A1ControllerDeletePolicyInstanceHandler")
247         }
248         if o.A1MediatorA1ControllerDeletePolicyTypeHandler == nil {
249                 unregistered = append(unregistered, "a1_mediator.A1ControllerDeletePolicyTypeHandler")
250         }
251         if o.A1MediatorA1ControllerGetAllInstancesForTypeHandler == nil {
252                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetAllInstancesForTypeHandler")
253         }
254         if o.A1MediatorA1ControllerGetAllPolicyTypesHandler == nil {
255                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetAllPolicyTypesHandler")
256         }
257         if o.A1MediatorA1ControllerGetHealthcheckHandler == nil {
258                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetHealthcheckHandler")
259         }
260         if o.A1MediatorA1ControllerGetPolicyInstanceHandler == nil {
261                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetPolicyInstanceHandler")
262         }
263         if o.A1MediatorA1ControllerGetPolicyInstanceStatusHandler == nil {
264                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetPolicyInstanceStatusHandler")
265         }
266         if o.A1MediatorA1ControllerGetPolicyTypeHandler == nil {
267                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetPolicyTypeHandler")
268         }
269
270         if len(unregistered) > 0 {
271                 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
272         }
273
274         return nil
275 }
276
277 // ServeErrorFor gets a error handler for a given operation id
278 func (o *A1API) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
279         return o.ServeError
280 }
281
282 // AuthenticatorsFor gets the authenticators for the specified security schemes
283 func (o *A1API) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
284         return nil
285 }
286
287 // Authorizer returns the registered authorizer
288 func (o *A1API) Authorizer() runtime.Authorizer {
289         return nil
290 }
291
292 // ConsumersFor gets the consumers for the specified media types.
293 // MIME type parameters are ignored here.
294 func (o *A1API) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
295         result := make(map[string]runtime.Consumer, len(mediaTypes))
296         for _, mt := range mediaTypes {
297                 switch mt {
298                 case "application/json":
299                         result["application/json"] = o.JSONConsumer
300                 }
301
302                 if c, ok := o.customConsumers[mt]; ok {
303                         result[mt] = c
304                 }
305         }
306         return result
307 }
308
309 // ProducersFor gets the producers for the specified media types.
310 // MIME type parameters are ignored here.
311 func (o *A1API) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
312         result := make(map[string]runtime.Producer, len(mediaTypes))
313         for _, mt := range mediaTypes {
314                 switch mt {
315                 case "application/json":
316                         result["application/json"] = o.JSONProducer
317                 }
318
319                 if p, ok := o.customProducers[mt]; ok {
320                         result[mt] = p
321                 }
322         }
323         return result
324 }
325
326 // HandlerFor gets a http.Handler for the provided operation method and path
327 func (o *A1API) HandlerFor(method, path string) (http.Handler, bool) {
328         if o.handlers == nil {
329                 return nil, false
330         }
331         um := strings.ToUpper(method)
332         if _, ok := o.handlers[um]; !ok {
333                 return nil, false
334         }
335         if path == "/" {
336                 path = ""
337         }
338         h, ok := o.handlers[um][path]
339         return h, ok
340 }
341
342 // Context returns the middleware context for the a1 API
343 func (o *A1API) Context() *middleware.Context {
344         if o.context == nil {
345                 o.context = middleware.NewRoutableContext(o.spec, o, nil)
346         }
347
348         return o.context
349 }
350
351 func (o *A1API) initHandlerCache() {
352         o.Context() // don't care about the result, just that the initialization happened
353         if o.handlers == nil {
354                 o.handlers = make(map[string]map[string]http.Handler)
355         }
356
357         if o.handlers["PUT"] == nil {
358                 o.handlers["PUT"] = make(map[string]http.Handler)
359         }
360         o.handlers["PUT"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerCreateOrReplacePolicyInstance(o.context, o.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler)
361         if o.handlers["PUT"] == nil {
362                 o.handlers["PUT"] = make(map[string]http.Handler)
363         }
364         o.handlers["PUT"]["/A1-P/v2/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerCreatePolicyType(o.context, o.A1MediatorA1ControllerCreatePolicyTypeHandler)
365         if o.handlers["POST"] == nil {
366                 o.handlers["POST"] = make(map[string]http.Handler)
367         }
368         o.handlers["POST"]["/data-delivery"] = a1_e_i_data_delivery.NewA1ControllerDataDelivery(o.context, o.A1eiDataDeliveryA1ControllerDataDeliveryHandler)
369         if o.handlers["DELETE"] == nil {
370                 o.handlers["DELETE"] = make(map[string]http.Handler)
371         }
372         o.handlers["DELETE"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerDeletePolicyInstance(o.context, o.A1MediatorA1ControllerDeletePolicyInstanceHandler)
373         if o.handlers["DELETE"] == nil {
374                 o.handlers["DELETE"] = make(map[string]http.Handler)
375         }
376         o.handlers["DELETE"]["/A1-P/v2/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerDeletePolicyType(o.context, o.A1MediatorA1ControllerDeletePolicyTypeHandler)
377         if o.handlers["GET"] == nil {
378                 o.handlers["GET"] = make(map[string]http.Handler)
379         }
380         o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}/policies"] = a1_mediator.NewA1ControllerGetAllInstancesForType(o.context, o.A1MediatorA1ControllerGetAllInstancesForTypeHandler)
381         if o.handlers["GET"] == nil {
382                 o.handlers["GET"] = make(map[string]http.Handler)
383         }
384         o.handlers["GET"]["/A1-P/v2/policytypes"] = a1_mediator.NewA1ControllerGetAllPolicyTypes(o.context, o.A1MediatorA1ControllerGetAllPolicyTypesHandler)
385         if o.handlers["GET"] == nil {
386                 o.handlers["GET"] = make(map[string]http.Handler)
387         }
388         o.handlers["GET"]["/A1-P/v2/healthcheck"] = a1_mediator.NewA1ControllerGetHealthcheck(o.context, o.A1MediatorA1ControllerGetHealthcheckHandler)
389         if o.handlers["GET"] == nil {
390                 o.handlers["GET"] = make(map[string]http.Handler)
391         }
392         o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerGetPolicyInstance(o.context, o.A1MediatorA1ControllerGetPolicyInstanceHandler)
393         if o.handlers["GET"] == nil {
394                 o.handlers["GET"] = make(map[string]http.Handler)
395         }
396         o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}/status"] = a1_mediator.NewA1ControllerGetPolicyInstanceStatus(o.context, o.A1MediatorA1ControllerGetPolicyInstanceStatusHandler)
397         if o.handlers["GET"] == nil {
398                 o.handlers["GET"] = make(map[string]http.Handler)
399         }
400         o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerGetPolicyType(o.context, o.A1MediatorA1ControllerGetPolicyTypeHandler)
401 }
402
403 // Serve creates a http handler to serve the API over HTTP
404 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
405 func (o *A1API) Serve(builder middleware.Builder) http.Handler {
406         o.Init()
407
408         if o.Middleware != nil {
409                 return o.Middleware(builder)
410         }
411         if o.useSwaggerUI {
412                 return o.context.APIHandlerSwaggerUI(builder)
413         }
414         return o.context.APIHandler(builder)
415 }
416
417 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
418 func (o *A1API) Init() {
419         if len(o.handlers) == 0 {
420                 o.initHandlerCache()
421         }
422 }
423
424 // RegisterConsumer allows you to add (or override) a consumer for a media type.
425 func (o *A1API) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
426         o.customConsumers[mediaType] = consumer
427 }
428
429 // RegisterProducer allows you to add (or override) a producer for a media type.
430 func (o *A1API) RegisterProducer(mediaType string, producer runtime.Producer) {
431         o.customProducers[mediaType] = producer
432 }
433
434 // AddMiddlewareFor adds a http middleware to existing handler
435 func (o *A1API) AddMiddlewareFor(method, path string, builder middleware.Builder) {
436         um := strings.ToUpper(method)
437         if path == "/" {
438                 path = ""
439         }
440         o.Init()
441         if h, ok := o.handlers[um][path]; ok {
442                 o.handlers[method][path] = builder(h)
443         }
444 }