github.com/cilium/cilium@v1.16.2/api/v1/health/server/restapi/cilium_health_api_api.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 // Copyright Authors of Cilium 4 // SPDX-License-Identifier: Apache-2.0 5 6 package restapi 7 8 // This file was generated by the swagger tool. 9 // Editing this file might prove futile when you re-run the swagger generate command 10 11 import ( 12 "fmt" 13 "net/http" 14 "strings" 15 16 "github.com/go-openapi/errors" 17 "github.com/go-openapi/loads" 18 "github.com/go-openapi/runtime" 19 "github.com/go-openapi/runtime/middleware" 20 "github.com/go-openapi/runtime/security" 21 "github.com/go-openapi/spec" 22 "github.com/go-openapi/strfmt" 23 "github.com/go-openapi/swag" 24 25 "github.com/cilium/cilium/api/v1/health/server/restapi/connectivity" 26 ) 27 28 // NewCiliumHealthAPIAPI creates a new CiliumHealthAPI instance 29 func NewCiliumHealthAPIAPI(spec *loads.Document) *CiliumHealthAPIAPI { 30 return &CiliumHealthAPIAPI{ 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 PreServerShutdown: func() {}, 38 ServerShutdown: func() {}, 39 spec: spec, 40 useSwaggerUI: false, 41 ServeError: errors.ServeError, 42 BasicAuthenticator: security.BasicAuth, 43 APIKeyAuthenticator: security.APIKeyAuth, 44 BearerAuthenticator: security.BearerAuth, 45 46 JSONConsumer: runtime.JSONConsumer(), 47 48 JSONProducer: runtime.JSONProducer(), 49 50 GetHealthzHandler: GetHealthzHandlerFunc(func(params GetHealthzParams) middleware.Responder { 51 return middleware.NotImplemented("operation GetHealthz has not yet been implemented") 52 }), 53 ConnectivityGetStatusHandler: connectivity.GetStatusHandlerFunc(func(params connectivity.GetStatusParams) middleware.Responder { 54 return middleware.NotImplemented("operation connectivity.GetStatus has not yet been implemented") 55 }), 56 ConnectivityPutStatusProbeHandler: connectivity.PutStatusProbeHandlerFunc(func(params connectivity.PutStatusProbeParams) middleware.Responder { 57 return middleware.NotImplemented("operation connectivity.PutStatusProbe has not yet been implemented") 58 }), 59 } 60 } 61 62 /*CiliumHealthAPIAPI Cilium Health Checker */ 63 type CiliumHealthAPIAPI struct { 64 spec *loads.Document 65 context *middleware.Context 66 handlers map[string]map[string]http.Handler 67 formats strfmt.Registry 68 customConsumers map[string]runtime.Consumer 69 customProducers map[string]runtime.Producer 70 defaultConsumes string 71 defaultProduces string 72 Middleware func(middleware.Builder) http.Handler 73 useSwaggerUI bool 74 75 // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function. 76 // It has a default implementation in the security package, however you can replace it for your particular usage. 77 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator 78 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 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 the following mime types: 88 // - application/json 89 JSONConsumer runtime.Consumer 90 91 // JSONProducer registers a producer for the following mime types: 92 // - application/json 93 JSONProducer runtime.Producer 94 95 // GetHealthzHandler sets the operation handler for the get healthz operation 96 GetHealthzHandler GetHealthzHandler 97 // ConnectivityGetStatusHandler sets the operation handler for the get status operation 98 ConnectivityGetStatusHandler connectivity.GetStatusHandler 99 // ConnectivityPutStatusProbeHandler sets the operation handler for the put status probe operation 100 ConnectivityPutStatusProbeHandler connectivity.PutStatusProbeHandler 101 102 // ServeError is called when an error is received, there is a default handler 103 // but you can set your own with this 104 ServeError func(http.ResponseWriter, *http.Request, error) 105 106 // PreServerShutdown is called before the HTTP(S) server is shutdown 107 // This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic 108 PreServerShutdown func() 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 // UseRedoc for documentation at /docs 122 func (o *CiliumHealthAPIAPI) UseRedoc() { 123 o.useSwaggerUI = false 124 } 125 126 // UseSwaggerUI for documentation at /docs 127 func (o *CiliumHealthAPIAPI) UseSwaggerUI() { 128 o.useSwaggerUI = true 129 } 130 131 // SetDefaultProduces sets the default produces media type 132 func (o *CiliumHealthAPIAPI) SetDefaultProduces(mediaType string) { 133 o.defaultProduces = mediaType 134 } 135 136 // SetDefaultConsumes returns the default consumes media type 137 func (o *CiliumHealthAPIAPI) SetDefaultConsumes(mediaType string) { 138 o.defaultConsumes = mediaType 139 } 140 141 // SetSpec sets a spec that will be served for the clients. 142 func (o *CiliumHealthAPIAPI) SetSpec(spec *loads.Document) { 143 o.spec = spec 144 } 145 146 // DefaultProduces returns the default produces media type 147 func (o *CiliumHealthAPIAPI) DefaultProduces() string { 148 return o.defaultProduces 149 } 150 151 // DefaultConsumes returns the default consumes media type 152 func (o *CiliumHealthAPIAPI) DefaultConsumes() string { 153 return o.defaultConsumes 154 } 155 156 // Formats returns the registered string formats 157 func (o *CiliumHealthAPIAPI) Formats() strfmt.Registry { 158 return o.formats 159 } 160 161 // RegisterFormat registers a custom format validator 162 func (o *CiliumHealthAPIAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) { 163 o.formats.Add(name, format, validator) 164 } 165 166 // Validate validates the registrations in the CiliumHealthAPIAPI 167 func (o *CiliumHealthAPIAPI) Validate() error { 168 var unregistered []string 169 170 if o.JSONConsumer == nil { 171 unregistered = append(unregistered, "JSONConsumer") 172 } 173 174 if o.JSONProducer == nil { 175 unregistered = append(unregistered, "JSONProducer") 176 } 177 178 if o.GetHealthzHandler == nil { 179 unregistered = append(unregistered, "GetHealthzHandler") 180 } 181 if o.ConnectivityGetStatusHandler == nil { 182 unregistered = append(unregistered, "connectivity.GetStatusHandler") 183 } 184 if o.ConnectivityPutStatusProbeHandler == nil { 185 unregistered = append(unregistered, "connectivity.PutStatusProbeHandler") 186 } 187 188 if len(unregistered) > 0 { 189 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", ")) 190 } 191 192 return nil 193 } 194 195 // ServeErrorFor gets a error handler for a given operation id 196 func (o *CiliumHealthAPIAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) { 197 return o.ServeError 198 } 199 200 // AuthenticatorsFor gets the authenticators for the specified security schemes 201 func (o *CiliumHealthAPIAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator { 202 return nil 203 } 204 205 // Authorizer returns the registered authorizer 206 func (o *CiliumHealthAPIAPI) Authorizer() runtime.Authorizer { 207 return nil 208 } 209 210 // ConsumersFor gets the consumers for the specified media types. 211 // MIME type parameters are ignored here. 212 func (o *CiliumHealthAPIAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer { 213 result := make(map[string]runtime.Consumer, len(mediaTypes)) 214 for _, mt := range mediaTypes { 215 switch mt { 216 case "application/json": 217 result["application/json"] = o.JSONConsumer 218 } 219 220 if c, ok := o.customConsumers[mt]; ok { 221 result[mt] = c 222 } 223 } 224 return result 225 } 226 227 // ProducersFor gets the producers for the specified media types. 228 // MIME type parameters are ignored here. 229 func (o *CiliumHealthAPIAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer { 230 result := make(map[string]runtime.Producer, len(mediaTypes)) 231 for _, mt := range mediaTypes { 232 switch mt { 233 case "application/json": 234 result["application/json"] = o.JSONProducer 235 } 236 237 if p, ok := o.customProducers[mt]; ok { 238 result[mt] = p 239 } 240 } 241 return result 242 } 243 244 // HandlerFor gets a http.Handler for the provided operation method and path 245 func (o *CiliumHealthAPIAPI) HandlerFor(method, path string) (http.Handler, bool) { 246 if o.handlers == nil { 247 return nil, false 248 } 249 um := strings.ToUpper(method) 250 if _, ok := o.handlers[um]; !ok { 251 return nil, false 252 } 253 if path == "/" { 254 path = "" 255 } 256 h, ok := o.handlers[um][path] 257 return h, ok 258 } 259 260 // Context returns the middleware context for the cilium health API API 261 func (o *CiliumHealthAPIAPI) Context() *middleware.Context { 262 if o.context == nil { 263 o.context = middleware.NewRoutableContext(o.spec, o, nil) 264 } 265 266 return o.context 267 } 268 269 func (o *CiliumHealthAPIAPI) initHandlerCache() { 270 o.Context() // don't care about the result, just that the initialization happened 271 if o.handlers == nil { 272 o.handlers = make(map[string]map[string]http.Handler) 273 } 274 275 if o.handlers["GET"] == nil { 276 o.handlers["GET"] = make(map[string]http.Handler) 277 } 278 o.handlers["GET"]["/healthz"] = NewGetHealthz(o.context, o.GetHealthzHandler) 279 if o.handlers["GET"] == nil { 280 o.handlers["GET"] = make(map[string]http.Handler) 281 } 282 o.handlers["GET"]["/status"] = connectivity.NewGetStatus(o.context, o.ConnectivityGetStatusHandler) 283 if o.handlers["PUT"] == nil { 284 o.handlers["PUT"] = make(map[string]http.Handler) 285 } 286 o.handlers["PUT"]["/status/probe"] = connectivity.NewPutStatusProbe(o.context, o.ConnectivityPutStatusProbeHandler) 287 } 288 289 // Serve creates a http handler to serve the API over HTTP 290 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil)) 291 func (o *CiliumHealthAPIAPI) Serve(builder middleware.Builder) http.Handler { 292 o.Init() 293 294 if o.Middleware != nil { 295 return o.Middleware(builder) 296 } 297 if o.useSwaggerUI { 298 return o.context.APIHandlerSwaggerUI(builder) 299 } 300 return o.context.APIHandler(builder) 301 } 302 303 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit 304 func (o *CiliumHealthAPIAPI) Init() { 305 if len(o.handlers) == 0 { 306 o.initHandlerCache() 307 } 308 } 309 310 // RegisterConsumer allows you to add (or override) a consumer for a media type. 311 func (o *CiliumHealthAPIAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) { 312 o.customConsumers[mediaType] = consumer 313 } 314 315 // RegisterProducer allows you to add (or override) a producer for a media type. 316 func (o *CiliumHealthAPIAPI) RegisterProducer(mediaType string, producer runtime.Producer) { 317 o.customProducers[mediaType] = producer 318 } 319 320 // AddMiddlewareFor adds a http middleware to existing handler 321 func (o *CiliumHealthAPIAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) { 322 um := strings.ToUpper(method) 323 if path == "/" { 324 path = "" 325 } 326 o.Init() 327 if h, ok := o.handlers[um][path]; ok { 328 o.handlers[um][path] = builder(h) 329 } 330 }