Skip to content

Commit

Permalink
add constants to set defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidapaulopt committed Dec 11, 2024
1 parent 641a371 commit 7ccf0d1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
15 changes: 8 additions & 7 deletions internal/proxyconfig/proxyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ const (

// Default values to proxyconfig
//
ProxyAccessLog = true
ProxyProvider = ""
DefaultProxyAccessLog = true
DefaultProxyProvider = ""
DefaultTLSValidate = true

// tailscale defaults
TailscaleEphemeral = true
TailscaleRunWebClient = false
TailscaleVerbose = false
TailscaleFunnel = false
TailscaleControlURL = ""
DefaultTailscaleEphemeral = true
DefaultTailscaleRunWebClient = false
DefaultTailscaleVerbose = false
DefaultTailscaleFunnel = false
DefaultTailscaleControlURL = ""
)
2 changes: 1 addition & 1 deletion internal/proxyproviders/tailscale/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *Client) NewProxy(config *proxyconfig.Config) (proxyproviders.Proxy, err
// getControlURL method returns the control URL
func (c *Client) getControlURL(cfg *proxyconfig.Config) string {
if cfg.Tailscale.ControlURL == "" {
return proxyconfig.TailscaleControlURL
return proxyconfig.DefaultTailscaleControlURL
}
return cfg.Tailscale.ControlURL
}
23 changes: 14 additions & 9 deletions internal/targetproviders/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const (
LabelAutoDetect = LabelPrefix + "autodetect"
LabelScheme = LabelPrefix + "scheme"
LabelTLSValidate = LabelPrefix + "tlsvalidate"

// docker only defaults
DefaultAutoDetect = true
DefaultScheme = "http"

//
dialTimeout = 2 * time.Second
autoDetectTries = 5
Expand Down Expand Up @@ -71,8 +76,8 @@ func newContainer(logger zerolog.Logger, dcontainer types.ContainerJSON, imageIn
targetProviderName: targetproviderName,
}

c.autodetect = c.getLabelBool(LabelAutoDetect, true)
c.scheme = c.getLabelString(LabelScheme, "http")
c.autodetect = c.getLabelBool(LabelAutoDetect, DefaultAutoDetect)
c.scheme = c.getLabelString(LabelScheme, DefaultScheme)

return c
}
Expand Down Expand Up @@ -105,9 +110,9 @@ func (c *container) newProxyConfig() (*proxyconfig.Config, error) {
Hostname: proxyURL.Hostname(),
TargetProvider: c.targetProviderName,
Tailscale: tailscale,
ProxyProvider: c.getLabelString(LabelProxyProvider, proxyconfig.ProxyProvider),
ProxyAccessLog: c.getLabelBool(LabelContainerAccessLog, proxyconfig.ProxyAccessLog),
TLSValidate: c.getLabelBool(LabelTLSValidate, true),
ProxyProvider: c.getLabelString(LabelProxyProvider, proxyconfig.DefaultProxyProvider),
ProxyAccessLog: c.getLabelBool(LabelContainerAccessLog, proxyconfig.DefaultProxyAccessLog),
TLSValidate: c.getLabelBool(LabelTLSValidate, proxyconfig.DefaultTLSValidate),
}, nil
}

Expand All @@ -121,10 +126,10 @@ func (c *container) getTailscaleConfig() (*proxyconfig.Tailscale, error) {
}

return &proxyconfig.Tailscale{
Ephemeral: c.getLabelBool(LabelEphemeral, proxyconfig.TailscaleEphemeral),
RunWebClient: c.getLabelBool(LabelRunWebClient, proxyconfig.TailscaleRunWebClient),
Verbose: c.getLabelBool(LabelTsnetVerbose, proxyconfig.TailscaleVerbose),
Funnel: c.getLabelBool(LabelFunnel, proxyconfig.TailscaleFunnel),
Ephemeral: c.getLabelBool(LabelEphemeral, proxyconfig.DefaultTailscaleEphemeral),
RunWebClient: c.getLabelBool(LabelRunWebClient, proxyconfig.DefaultTailscaleRunWebClient),
Verbose: c.getLabelBool(LabelTsnetVerbose, proxyconfig.DefaultTailscaleVerbose),
Funnel: c.getLabelBool(LabelFunnel, proxyconfig.DefaultTailscaleFunnel),
AuthKey: authKey,
// TODO: add controlURL
// ControlURL: c.,
Expand Down
2 changes: 1 addition & 1 deletion internal/targetproviders/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (c *Client) newProxyConfig(name string, p proxyConfig) (*proxyconfig.Config
proxyProvider = p.ProxyProvider
}

proxyAccessLog := proxyconfig.ProxyAccessLog
proxyAccessLog := proxyconfig.DefaultProxyAccessLog

pcfg := &proxyconfig.Config{
TargetID: name,
Expand Down

0 comments on commit 7ccf0d1

Please sign in to comment.