Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add no_proxy config option, fix setting proxy.url #78

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/local/chart/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chart
import (
"errors"
"fmt"
"strings"

config_v1 "github.com/weka/gohomecli/internal/local/config/v1"
"github.com/weka/gohomecli/internal/utils"
Expand Down Expand Up @@ -193,7 +194,12 @@ func configureCore(configuration *config_v1.Configuration) (yamlMap, error) {
cfg = make(yamlMap)
)

err = writeMapEntryIfSet(cfg, "core.proxy.url", configuration.Proxy)
if configuration.Proxy.URL != "" {
err = errors.Join(
writeMapEntryIfSet(cfg, "core.proxy.url", configuration.Proxy.URL),
writeMapEntryIfSet(cfg, "core.proxy.noProxy", strings.Join(configuration.Proxy.NoProxy, ",")),
)
}

return cfg, err
}
Expand Down
10 changes: 9 additions & 1 deletion internal/local/config/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ type ForwardingConfig struct {
}

type ProxyConfig struct {
URL string `json:"url,omitempty"`
URL string `json:"url,omitempty"`
NoProxy []string `json:"no_proxy,omitempty"`
}

func (p ProxyConfig) NoProxyWithDefaults() []string {
return append([]string{
"127.0.0.0/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16",
"cluster.local", "localhost",
}, p.NoProxy...)
}

// Configuration flat options for the chart, pointers are used to distinguish between empty and unset values
Expand Down
13 changes: 7 additions & 6 deletions internal/local/k3s/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,17 @@ func k3sInstall(ctx context.Context, c Config, fi fs.FileInfo, r io.Reader) erro
return fmt.Errorf("url parse: %w", err)
}

// skip internal IP from proxying
noProxy := append([]string{
fmt.Sprintf("%s/32", c.IP),
fmt.Sprintf("%s/32", c.ifaceAddr),
}, c.Proxy.NoProxyWithDefaults()...)

logger.Info().
Str("proxy", utils.URLSafe(proxyURL).String()).
Strs("no_proxy", noProxy).
Msg("Using proxy")

var noProxy = []string{
"127.0.0.0/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16",
fmt.Sprintf("%s/32", c.IP),
fmt.Sprintf("%s/32", c.ifaceAddr),
}

os.Setenv("NO_PROXY", strings.Join(noProxy, ","))

switch proxyURL.Scheme {
Expand Down
Loading