 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Variables
- func FormatServiceForTemplates(sr *Service)
- func GetBackTemplate(sr *Service) string
- func Glob(pattern, str string) bool
- func IsValidReconf(service *Service) (statusCode int, msg string)
- func NewHaProxy(templatesPath, configsPath string) proxy
- type Data
- type HaProxy
- func (m HaProxy) AddService(service Service)
- func (m HaProxy) CreateConfigFromTemplates() error
- func (m HaProxy) GetCertPaths() []string
- func (m HaProxy) GetCerts() map[string]string
- func (m HaProxy) GetServices() map[string]Service
- func (m HaProxy) ReadConfig() (string, error)
- func (m HaProxy) Reload() error
- func (m HaProxy) RemoveService(service string) bool
- func (m HaProxy) RunCmd(extraArgs []string) error
 
- type Service
- type ServiceDest
- type ServiceParameterProvider
- type Services
- type User
- type UserAgent
Constants ¶
This section is empty.
Variables ¶
var Instance proxy
    Instance is a singleton containing an instance of the proxy
var LookupHost = net.LookupHost
    LookupHost overwrites net.LookupHost so that it can be mocked from other packages
var ReadFile = ioutil.ReadFile
    ReadFile overwrites ioutil.ReadFile so that it can be mocked from other packages
Functions ¶
func FormatServiceForTemplates ¶
func FormatServiceForTemplates(sr *Service)
FormatServiceForTemplates adds addtional variables to service that is used by templates
func GetBackTemplate ¶
GetBackTemplate returns template used to create a service backend TODO: Change to private function when actions.GetTemplates is moved to the proxy package TODO: Create a single string for the template TODO: Unify HTTP and HTTPS into a single string TODO: Move to a file
func IsValidReconf ¶
IsValidReconf validates whether reconfigure data is valid
func NewHaProxy ¶
func NewHaProxy(templatesPath, configsPath string) proxy
NewHaProxy returns an instance of the proxy
Types ¶
type HaProxy ¶
type HaProxy struct {
	// contains filtered or unexported fields
}
    HaProxy contains structure used by HAProxy implementation
func (HaProxy) AddService ¶
AddService puts a service into `dataInstance` map. The key of the map is `ServiceName`
func (HaProxy) CreateConfigFromTemplates ¶
CreateConfigFromTemplates creates haproxy.cfg configuration file based on templates
func (HaProxy) GetCertPaths ¶
GetCertPaths returns the paths of all the certificates
func (HaProxy) GetCerts ¶
GetCerts return all the certificates from the system. Map's key contains the path to a certificate while the value is the certificate content.
func (HaProxy) GetServices ¶
GetServices returns a map with all the services used by the proxy. The key of the map is the name of a service.
func (HaProxy) ReadConfig ¶
ReadConfig returns the current HAProxy configuration
func (HaProxy) RemoveService ¶
RemoveService deletes a service from the `dataInstance` map using `ServiceName` as the key Returns false if there are no services to remove
type Service ¶
type Service struct {
	// ACLs are ordered alphabetically by their names.
	// If not specified, serviceName is used instead.
	AclName string `split_words:"true"`
	// Additional headers that will be added to the request before forwarding it to the service.
	// Please consult https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#add-a-header-to-the-request for more info.
	AddReqHeader []string `split_words:"true"`
	// Additional headers that will be added to the response before forwarding it to the client.
	AddResHeader []string `split_words:"true"`
	// Additional configuration that will be added to the bottom of the service backend
	BackendExtra string `split_words:"true"`
	// Enable resolvers.
	// Provides higher reliability at the cost of backend initialization time.
	// If enabled, it might take a few seconds until a backend is resolved and operational.
	// Resolvers can be customized through the environment variable RESOLVERS.
	CheckResolvers bool `split_words:"true"`
	// Enable HTTP compression.
	// The currently supported algorithms are: identity, gzip, deflate, raw-deflate.
	CompressionAlgo string `split_words:"true"`
	// The type of files that will be compressed.
	CompressionType string `split_words:"true"`
	// One of the five connection modes supported by the HAProxy.
	// `http-keep-alive`: all requests and responses are processed.
	// `http-tunnel`: only the first request and response are processed, everything else is forwarded with no analysis.
	// `httpclose`: tunnel with "Connection: close" added in both directions.
	// `http-server-close`: the server-facing connection is closed after the response.
	// `forceclose`: the connection is actively closed after end of response.
	// In general, it is preferred to use http-server-close with application servers, and some static servers might benefit from http-keep-alive.
	// Connection mode is restricted to HTTP mode only.
	// If specified, connection mode will be applied to the backend section.
	ConnectionMode string `split_words:"true"`
	// Internal use only
	Debug bool
	// Internal use only
	DebugFormat string
	// Additional headers that will be deleted in the request before forwarding it to the service. Please consult https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#delete-a-header-in-the-request for more info.
	DelReqHeader []string `split_words:"true"`
	// Additional headers that will be deleted in the response before forwarding it to the client. Please consult https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#delete-a-header-in-the-response for more info.
	DelResHeader []string `split_words:"true"`
	// The type of service discovery.
	// Currently supported are Overlay (default) and DNS.
	// Overlay discovery relies on Overlay network to perform round-robing load balancing. This is the recommended discovery.
	// DNS discovery detects the replicas using DNS SD.
	DiscoveryType string
	// Whether to distribute a request to all the instances of the proxy.
	// Used only in the swarm mode.
	Distribute bool `split_words:"true"`
	// If set to true, it will be the default_backend service.
	IsDefaultBackend bool `split_words:"true"`
	// When `FILTER_PROXY_INSTANCE_NAME` is set to `true`, only services with
	// ProxyInstanceName equal to `PROXY_INSTANCE_NAME` will be configured by this proxy.
	ProxyInstanceName string `split_words:"true"`
	// Whether to redirect to https when X-Forwarded-Proto is http
	RedirectWhenHttpProto bool `split_words:"true"`
	// Whether to redirect to https unless X-Forwarded-Proto is https
	RedirectUnlessHttpsProto bool `split_words:"true"`
	// The number of replicas of a service.
	// This parameter is used if `DiscoveryType` is set to `DNS`.
	// Non-Global services with 0 replicas will not be added to the HAproxy config.
	// Replicas is set to -1 with services added through ENV variables
	Replicas int `split_words:"true"`
	// TODO: Deprecated since Dec. 2017.
	// A regular expression to apply the modification.
	// If specified, `reqPathSearch` needs to be set as well.
	ReqPathReplace string `split_words:"true"`
	// TODO: Deprecated since Dec. 2017.
	// A regular expression to search the content to be replaced.
	// If specified, `reqPathReplace` needs to be set as well.
	ReqPathSearch string `split_words:"true"`
	// Content of the PEM-encoded certificate to be used by the proxy when serving traffic over SSL.
	ServiceCert string `split_words:"true"`
	// The algorithm that should be applied to domain acl. The default value is `hdr_beg(host)`.
	ServiceDomainAlgo string
	// The name of the service.
	// It must match the name of the Swarm service.
	ServiceName string `split_words:"true"`
	// Determines the type of sticky sessions. If set to `sticky-server`, session cookie will be set by the proxy. Any other value means that sticky sessions are not used and load balancing is performed by Docker's Overlay network. Please open an issue if you'd like support for other types of sticky sessions.
	SessionType string `split_words:"true"`
	// Additional headers that will be set to the request before forwarding it to the service. If a specified header exists, it will be replaced with the new one.
	SetReqHeader []string `split_words:"true"`
	// Additional headers that will be set to the response before forwarding it to the client. If a specified header exists, it will be replaced with the new one.
	SetResHeader []string `split_words:"true"`
	// The path to the template representing a snippet of the backend configuration.
	// If specified, the backend template will be loaded from the specified file.
	// If specified, `templateFePath` must be set as well.
	// See the https://github.com/docker-flow/docker-flow-proxy#templates section for more info.
	TemplateBePath string `split_words:"true"`
	// The path to the template representing a snippet of the frontend configuration.
	// If specified, the frontend template will be loaded from the specified file.
	// If specified, `templateBePath` must be set as well.
	// See the https://github.com/docker-flow/docker-flow-proxy#templates section for more info.
	TemplateFePath string `split_words:"true"`
	// Internal use only.
	UseGlobalUsers bool
	// A comma-separated list of credentials(<user>:<pass>) for HTTP basic auth, which applies only to the service that will be reconfigured.
	Users []User `split_words:"true"`
	// The rest of variables are for internal use only
	ServicePort         string
	AclCondition        string
	IsGlobal            bool
	LookupRetry         int
	LookupRetryInterval int
	ServiceDest         []ServiceDest
	Tasks               []string
}
    Service contains description of a service that should be added to the proxy configuration.
func GetServiceFromMap ¶
GetServiceFromMap returns Service struct by extracting request parameters
func GetServiceFromProvider ¶
func GetServiceFromProvider(provider ServiceParameterProvider) *Service
GetServiceFromProvider returns Service by extracting parameters from ServiceParameterProvider
type ServiceDest ¶
type ServiceDest struct {
	// The list of allowed methods. If specified, a request with a method that is not on the list will be denied.
	AllowedMethods []string
	// HAProxy balance mode for in TCP groups.
	BalanceGroup string
	// Checks tcp connection. Only used in sni or tcp mode.
	CheckTCP bool
	// Enable sending of TCP keepalive packets on the client side. Only used in sni or tcp mode.
	Clitcpka bool
	// The list of denied methods. If specified, a request with a method that is on the list will be denied.
	DeniedMethods []string
	// Whether to deny HTTP requests thus allowing only HTTPS.
	DenyHttp bool
	// Whether to redirect all http requests to https
	HttpsOnly bool
	// The internal HTTPS port of a service that should be reconfigured.
	// The port is used only in the swarm mode.
	// If not specified, the `port` parameter will be used instead.
	HttpsPort int
	// HTTP code for HTTP to HTTPS redirects. This parameter is used only if `httpsOnly` is set to `true`.
	HttpsRedirectCode string
	// Whether to ignore authorization for this service destination.
	IgnoreAuthorization bool
	// The hostname where the service is running, for instance on a separate swarm.
	// If specified, the proxy will dispatch requests to that domain.
	OutboundHostname string
	// The ACL derivative. Defaults to path_beg.
	// See https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#7.3.6-path for more info.
	PathType string
	// The internal port of a service that should be reconfigured.
	// The port is used only in the *swarm* mode.
	Port string
	// If a request is sent to one of the domains in this list, it will be redirected to one of the values of the `ServiceDomain`.
	RedirectFromDomain []string
	// The request mode. The proxy should be able to work with any mode supported by HAProxy.
	// However, actively supported and tested modes are *http*, *tcp*, and *sni*.
	ReqMode string
	// Internal use only. Do not modify.
	ReqModeFormatted string
	// A regular expression to search and replace the content.
	// Search and replace values are separated with comma (`,`).
	// Multiple search/replace combinations can be separated with colon (`:`).
	// This field deprecates `ReqPathSearch` and `ReqPathReplace`.
	ReqPathSearchReplace string
	// The domain of the service.
	// If set, the proxy will allow access only to requests coming to that domain.
	ServiceDomain []string
	// Name of service group used by tcp groups
	ServiceGroup string
	// Headers used to filter requests
	ServiceHeader map[string]string
	// The URL path of the service.
	ServicePath []string
	// The URL path that should be excluded from the rules.
	ServicePathExclude []string
	// The source (entry) port of a service.
	// Useful only when specifying multiple destinations of a single service.
	SrcPort int
	// The source (entry) port of a https service.
	// Useful only when specifying multiple destinations of a single service.
	SrcHttpsPort int
	// Internal use only. Do not modify.
	SrcPortAcl string
	// Internal use only. Do not modify.
	SrcPortAclName string
	// Internal use only. Do not modify.
	SrcHttpsPortAcl string
	// Internal use only. Do not modify.
	SrcHttpsPortAclName string
	// If set to true, server certificates are not verified. This flag should be set for SSL enabled backend services.
	SslVerifyNone bool
	// The server timeout in seconds
	TimeoutServer string
	// The client timeout in seconds
	TimeoutClient string
	// The tunnel timeout in seconds
	TimeoutTunnel string
	// Whether to verify client SSL and deny request when it is invalid
	VerifyClientSsl bool
	// If specified, only requests with the same agent will be forwarded to the backend.
	UserAgent UserAgent
	// User defined value.
	// This value is not used with current template.
	// It is designed as a way to provide additional data that can be used with custom templates.
	UserDef string
	// Internal use only
	Index int
	// Internal use only
	ReqPathSearchReplaceFormatted []string
	// Internal use only
	IncludeSrcPortACL bool
	// Internal use only
	IncludeSrcHttpsPortACL bool
}
    ServiceDest holds data used to generate proxy configuration. It is extracted as a separate struct since a single service can have multiple combinations.
type ServiceParameterProvider ¶
ServiceParameterProvider defines common interface for translating parameters into structs.
type Services ¶
type Services []Service
Services contains the list of services used inside the proxy