github.com/cilium/cilium@v1.16.2/api/v1/client/cilium_api_client.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 client 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 "github.com/go-openapi/runtime" 13 httptransport "github.com/go-openapi/runtime/client" 14 "github.com/go-openapi/strfmt" 15 16 "github.com/cilium/cilium/api/v1/client/bgp" 17 "github.com/cilium/cilium/api/v1/client/daemon" 18 "github.com/cilium/cilium/api/v1/client/endpoint" 19 "github.com/cilium/cilium/api/v1/client/ipam" 20 "github.com/cilium/cilium/api/v1/client/metrics" 21 "github.com/cilium/cilium/api/v1/client/policy" 22 "github.com/cilium/cilium/api/v1/client/prefilter" 23 "github.com/cilium/cilium/api/v1/client/recorder" 24 "github.com/cilium/cilium/api/v1/client/service" 25 ) 26 27 // Default cilium API HTTP client. 28 var Default = NewHTTPClient(nil) 29 30 const ( 31 // DefaultHost is the default Host 32 // found in Meta (info) section of spec file 33 DefaultHost string = "localhost" 34 // DefaultBasePath is the default BasePath 35 // found in Meta (info) section of spec file 36 DefaultBasePath string = "/v1" 37 ) 38 39 // DefaultSchemes are the default schemes found in Meta (info) section of spec file 40 var DefaultSchemes = []string{"http"} 41 42 // NewHTTPClient creates a new cilium API HTTP client. 43 func NewHTTPClient(formats strfmt.Registry) *CiliumAPI { 44 return NewHTTPClientWithConfig(formats, nil) 45 } 46 47 // NewHTTPClientWithConfig creates a new cilium API HTTP client, 48 // using a customizable transport config. 49 func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *CiliumAPI { 50 // ensure nullable parameters have default 51 if cfg == nil { 52 cfg = DefaultTransportConfig() 53 } 54 55 // create transport and client 56 transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes) 57 return New(transport, formats) 58 } 59 60 // New creates a new cilium API client 61 func New(transport runtime.ClientTransport, formats strfmt.Registry) *CiliumAPI { 62 // ensure nullable parameters have default 63 if formats == nil { 64 formats = strfmt.Default 65 } 66 67 cli := new(CiliumAPI) 68 cli.Transport = transport 69 cli.Bgp = bgp.New(transport, formats) 70 cli.Daemon = daemon.New(transport, formats) 71 cli.Endpoint = endpoint.New(transport, formats) 72 cli.Ipam = ipam.New(transport, formats) 73 cli.Metrics = metrics.New(transport, formats) 74 cli.Policy = policy.New(transport, formats) 75 cli.Prefilter = prefilter.New(transport, formats) 76 cli.Recorder = recorder.New(transport, formats) 77 cli.Service = service.New(transport, formats) 78 return cli 79 } 80 81 // DefaultTransportConfig creates a TransportConfig with the 82 // default settings taken from the meta section of the spec file. 83 func DefaultTransportConfig() *TransportConfig { 84 return &TransportConfig{ 85 Host: DefaultHost, 86 BasePath: DefaultBasePath, 87 Schemes: DefaultSchemes, 88 } 89 } 90 91 // TransportConfig contains the transport related info, 92 // found in the meta section of the spec file. 93 type TransportConfig struct { 94 Host string 95 BasePath string 96 Schemes []string 97 } 98 99 // WithHost overrides the default host, 100 // provided by the meta section of the spec file. 101 func (cfg *TransportConfig) WithHost(host string) *TransportConfig { 102 cfg.Host = host 103 return cfg 104 } 105 106 // WithBasePath overrides the default basePath, 107 // provided by the meta section of the spec file. 108 func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig { 109 cfg.BasePath = basePath 110 return cfg 111 } 112 113 // WithSchemes overrides the default schemes, 114 // provided by the meta section of the spec file. 115 func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig { 116 cfg.Schemes = schemes 117 return cfg 118 } 119 120 // CiliumAPI is a client for cilium API 121 type CiliumAPI struct { 122 Bgp bgp.ClientService 123 124 Daemon daemon.ClientService 125 126 Endpoint endpoint.ClientService 127 128 Ipam ipam.ClientService 129 130 Metrics metrics.ClientService 131 132 Policy policy.ClientService 133 134 Prefilter prefilter.ClientService 135 136 Recorder recorder.ClientService 137 138 Service service.ClientService 139 140 Transport runtime.ClientTransport 141 } 142 143 // SetTransport changes the transport on the client and all its subresources 144 func (c *CiliumAPI) SetTransport(transport runtime.ClientTransport) { 145 c.Transport = transport 146 c.Bgp.SetTransport(transport) 147 c.Daemon.SetTransport(transport) 148 c.Endpoint.SetTransport(transport) 149 c.Ipam.SetTransport(transport) 150 c.Metrics.SetTransport(transport) 151 c.Policy.SetTransport(transport) 152 c.Prefilter.SetTransport(transport) 153 c.Recorder.SetTransport(transport) 154 c.Service.SetTransport(transport) 155 }