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