Update module name
[ric-plt/a1.git] / a1-go / 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                 ServeError:          errors.ServeError,
59                 BasicAuthenticator:  security.BasicAuth,
60                 APIKeyAuthenticator: security.APIKeyAuth,
61                 BearerAuthenticator: security.BearerAuth,
62
63                 JSONConsumer: runtime.JSONConsumer(),
64
65                 JSONProducer: runtime.JSONProducer(),
66
67                 A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler: a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerCreateOrReplacePolicyInstanceParams) middleware.Responder {
68                         return middleware.NotImplemented("operation a1_mediator.A1ControllerCreateOrReplacePolicyInstance has not yet been implemented")
69                 }),
70                 A1MediatorA1ControllerCreatePolicyTypeHandler: a1_mediator.A1ControllerCreatePolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerCreatePolicyTypeParams) middleware.Responder {
71                         return middleware.NotImplemented("operation a1_mediator.A1ControllerCreatePolicyType has not yet been implemented")
72                 }),
73                 A1eiDataDeliveryA1ControllerDataDeliveryHandler: a1_e_i_data_delivery.A1ControllerDataDeliveryHandlerFunc(func(params a1_e_i_data_delivery.A1ControllerDataDeliveryParams) middleware.Responder {
74                         return middleware.NotImplemented("operation a1_e_i_data_delivery.A1ControllerDataDelivery has not yet been implemented")
75                 }),
76                 A1MediatorA1ControllerDeletePolicyInstanceHandler: a1_mediator.A1ControllerDeletePolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerDeletePolicyInstanceParams) middleware.Responder {
77                         return middleware.NotImplemented("operation a1_mediator.A1ControllerDeletePolicyInstance has not yet been implemented")
78                 }),
79                 A1MediatorA1ControllerDeletePolicyTypeHandler: a1_mediator.A1ControllerDeletePolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerDeletePolicyTypeParams) middleware.Responder {
80                         return middleware.NotImplemented("operation a1_mediator.A1ControllerDeletePolicyType has not yet been implemented")
81                 }),
82                 A1MediatorA1ControllerGetAllInstancesForTypeHandler: a1_mediator.A1ControllerGetAllInstancesForTypeHandlerFunc(func(params a1_mediator.A1ControllerGetAllInstancesForTypeParams) middleware.Responder {
83                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetAllInstancesForType has not yet been implemented")
84                 }),
85                 A1MediatorA1ControllerGetAllPolicyTypesHandler: a1_mediator.A1ControllerGetAllPolicyTypesHandlerFunc(func(params a1_mediator.A1ControllerGetAllPolicyTypesParams) middleware.Responder {
86                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetAllPolicyTypes has not yet been implemented")
87                 }),
88                 A1MediatorA1ControllerGetHealthcheckHandler: a1_mediator.A1ControllerGetHealthcheckHandlerFunc(func(params a1_mediator.A1ControllerGetHealthcheckParams) middleware.Responder {
89                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetHealthcheck has not yet been implemented")
90                 }),
91                 A1MediatorA1ControllerGetPolicyInstanceHandler: a1_mediator.A1ControllerGetPolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyInstanceParams) middleware.Responder {
92                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetPolicyInstance has not yet been implemented")
93                 }),
94                 A1MediatorA1ControllerGetPolicyInstanceStatusHandler: a1_mediator.A1ControllerGetPolicyInstanceStatusHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyInstanceStatusParams) middleware.Responder {
95                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetPolicyInstanceStatus has not yet been implemented")
96                 }),
97                 A1MediatorA1ControllerGetPolicyTypeHandler: a1_mediator.A1ControllerGetPolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyTypeParams) middleware.Responder {
98                         return middleware.NotImplemented("operation a1_mediator.A1ControllerGetPolicyType has not yet been implemented")
99                 }),
100         }
101 }
102
103 /*A1API the a1 API */
104 type A1API struct {
105         spec            *loads.Document
106         context         *middleware.Context
107         handlers        map[string]map[string]http.Handler
108         formats         strfmt.Registry
109         customConsumers map[string]runtime.Consumer
110         customProducers map[string]runtime.Producer
111         defaultConsumes string
112         defaultProduces string
113         Middleware      func(middleware.Builder) http.Handler
114
115         // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
116         // It has a default implementation in the security package, however you can replace it for your particular usage.
117         BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
118         // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
119         // It has a default implementation in the security package, however you can replace it for your particular usage.
120         APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
121         // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
122         // It has a default implementation in the security package, however you can replace it for your particular usage.
123         BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
124
125         // JSONConsumer registers a consumer for the following mime types:
126         //   - application/json
127         JSONConsumer runtime.Consumer
128
129         // JSONProducer registers a producer for the following mime types:
130         //   - application/json
131         JSONProducer runtime.Producer
132
133         // A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler sets the operation handler for the a1 controller create or replace policy instance operation
134         A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandler
135         // A1MediatorA1ControllerCreatePolicyTypeHandler sets the operation handler for the a1 controller create policy type operation
136         A1MediatorA1ControllerCreatePolicyTypeHandler a1_mediator.A1ControllerCreatePolicyTypeHandler
137         // A1eiDataDeliveryA1ControllerDataDeliveryHandler sets the operation handler for the a1 controller data delivery operation
138         A1eiDataDeliveryA1ControllerDataDeliveryHandler a1_e_i_data_delivery.A1ControllerDataDeliveryHandler
139         // A1MediatorA1ControllerDeletePolicyInstanceHandler sets the operation handler for the a1 controller delete policy instance operation
140         A1MediatorA1ControllerDeletePolicyInstanceHandler a1_mediator.A1ControllerDeletePolicyInstanceHandler
141         // A1MediatorA1ControllerDeletePolicyTypeHandler sets the operation handler for the a1 controller delete policy type operation
142         A1MediatorA1ControllerDeletePolicyTypeHandler a1_mediator.A1ControllerDeletePolicyTypeHandler
143         // A1MediatorA1ControllerGetAllInstancesForTypeHandler sets the operation handler for the a1 controller get all instances for type operation
144         A1MediatorA1ControllerGetAllInstancesForTypeHandler a1_mediator.A1ControllerGetAllInstancesForTypeHandler
145         // A1MediatorA1ControllerGetAllPolicyTypesHandler sets the operation handler for the a1 controller get all policy types operation
146         A1MediatorA1ControllerGetAllPolicyTypesHandler a1_mediator.A1ControllerGetAllPolicyTypesHandler
147         // A1MediatorA1ControllerGetHealthcheckHandler sets the operation handler for the a1 controller get healthcheck operation
148         A1MediatorA1ControllerGetHealthcheckHandler a1_mediator.A1ControllerGetHealthcheckHandler
149         // A1MediatorA1ControllerGetPolicyInstanceHandler sets the operation handler for the a1 controller get policy instance operation
150         A1MediatorA1ControllerGetPolicyInstanceHandler a1_mediator.A1ControllerGetPolicyInstanceHandler
151         // A1MediatorA1ControllerGetPolicyInstanceStatusHandler sets the operation handler for the a1 controller get policy instance status operation
152         A1MediatorA1ControllerGetPolicyInstanceStatusHandler a1_mediator.A1ControllerGetPolicyInstanceStatusHandler
153         // A1MediatorA1ControllerGetPolicyTypeHandler sets the operation handler for the a1 controller get policy type operation
154         A1MediatorA1ControllerGetPolicyTypeHandler a1_mediator.A1ControllerGetPolicyTypeHandler
155         // ServeError is called when an error is received, there is a default handler
156         // but you can set your own with this
157         ServeError func(http.ResponseWriter, *http.Request, error)
158
159         // PreServerShutdown is called before the HTTP(S) server is shutdown
160         // This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic
161         PreServerShutdown func()
162
163         // ServerShutdown is called when the HTTP(S) server is shut down and done
164         // handling all active connections and does not accept connections any more
165         ServerShutdown func()
166
167         // Custom command line argument groups with their descriptions
168         CommandLineOptionsGroups []swag.CommandLineOptionsGroup
169
170         // User defined logger function.
171         Logger func(string, ...interface{})
172 }
173
174 // SetDefaultProduces sets the default produces media type
175 func (o *A1API) SetDefaultProduces(mediaType string) {
176         o.defaultProduces = mediaType
177 }
178
179 // SetDefaultConsumes returns the default consumes media type
180 func (o *A1API) SetDefaultConsumes(mediaType string) {
181         o.defaultConsumes = mediaType
182 }
183
184 // SetSpec sets a spec that will be served for the clients.
185 func (o *A1API) SetSpec(spec *loads.Document) {
186         o.spec = spec
187 }
188
189 // DefaultProduces returns the default produces media type
190 func (o *A1API) DefaultProduces() string {
191         return o.defaultProduces
192 }
193
194 // DefaultConsumes returns the default consumes media type
195 func (o *A1API) DefaultConsumes() string {
196         return o.defaultConsumes
197 }
198
199 // Formats returns the registered string formats
200 func (o *A1API) Formats() strfmt.Registry {
201         return o.formats
202 }
203
204 // RegisterFormat registers a custom format validator
205 func (o *A1API) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
206         o.formats.Add(name, format, validator)
207 }
208
209 // Validate validates the registrations in the A1API
210 func (o *A1API) Validate() error {
211         var unregistered []string
212
213         if o.JSONConsumer == nil {
214                 unregistered = append(unregistered, "JSONConsumer")
215         }
216
217         if o.JSONProducer == nil {
218                 unregistered = append(unregistered, "JSONProducer")
219         }
220
221         if o.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler == nil {
222                 unregistered = append(unregistered, "a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandler")
223         }
224         if o.A1MediatorA1ControllerCreatePolicyTypeHandler == nil {
225                 unregistered = append(unregistered, "a1_mediator.A1ControllerCreatePolicyTypeHandler")
226         }
227         if o.A1eiDataDeliveryA1ControllerDataDeliveryHandler == nil {
228                 unregistered = append(unregistered, "a1_e_i_data_delivery.A1ControllerDataDeliveryHandler")
229         }
230         if o.A1MediatorA1ControllerDeletePolicyInstanceHandler == nil {
231                 unregistered = append(unregistered, "a1_mediator.A1ControllerDeletePolicyInstanceHandler")
232         }
233         if o.A1MediatorA1ControllerDeletePolicyTypeHandler == nil {
234                 unregistered = append(unregistered, "a1_mediator.A1ControllerDeletePolicyTypeHandler")
235         }
236         if o.A1MediatorA1ControllerGetAllInstancesForTypeHandler == nil {
237                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetAllInstancesForTypeHandler")
238         }
239         if o.A1MediatorA1ControllerGetAllPolicyTypesHandler == nil {
240                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetAllPolicyTypesHandler")
241         }
242         if o.A1MediatorA1ControllerGetHealthcheckHandler == nil {
243                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetHealthcheckHandler")
244         }
245         if o.A1MediatorA1ControllerGetPolicyInstanceHandler == nil {
246                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetPolicyInstanceHandler")
247         }
248         if o.A1MediatorA1ControllerGetPolicyInstanceStatusHandler == nil {
249                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetPolicyInstanceStatusHandler")
250         }
251         if o.A1MediatorA1ControllerGetPolicyTypeHandler == nil {
252                 unregistered = append(unregistered, "a1_mediator.A1ControllerGetPolicyTypeHandler")
253         }
254
255         if len(unregistered) > 0 {
256                 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
257         }
258
259         return nil
260 }
261
262 // ServeErrorFor gets a error handler for a given operation id
263 func (o *A1API) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
264         return o.ServeError
265 }
266
267 // AuthenticatorsFor gets the authenticators for the specified security schemes
268 func (o *A1API) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
269         return nil
270 }
271
272 // Authorizer returns the registered authorizer
273 func (o *A1API) Authorizer() runtime.Authorizer {
274         return nil
275 }
276
277 // ConsumersFor gets the consumers for the specified media types.
278 // MIME type parameters are ignored here.
279 func (o *A1API) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
280         result := make(map[string]runtime.Consumer, len(mediaTypes))
281         for _, mt := range mediaTypes {
282                 switch mt {
283                 case "application/json":
284                         result["application/json"] = o.JSONConsumer
285                 }
286
287                 if c, ok := o.customConsumers[mt]; ok {
288                         result[mt] = c
289                 }
290         }
291         return result
292 }
293
294 // ProducersFor gets the producers for the specified media types.
295 // MIME type parameters are ignored here.
296 func (o *A1API) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
297         result := make(map[string]runtime.Producer, len(mediaTypes))
298         for _, mt := range mediaTypes {
299                 switch mt {
300                 case "application/json":
301                         result["application/json"] = o.JSONProducer
302                 }
303
304                 if p, ok := o.customProducers[mt]; ok {
305                         result[mt] = p
306                 }
307         }
308         return result
309 }
310
311 // HandlerFor gets a http.Handler for the provided operation method and path
312 func (o *A1API) HandlerFor(method, path string) (http.Handler, bool) {
313         if o.handlers == nil {
314                 return nil, false
315         }
316         um := strings.ToUpper(method)
317         if _, ok := o.handlers[um]; !ok {
318                 return nil, false
319         }
320         if path == "/" {
321                 path = ""
322         }
323         h, ok := o.handlers[um][path]
324         return h, ok
325 }
326
327 // Context returns the middleware context for the a1 API
328 func (o *A1API) Context() *middleware.Context {
329         if o.context == nil {
330                 o.context = middleware.NewRoutableContext(o.spec, o, nil)
331         }
332
333         return o.context
334 }
335
336 func (o *A1API) initHandlerCache() {
337         o.Context() // don't care about the result, just that the initialization happened
338         if o.handlers == nil {
339                 o.handlers = make(map[string]map[string]http.Handler)
340         }
341
342         if o.handlers["PUT"] == nil {
343                 o.handlers["PUT"] = make(map[string]http.Handler)
344         }
345         o.handlers["PUT"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerCreateOrReplacePolicyInstance(o.context, o.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler)
346         if o.handlers["PUT"] == nil {
347                 o.handlers["PUT"] = make(map[string]http.Handler)
348         }
349         o.handlers["PUT"]["/a1-p/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerCreatePolicyType(o.context, o.A1MediatorA1ControllerCreatePolicyTypeHandler)
350         if o.handlers["POST"] == nil {
351                 o.handlers["POST"] = make(map[string]http.Handler)
352         }
353         o.handlers["POST"]["/data-delivery"] = a1_e_i_data_delivery.NewA1ControllerDataDelivery(o.context, o.A1eiDataDeliveryA1ControllerDataDeliveryHandler)
354         if o.handlers["DELETE"] == nil {
355                 o.handlers["DELETE"] = make(map[string]http.Handler)
356         }
357         o.handlers["DELETE"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerDeletePolicyInstance(o.context, o.A1MediatorA1ControllerDeletePolicyInstanceHandler)
358         if o.handlers["DELETE"] == nil {
359                 o.handlers["DELETE"] = make(map[string]http.Handler)
360         }
361         o.handlers["DELETE"]["/a1-p/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerDeletePolicyType(o.context, o.A1MediatorA1ControllerDeletePolicyTypeHandler)
362         if o.handlers["GET"] == nil {
363                 o.handlers["GET"] = make(map[string]http.Handler)
364         }
365         o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}/policies"] = a1_mediator.NewA1ControllerGetAllInstancesForType(o.context, o.A1MediatorA1ControllerGetAllInstancesForTypeHandler)
366         if o.handlers["GET"] == nil {
367                 o.handlers["GET"] = make(map[string]http.Handler)
368         }
369         o.handlers["GET"]["/a1-p/policytypes"] = a1_mediator.NewA1ControllerGetAllPolicyTypes(o.context, o.A1MediatorA1ControllerGetAllPolicyTypesHandler)
370         if o.handlers["GET"] == nil {
371                 o.handlers["GET"] = make(map[string]http.Handler)
372         }
373         o.handlers["GET"]["/a1-p/healthcheck"] = a1_mediator.NewA1ControllerGetHealthcheck(o.context, o.A1MediatorA1ControllerGetHealthcheckHandler)
374         if o.handlers["GET"] == nil {
375                 o.handlers["GET"] = make(map[string]http.Handler)
376         }
377         o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerGetPolicyInstance(o.context, o.A1MediatorA1ControllerGetPolicyInstanceHandler)
378         if o.handlers["GET"] == nil {
379                 o.handlers["GET"] = make(map[string]http.Handler)
380         }
381         o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status"] = a1_mediator.NewA1ControllerGetPolicyInstanceStatus(o.context, o.A1MediatorA1ControllerGetPolicyInstanceStatusHandler)
382         if o.handlers["GET"] == nil {
383                 o.handlers["GET"] = make(map[string]http.Handler)
384         }
385         o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerGetPolicyType(o.context, o.A1MediatorA1ControllerGetPolicyTypeHandler)
386 }
387
388 // Serve creates a http handler to serve the API over HTTP
389 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
390 func (o *A1API) Serve(builder middleware.Builder) http.Handler {
391         o.Init()
392
393         if o.Middleware != nil {
394                 return o.Middleware(builder)
395         }
396         return o.context.APIHandler(builder)
397 }
398
399 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
400 func (o *A1API) Init() {
401         if len(o.handlers) == 0 {
402                 o.initHandlerCache()
403         }
404 }
405
406 // RegisterConsumer allows you to add (or override) a consumer for a media type.
407 func (o *A1API) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
408         o.customConsumers[mediaType] = consumer
409 }
410
411 // RegisterProducer allows you to add (or override) a producer for a media type.
412 func (o *A1API) RegisterProducer(mediaType string, producer runtime.Producer) {
413         o.customProducers[mediaType] = producer
414 }
415
416 // AddMiddlewareFor adds a http middleware to existing handler
417 func (o *A1API) AddMiddlewareFor(method, path string, builder middleware.Builder) {
418         um := strings.ToUpper(method)
419         if path == "/" {
420                 path = ""
421         }
422         o.Init()
423         if h, ok := o.handlers[um][path]; ok {
424                 o.handlers[method][path] = builder(h)
425         }
426 }