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