Skip to content

Commit

Permalink
fix: add no_proxy config option, fix setting proxy.url (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdand-weka authored Mar 29, 2024
1 parent 9f2c731 commit 7fbcb26
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
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

0 comments on commit 7fbcb26

Please sign in to comment.