config.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * mod_config.go - config file definitions
  16. *
  17. * @author Yaroslav Pogrebnyak <yyyaroslav@gmail.com>
  18. * @author Gene Ponomarenko <kikomdev@gmail.com>
  19. */
  20. package gobetween
  21. /**
  22. * Config file top-level object
  23. */
  24. type Config struct {
  25. Logging LoggingConfig `toml:"logging" json:"logging"`
  26. Api ApiConfig `toml:"api" json:"api"`
  27. Defaults ConnectionOptions `toml:"defaults" json:"defaults"`
  28. Acme *AcmeConfig `toml:"acme" json:"acme"`
  29. Servers map[string]Server `toml:"servers" json:"servers"`
  30. }
  31. /**
  32. * Logging config section
  33. */
  34. type LoggingConfig struct {
  35. Level string `toml:"level" json:"level"`
  36. Output string `toml:"output" json:"output"`
  37. }
  38. /**
  39. * Api config section
  40. */
  41. type ApiConfig struct {
  42. Enabled bool `toml:"enabled" json:"enabled"`
  43. Bind string `toml:"bind" json:"bind"`
  44. BasicAuth *ApiBasicAuthConfig `toml:"basic_auth" json:"basic_auth"`
  45. Tls *ApiTlsConfig `toml:"tls" json:"tls"`
  46. Cors bool `toml:"cors" json:"cors"`
  47. }
  48. /**
  49. * Api Basic Auth Config
  50. */
  51. type ApiBasicAuthConfig struct {
  52. Login string `toml:"login" json:"login"`
  53. Password string `toml:"password" json:"password"`
  54. }
  55. /**
  56. * Api TLS server Config
  57. */
  58. type ApiTlsConfig struct {
  59. CertPath string `toml:"cert_path" json:"cert_path"`
  60. KeyPath string `toml:"key_path" json:"key_path"`
  61. }
  62. /**
  63. * Default values can be overridden in server
  64. */
  65. type ConnectionOptions struct {
  66. MaxConnections *int `toml:"max_connections" json:"max_connections"`
  67. ClientIdleTimeout *string `toml:"client_idle_timeout" json:"client_idle_timeout"`
  68. BackendIdleTimeout *string `toml:"backend_idle_timeout" json:"backend_idle_timeout"`
  69. BackendConnectionTimeout *string `toml:"backend_connection_timeout" json:"backend_connection_timeout"`
  70. }
  71. /**
  72. * Acme config
  73. */
  74. type AcmeConfig struct {
  75. Challenge string `toml:"challenge" json:"challenge"`
  76. HttpBind string `toml:"http_bind" json:"http_bind"`
  77. CacheDir string `toml:"cache_dir" json:"cache_dir"`
  78. }
  79. /**
  80. * Server section config
  81. */
  82. type Server struct {
  83. ConnectionOptions
  84. // hostname:port
  85. Bind string `toml:"bind" json:"bind"`
  86. // tcp | udp | tls
  87. Protocol string `toml:"protocol" json:"protocol"`
  88. // weight | leastconn | roundrobin
  89. Balance string `toml:"balance" json:"balance"`
  90. // Optional configuration for server name indication
  91. Sni *Sni `toml:"sni" json:"sni"`
  92. // Optional configuration for protocol = tls
  93. Tls *Tls `toml:"tls" json:"tls"`
  94. // Optional configuration for backend_tls_enabled = true
  95. BackendsTls *BackendsTls `toml:"backends_tls" json:"backends_tls"`
  96. // Optional configuration for protocol = udp
  97. Udp *Udp `toml:"udp" json:"udp"`
  98. // Access configuration
  99. Access *AccessConfig `toml:"access" json:"access"`
  100. // ProxyProtocol configuration
  101. ProxyProtocol *ProxyProtocol `toml:"proxy_protocol" json:"proxy_protocol"`
  102. // Discovery configuration
  103. Discovery *DiscoveryConfig `toml:"discovery" json:"discovery"`
  104. // Healthcheck configuration
  105. Healthcheck *HealthcheckConfig `toml:"healthcheck" json:"healthcheck"`
  106. }
  107. /**
  108. * ProxyProtocol configurtion
  109. */
  110. type ProxyProtocol struct {
  111. Version string `toml:"version" json:"version"`
  112. }
  113. /**
  114. * Server Sni options
  115. */
  116. type Sni struct {
  117. HostnameMatchingStrategy string `toml:"hostname_matching_strategy" json:"hostname_matching_strategy"`
  118. UnexpectedHostnameStrategy string `toml:"unexpected_hostname_strategy" json:"unexpected_hostname_strategy"`
  119. ReadTimeout string `toml:"read_timeout" json:"read_timeout"`
  120. }
  121. /**
  122. * Common part of Tls and BackendTls types
  123. */
  124. type tlsCommon struct {
  125. Ciphers []string `toml:"ciphers" json:"ciphers"`
  126. PreferServerCiphers bool `toml:"prefer_server_ciphers" json:"prefer_server_ciphers"`
  127. MinVersion string `toml:"min_version" json:"min_version"`
  128. MaxVersion string `toml:"max_version" json:"max_version"`
  129. SessionTickets bool `toml:"session_tickets" json:"session_tickets"`
  130. }
  131. /**
  132. * Server Tls options
  133. * for protocol = "tls"
  134. */
  135. type Tls struct {
  136. AcmeHosts []string `toml:"acme_hosts" json:"acme_hosts"`
  137. CertPath string `toml:"cert_path" json:"cert_path"`
  138. KeyPath string `toml:"key_path" json:"key_path"`
  139. tlsCommon
  140. }
  141. type BackendsTls struct {
  142. IgnoreVerify bool `toml:"ignore_verify" json:"ignore_verify"`
  143. RootCaCertPath *string `toml:"root_ca_cert_path" json:"root_ca_cert_path"`
  144. CertPath *string `toml:"cert_path" json:"cert_path"`
  145. KeyPath *string `toml:"key_path" json:"key_path"`
  146. tlsCommon
  147. }
  148. /**
  149. * Server udp options
  150. * for protocol = "udp"
  151. */
  152. type Udp struct {
  153. MaxRequests uint64 `toml:"max_requests" json:"max_requests"`
  154. MaxResponses uint64 `toml:"max_responses" json:"max_responses"`
  155. }
  156. /**
  157. * Access configuration
  158. */
  159. type AccessConfig struct {
  160. Default string `toml:"default" json:"default"`
  161. Rules []string `toml:"rules" json:"rules"`
  162. }
  163. /**
  164. * Discovery configuration
  165. */
  166. type DiscoveryConfig struct {
  167. Kind string `toml:"kind" json:"kind"`
  168. Failpolicy string `toml:"failpolicy" json:"failpolicy"`
  169. Interval string `toml:"interval" json:"interval"`
  170. Timeout string `toml:"timeout" json:"timeout"`
  171. /* Depends on Kind */
  172. *StaticDiscoveryConfig
  173. *SrvDiscoveryConfig
  174. *DockerDiscoveryConfig
  175. *JsonDiscoveryConfig
  176. *ExecDiscoveryConfig
  177. *PlaintextDiscoveryConfig
  178. *ConsulDiscoveryConfig
  179. *LXDDiscoveryConfig
  180. }
  181. type StaticDiscoveryConfig struct {
  182. StaticList []string `toml:"static_list" json:"static_list"`
  183. }
  184. type SrvDiscoveryConfig struct {
  185. SrvLookupServer string `toml:"srv_lookup_server" json:"srv_lookup_server"`
  186. SrvLookupPattern string `toml:"srv_lookup_pattern" json:"srv_lookup_pattern"`
  187. SrvDnsProtocol string `toml:"srv_dns_protocol" json:"srv_dns_protocol"`
  188. }
  189. type ExecDiscoveryConfig struct {
  190. ExecCommand []string `toml:"exec_command" json:"exec_command"`
  191. }
  192. type JsonDiscoveryConfig struct {
  193. JsonEndpoint string `toml:"json_endpoint" json:"json_endpoint"`
  194. JsonHostPattern string `toml:"json_host_pattern" json:"json_host_pattern"`
  195. JsonPortPattern string `toml:"json_port_pattern" json:"json_port_pattern"`
  196. JsonWeightPattern string `toml:"json_weight_pattern" json:"json_weight_pattern"`
  197. JsonPriorityPattern string `toml:"json_priority_pattern" json:"json_priority_pattern"`
  198. JsonSniPattern string `toml:"json_sni_pattern" json:"json_sni_pattern"`
  199. }
  200. type PlaintextDiscoveryConfig struct {
  201. PlaintextEndpoint string `toml:"plaintext_endpoint" json:"plaintext_endpoint"`
  202. PlaintextRegexpPattern string `toml:"plaintext_regex_pattern" json:"plaintext_regex_pattern"`
  203. }
  204. type DockerDiscoveryConfig struct {
  205. DockerEndpoint string `toml:"docker_endpoint" json:"docker_endpoint"`
  206. DockerContainerLabel string `toml:"docker_container_label" json:"docker_container_label"`
  207. DockerContainerPrivatePort int64 `toml:"docker_container_private_port" json:"docker_container_private_port"`
  208. DockerContainerHostEnvVar string `toml:"docker_container_host_env_var" json:"docker_container_host_env_var"`
  209. DockerTlsEnabled bool `toml:"docker_tls_enabled" json:"docker_tls_enabled"`
  210. DockerTlsCertPath string `toml:"docker_tls_cert_path" json:"docker_tls_cert_path"`
  211. DockerTlsKeyPath string `toml:"docker_tls_key_path" json:"docker_tls_key_path"`
  212. DockerTlsCacertPath string `toml:"docker_tls_cacert_path" json:"docker_tls_cacert_path"`
  213. }
  214. type ConsulDiscoveryConfig struct {
  215. ConsulHost string `toml:"consul_host" json:"consul_host"`
  216. ConsulServiceName string `toml:"consul_service_name" json:"consul_service_name"`
  217. ConsulServiceTag string `toml:"consul_service_tag" json:"consul_service_tag"`
  218. ConsulServicePassingOnly bool `toml:"consul_service_passing_only" json:"consul_service_passing_only"`
  219. ConsulDatacenter string `toml:"consul_datacenter" json:"consul_datacenter"`
  220. ConsulAuthUsername string `toml:"consul_auth_username" json:"consul_auth_username"`
  221. ConsulAuthPassword string `toml:"consul_auth_password" json:"consul_auth_password"`
  222. ConsulTlsEnabled bool `toml:"consul_tls_enabled" json:"consul_tls_enabled"`
  223. ConsulTlsCertPath string `toml:"consul_tls_cert_path" json:"consul_tls_cert_path"`
  224. ConsulTlsKeyPath string `toml:"consul_tls_key_path" json:"consul_tls_key_path"`
  225. ConsulTlsCacertPath string `toml:"consul_tls_cacert_path" json:"consul_tls_cacert_path"`
  226. }
  227. type LXDDiscoveryConfig struct {
  228. LXDServerAddress string `toml:"lxd_server_address" json:"lxd_server_address"`
  229. LXDServerRemoteName string `toml:"lxd_server_remote_name" json:"lxd_server_remote_name"`
  230. LXDServerRemotePassword string `toml:"lxd_server_remote_password" json:"lxd_server_remote_password"`
  231. LXDConfigDirectory string `toml:"lxd_config_directory" json:"lxd_config_directory"`
  232. LXDGenerateClientCerts bool `toml:"lxd_generate_client_certs" json:"lxd_generate_client_certs"`
  233. LXDAcceptServerCert bool `toml:"lxd_accept_server_cert" json:"lxd_accept_server_cert"`
  234. LXDContainerLabelKey string `toml:"lxd_container_label_key" json:"lxd_container_label_key"`
  235. LXDContainerLabelValue string `toml:"lxd_container_label_value" json:"lxd_container_label_value"`
  236. LXDContainerPort int `toml:"lxd_container_port" json:"lxd_container_port"`
  237. LXDContainerPortKey string `toml:"lxd_container_port_key" json:"lxd_container_port_key"`
  238. LXDContainerInterface string `toml:"lxd_container_interface" json:"lxd_container_interface"`
  239. LXDContainerInterfaceKey string `toml:"lxd_container_interface_key" json:"lxd_container_interface_key"`
  240. LXDContainerSNIKey string `toml:"lxd_container_sni_key" json:"lxd_container_sni_key"`
  241. LXDContainerAddressType string `toml:"lxd_container_address_type" json:"lxd_container_address_type"`
  242. }
  243. /**
  244. * Healthcheck configuration
  245. */
  246. type HealthcheckConfig struct {
  247. Kind string `toml:"kind" json:"kind"`
  248. Interval string `toml:"interval" json:"interval"`
  249. Passes int `toml:"passes" json:"passes"`
  250. Fails int `toml:"fails" json:"fails"`
  251. Timeout string `toml:"timeout" json:"timeout"`
  252. /* Depends on Kind */
  253. *PingHealthcheckConfig
  254. *ExecHealthcheckConfig
  255. *UdpHealthcheckConfig
  256. }
  257. type PingHealthcheckConfig struct{}
  258. type ExecHealthcheckConfig struct {
  259. ExecCommand string `toml:"exec_command" json:"exec_command,omitempty"`
  260. ExecExpectedPositiveOutput string `toml:"exec_expected_positive_output" json:"exec_expected_positive_output"`
  261. ExecExpectedNegativeOutput string `toml:"exec_expected_negative_output" json:"exec_expected_negative_output"`
  262. }
  263. type UdpHealthcheckConfig struct {
  264. Receive string
  265. Send string
  266. }