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

Display nicely Networks (CIDR) in runtime configuration #6029

Merged
merged 2 commits into from
Jul 23, 2019
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
3 changes: 2 additions & 1 deletion agent/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,6 @@ func cleanRetryJoin(a string) string {
func sanitize(name string, v reflect.Value) reflect.Value {
typ := v.Type()
switch {

// check before isStruct and isPtr
case isNetAddr(typ):
if v.IsNil() {
Expand All @@ -1666,6 +1665,8 @@ func sanitize(name string, v reflect.Value) reflect.Value {
return reflect.ValueOf("unix://" + x.String())
case *net.IPAddr:
return reflect.ValueOf(x.IP.String())
case *net.IPNet:
return reflect.ValueOf(x.String())
default:
return v
}
Expand Down
17 changes: 16 additions & 1 deletion agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5051,6 +5051,14 @@ func TestConfigDecodeBytes(t *testing.T) {
}
}

func parseCIDR(t *testing.T, cidr string) *net.IPNet {
_, x, err := net.ParseCIDR(cidr)
if err != nil {
t.Fatalf("CIDRParse: %v", err)
}
return x
}

func TestSanitize(t *testing.T) {
rt := RuntimeConfig{
BindAddr: &net.IPAddr{IP: net.ParseIP("127.0.0.1")},
Expand All @@ -5061,6 +5069,10 @@ func TestSanitize(t *testing.T) {
&net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 5678},
},
DNSSOA: RuntimeSOAConfig{Refresh: 3600, Retry: 600, Expire: 86400, Minttl: 0},
AllowWriteHTTPFrom: []*net.IPNet{
parseCIDR(t, "127.0.0.0/8"),
parseCIDR(t, "::1/128"),
},
HTTPAddrs: []net.Addr{
&net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 5678},
&net.UnixAddr{Name: "/var/run/foo"},
Expand Down Expand Up @@ -5395,7 +5407,10 @@ func TestSanitize(t *testing.T) {
"Version": "",
"VersionPrerelease": "",
"Watches": [],
"AllowWriteHTTPFrom": []
"AllowWriteHTTPFrom": [
"127.0.0.0/8",
"::1/128"
]
}`
b, err := json.MarshalIndent(rt.Sanitized(), "", " ")
if err != nil {
Expand Down