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