e16707ee46df38843d3d9b122d3b41b0449a361b
[ric-plt/xapp-frame.git] / pkg / restapi / operations / xapp_framework_api.go
1 // Code generated by go-swagger; DO NOT EDIT.
2
3 package operations
4
5 // This file was generated by the swagger tool.
6 // Editing this file might prove futile when you re-run the swagger generate command
7
8 import (
9         "fmt"
10         "net/http"
11         "strings"
12
13         errors "github.com/go-openapi/errors"
14         loads "github.com/go-openapi/loads"
15         runtime "github.com/go-openapi/runtime"
16         middleware "github.com/go-openapi/runtime/middleware"
17         security "github.com/go-openapi/runtime/security"
18         spec "github.com/go-openapi/spec"
19         strfmt "github.com/go-openapi/strfmt"
20         "github.com/go-openapi/swag"
21
22         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common"
23         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/xapp"
24 )
25
26 // NewXappFrameworkAPI creates a new XappFramework instance
27 func NewXappFrameworkAPI(spec *loads.Document) *XappFrameworkAPI {
28         return &XappFrameworkAPI{
29                 handlers:            make(map[string]map[string]http.Handler),
30                 formats:             strfmt.Default,
31                 defaultConsumes:     "application/json",
32                 defaultProduces:     "application/json",
33                 customConsumers:     make(map[string]runtime.Consumer),
34                 customProducers:     make(map[string]runtime.Producer),
35                 ServerShutdown:      func() {},
36                 spec:                spec,
37                 ServeError:          errors.ServeError,
38                 BasicAuthenticator:  security.BasicAuth,
39                 APIKeyAuthenticator: security.APIKeyAuth,
40                 BearerAuthenticator: security.BearerAuth,
41                 JSONConsumer:        runtime.JSONConsumer(),
42                 JSONProducer:        runtime.JSONProducer(),
43                 XMLProducer:         runtime.XMLProducer(),
44                 CommonSubscribeHandler: common.SubscribeHandlerFunc(func(params common.SubscribeParams) middleware.Responder {
45                         return middleware.NotImplemented("operation CommonSubscribe has not yet been implemented")
46                 }),
47                 CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
48                         return middleware.NotImplemented("operation CommonUnsubscribe has not yet been implemented")
49                 }),
50                 CommonGetAllSubscriptionsHandler: common.GetAllSubscriptionsHandlerFunc(func(params common.GetAllSubscriptionsParams) middleware.Responder {
51                         return middleware.NotImplemented("operation CommonGetAllSubscriptions has not yet been implemented")
52                 }),
53                 XappGetXappConfigListHandler: xapp.GetXappConfigListHandlerFunc(func(params xapp.GetXappConfigListParams) middleware.Responder {
54                         return middleware.NotImplemented("operation XappGetXappConfigList has not yet been implemented")
55                 }),
56         }
57 }
58
59 /*XappFrameworkAPI This is the initial REST API for RIC subscription */
60 type XappFrameworkAPI struct {
61         spec            *loads.Document
62         context         *middleware.Context
63         handlers        map[string]map[string]http.Handler
64         formats         strfmt.Registry
65         customConsumers map[string]runtime.Consumer
66         customProducers map[string]runtime.Producer
67         defaultConsumes string
68         defaultProduces string
69         Middleware      func(middleware.Builder) http.Handler
70
71         // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
72         // It has a default implementation in the security package, however you can replace it for your particular usage.
73         BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
74         // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
75         // It has a default implementation in the security package, however you can replace it for your particular usage.
76         APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
77         // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
78         // It has a default implementation in the security package, however you can replace it for your particular usage.
79         BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
80
81         // JSONConsumer registers a consumer for a "application/json" mime type
82         JSONConsumer runtime.Consumer
83
84         // JSONProducer registers a producer for a "application/json" mime type
85         JSONProducer runtime.Producer
86         // XMLProducer registers a producer for a "application/xml" mime type
87         XMLProducer runtime.Producer
88
89         // CommonSubscribeHandler sets the operation handler for the subscribe operation
90         CommonSubscribeHandler common.SubscribeHandler
91         // CommonUnsubscribeHandler sets the operation handler for the unsubscribe operation
92         CommonUnsubscribeHandler common.UnsubscribeHandler
93         // CommonGetAllSubscriptionsHandler sets the operation handler for the get all subscriptions operation
94         CommonGetAllSubscriptionsHandler common.GetAllSubscriptionsHandler
95         // XappGetXappConfigListHandler sets the operation handler for the get xapp config list operation
96         XappGetXappConfigListHandler xapp.GetXappConfigListHandler
97
98         // ServeError is called when an error is received, there is a default handler
99         // but you can set your own with this
100         ServeError func(http.ResponseWriter, *http.Request, error)
101
102         // ServerShutdown is called when the HTTP(S) server is shut down and done
103         // handling all active connections and does not accept connections any more
104         ServerShutdown func()
105
106         // Custom command line argument groups with their descriptions
107         CommandLineOptionsGroups []swag.CommandLineOptionsGroup
108
109         // User defined logger function.
110         Logger func(string, ...interface{})
111 }
112
113 // SetDefaultProduces sets the default produces media type
114 func (o *XappFrameworkAPI) SetDefaultProduces(mediaType string) {
115         o.defaultProduces = mediaType
116 }
117
118 // SetDefaultConsumes returns the default consumes media type
119 func (o *XappFrameworkAPI) SetDefaultConsumes(mediaType string) {
120         o.defaultConsumes = mediaType
121 }
122
123 // SetSpec sets a spec that will be served for the clients.
124 func (o *XappFrameworkAPI) SetSpec(spec *loads.Document) {
125         o.spec = spec
126 }
127
128 // DefaultProduces returns the default produces media type
129 func (o *XappFrameworkAPI) DefaultProduces() string {
130         return o.defaultProduces
131 }
132
133 // DefaultConsumes returns the default consumes media type
134 func (o *XappFrameworkAPI) DefaultConsumes() string {
135         return o.defaultConsumes
136 }
137
138 // Formats returns the registered string formats
139 func (o *XappFrameworkAPI) Formats() strfmt.Registry {
140         return o.formats
141 }
142
143 // RegisterFormat registers a custom format validator
144 func (o *XappFrameworkAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
145         o.formats.Add(name, format, validator)
146 }
147
148 // Validate validates the registrations in the XappFrameworkAPI
149 func (o *XappFrameworkAPI) Validate() error {
150         var unregistered []string
151
152         if o.JSONConsumer == nil {
153                 unregistered = append(unregistered, "JSONConsumer")
154         }
155
156         if o.JSONProducer == nil {
157                 unregistered = append(unregistered, "JSONProducer")
158         }
159
160         if o.XMLProducer == nil {
161                 unregistered = append(unregistered, "XMLProducer")
162         }
163
164         if o.CommonSubscribeHandler == nil {
165                 unregistered = append(unregistered, "common.SubscribeHandler")
166         }
167
168         if o.CommonUnsubscribeHandler == nil {
169                 unregistered = append(unregistered, "common.UnsubscribeHandler")
170         }
171
172         if o.CommonGetAllSubscriptionsHandler == nil {
173                 unregistered = append(unregistered, "common.GetAllSubscriptionsHandler")
174         }
175
176         if o.XappGetXappConfigListHandler == nil {
177                 unregistered = append(unregistered, "xapp.GetXappConfigListHandler")
178         }
179
180         if len(unregistered) > 0 {
181                 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
182         }
183
184         return nil
185 }
186
187 // ServeErrorFor gets a error handler for a given operation id
188 func (o *XappFrameworkAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
189         return o.ServeError
190 }
191
192 // AuthenticatorsFor gets the authenticators for the specified security schemes
193 func (o *XappFrameworkAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
194
195         return nil
196
197 }
198
199 // Authorizer returns the registered authorizer
200 func (o *XappFrameworkAPI) Authorizer() runtime.Authorizer {
201
202         return nil
203
204 }
205
206 // ConsumersFor gets the consumers for the specified media types
207 func (o *XappFrameworkAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
208
209         result := make(map[string]runtime.Consumer)
210         for _, mt := range mediaTypes {
211                 switch mt {
212
213                 case "application/json":
214                         result["application/json"] = o.JSONConsumer
215
216                 }
217
218                 if c, ok := o.customConsumers[mt]; ok {
219                         result[mt] = c
220                 }
221         }
222         return result
223
224 }
225
226 // ProducersFor gets the producers for the specified media types
227 func (o *XappFrameworkAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
228
229         result := make(map[string]runtime.Producer)
230         for _, mt := range mediaTypes {
231                 switch mt {
232
233                 case "application/json":
234                         result["application/json"] = o.JSONProducer
235
236                 case "application/xml":
237                         result["application/xml"] = o.XMLProducer
238
239                 }
240
241                 if p, ok := o.customProducers[mt]; ok {
242                         result[mt] = p
243                 }
244         }
245         return result
246
247 }
248
249 // HandlerFor gets a http.Handler for the provided operation method and path
250 func (o *XappFrameworkAPI) HandlerFor(method, path string) (http.Handler, bool) {
251         if o.handlers == nil {
252                 return nil, false
253         }
254         um := strings.ToUpper(method)
255         if _, ok := o.handlers[um]; !ok {
256                 return nil, false
257         }
258         if path == "/" {
259                 path = ""
260         }
261         h, ok := o.handlers[um][path]
262         return h, ok
263 }
264
265 // Context returns the middleware context for the xapp framework API
266 func (o *XappFrameworkAPI) Context() *middleware.Context {
267         if o.context == nil {
268                 o.context = middleware.NewRoutableContext(o.spec, o, nil)
269         }
270
271         return o.context
272 }
273
274 func (o *XappFrameworkAPI) initHandlerCache() {
275         o.Context() // don't care about the result, just that the initialization happened
276
277         if o.handlers == nil {
278                 o.handlers = make(map[string]map[string]http.Handler)
279         }
280
281         if o.handlers["POST"] == nil {
282                 o.handlers["POST"] = make(map[string]http.Handler)
283         }
284         o.handlers["POST"]["/subscriptions"] = common.NewSubscribe(o.context, o.CommonSubscribeHandler)
285
286         if o.handlers["DELETE"] == nil {
287                 o.handlers["DELETE"] = make(map[string]http.Handler)
288         }
289         o.handlers["DELETE"]["/subscriptions/{subscriptionId}"] = common.NewUnsubscribe(o.context, o.CommonUnsubscribeHandler)
290
291         if o.handlers["GET"] == nil {
292                 o.handlers["GET"] = make(map[string]http.Handler)
293         }
294         o.handlers["GET"]["/subscriptions"] = common.NewGetAllSubscriptions(o.context, o.CommonGetAllSubscriptionsHandler)
295
296         if o.handlers["GET"] == nil {
297                 o.handlers["GET"] = make(map[string]http.Handler)
298         }
299         o.handlers["GET"]["/config"] = xapp.NewGetXappConfigList(o.context, o.XappGetXappConfigListHandler)
300
301 }
302
303 // Serve creates a http handler to serve the API over HTTP
304 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
305 func (o *XappFrameworkAPI) Serve(builder middleware.Builder) http.Handler {
306         o.Init()
307
308         if o.Middleware != nil {
309                 return o.Middleware(builder)
310         }
311         return o.context.APIHandler(builder)
312 }
313
314 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
315 func (o *XappFrameworkAPI) Init() {
316         if len(o.handlers) == 0 {
317                 o.initHandlerCache()
318         }
319 }
320
321 // RegisterConsumer allows you to add (or override) a consumer for a media type.
322 func (o *XappFrameworkAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
323         o.customConsumers[mediaType] = consumer
324 }
325
326 // RegisterProducer allows you to add (or override) a producer for a media type.
327 func (o *XappFrameworkAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
328         o.customProducers[mediaType] = producer
329 }