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