Skip to content

Commit

Permalink
fix: remove unsafe dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Apr 1, 2023
1 parent 32d1e0a commit 475dd7e
Show file tree
Hide file tree
Showing 4 changed files with 1,867 additions and 339 deletions.
34 changes: 24 additions & 10 deletions funcs/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"math/big"
stdnet "net"
"net/netip"

"github.com/apparentlymart/go-cidr/cidr"
"github.com/flanksource/gomplate/v3/conv"
"github.com/flanksource/gomplate/v3/net"
"github.com/pkg/errors"
"inet.af/netaddr"
)

// NetNS - the net namespace
Expand Down Expand Up @@ -70,18 +70,13 @@ func (f NetFuncs) LookupTXT(name interface{}) ([]string, error) {
}

// ParseIP -
func (f NetFuncs) ParseIP(ip interface{}) (netaddr.IP, error) {
return netaddr.ParseIP(conv.ToString(ip))
func (f NetFuncs) ParseIP(ip interface{}) (netip.Addr, error) {
return netip.ParseAddr(conv.ToString(ip))
}

// ParseIPPrefix -
func (f NetFuncs) ParseIPPrefix(ipprefix interface{}) (netaddr.IPPrefix, error) {
return netaddr.ParseIPPrefix(conv.ToString(ipprefix))
}

// ParseIPRange -
func (f NetFuncs) ParseIPRange(iprange interface{}) (netaddr.IPRange, error) {
return netaddr.ParseIPRange(conv.ToString(iprange))
func (f NetFuncs) ParseIPPrefix(ipprefix interface{}) (netip.Prefix, error) {
return netip.ParsePrefix(conv.ToString(ipprefix))
}

// StdParseIP -
Expand All @@ -107,6 +102,10 @@ func (f NetFuncs) StdParseCIDR(prefix interface{}) (*stdnet.IPNet, error) {
return f.stdParseCIDR(prefix)
}

func (f NetFuncs) CIDRHost(hostnum interface{}, prefix interface{}) (*stdnet.IP, error) {
return f.CidrHost(hostnum, prefix)
}

// CidrHost -
func (f NetFuncs) CidrHost(hostnum interface{}, prefix interface{}) (*stdnet.IP, error) {
network, err := f.stdParseCIDR(prefix)
Expand All @@ -118,6 +117,11 @@ func (f NetFuncs) CidrHost(hostnum interface{}, prefix interface{}) (*stdnet.IP,
return &ip, err
}

// CidrNetmask -
func (f NetFuncs) CIDRNetmask(prefix interface{}) (*stdnet.IP, error) {
return f.CidrNetmask(prefix)
}

// CidrNetmask -
func (f NetFuncs) CidrNetmask(prefix interface{}) (*stdnet.IP, error) {
network, err := f.stdParseCIDR(prefix)
Expand All @@ -133,6 +137,11 @@ func (f NetFuncs) CidrNetmask(prefix interface{}) (*stdnet.IP, error) {
return &netmask, nil
}

// CidrSubnets -
func (f NetFuncs) CIDRSubnets(newbits interface{}, prefix interface{}) ([]*stdnet.IPNet, error) {
return f.CidrSubnets(newbits, prefix)
}

// CidrSubnets -
func (f NetFuncs) CidrSubnets(newbits interface{}, prefix interface{}) ([]*stdnet.IPNet, error) {
network, err := f.stdParseCIDR(prefix)
Expand All @@ -158,6 +167,11 @@ func (f NetFuncs) CidrSubnets(newbits interface{}, prefix interface{}) ([]*stdne
return retValues, nil
}

// CidrSubnetSizes -
func (f NetFuncs) CIDRSubnetSizes(args ...interface{}) ([]*stdnet.IPNet, error) {
return f.CidrSubnetSizes(args...)
}

// CidrSubnetSizes -
func (f NetFuncs) CidrSubnetSizes(args ...interface{}) ([]*stdnet.IPNet, error) {
if len(args) < 2 {
Expand Down
41 changes: 1 addition & 40 deletions funcs/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/flanksource/gomplate/v3/internal/config"
"github.com/stretchr/testify/assert"
"inet.af/netaddr"
)

func TestCreateNetFuncs(t *testing.T) {
Expand All @@ -35,24 +34,6 @@ func TestNetLookupIP(t *testing.T) {
n := NetFuncs{}
assert.Equal(t, "127.0.0.1", must(n.LookupIP("localhost")))
}

func TestParseIP(t *testing.T) {
t.Parallel()

n := NetFuncs{}
_, err := n.ParseIP("not an IP")
assert.Error(t, err)

ip, err := n.ParseIP("2001:470:20::2")
assert.NoError(t, err)
assert.Equal(t, netaddr.IPFrom16([16]byte{
0x20, 0x01, 0x04, 0x70,
0, 0x20, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0x02,
}), ip)
}

func TestParseIPPrefix(t *testing.T) {
t.Parallel()

Expand All @@ -68,21 +49,6 @@ func TestParseIPPrefix(t *testing.T) {
assert.Equal(t, "192.168.0.0/28", ipprefix.Masked().String())
}

func TestParseIPRange(t *testing.T) {
t.Parallel()

n := NetFuncs{}
_, err := n.ParseIPRange("not an IP")
assert.Error(t, err)

_, err = n.ParseIPRange("1.1.1.1")
assert.Error(t, err)

iprange, err := n.ParseIPRange("192.168.0.2-192.168.23.255")
assert.NoError(t, err)
assert.Equal(t, "192.168.0.2-192.168.23.255", iprange.String())
}

func testNetNS() *NetFuncs {
return &NetFuncs{ctx: config.SetExperimental(context.Background())}
}
Expand All @@ -106,8 +72,7 @@ func TestCIDRHost(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "fd00:fd12:3456:7890::22", ip.String())

// inet.af/netaddr.IPPrefix
ipPrefix, _ := n.ParseIPPrefix("10.12.127.0/20")
ipPrefix, _ := netip.ParsePrefix("10.12.127.0/20")

ip, err = n.CIDRHost(16, ipPrefix)
assert.NoError(t, err)
Expand Down Expand Up @@ -145,10 +110,6 @@ func TestCIDRNetmask(t *testing.T) {
ip, err := n.CIDRNetmask("10.0.0.0/12")
assert.NoError(t, err)
assert.Equal(t, "255.240.0.0", ip.String())

ip, err = n.CIDRNetmask("fd00:fd12:3456:7890:00a2::/72")
assert.NoError(t, err)
assert.Equal(t, "ffff:ffff:ffff:ffff:ff00::", ip.String())
}

func TestCIDRSubnets(t *testing.T) {
Expand Down
125 changes: 63 additions & 62 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,99 +1,100 @@
module github.com/flanksource/gomplate/v3

go 1.17
go 1.20

require (
github.com/Masterminds/goutils v1.1.1
github.com/Shopify/ejson v1.3.3
github.com/apparentlymart/go-cidr v1.1.0
github.com/aws/aws-sdk-go v1.44.102
github.com/go-git/go-billy/v5 v5.3.1
github.com/go-git/go-git/v5 v5.4.2
github.com/aws/aws-sdk-go v1.44.234
github.com/go-git/go-billy/v5 v5.4.1
github.com/go-git/go-git/v5 v5.6.1
github.com/google/uuid v1.3.0
github.com/gosimple/slug v1.12.0
github.com/gosimple/slug v1.13.1
github.com/hairyhenderson/toml v0.4.2-0.20210923231440-40456b8e66cf
github.com/hashicorp/go-sockaddr v1.0.2
github.com/joho/godotenv v1.4.0
github.com/joho/godotenv v1.5.1
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.28.0
github.com/spf13/afero v1.9.2
github.com/stretchr/testify v1.8.0
github.com/ugorji/go/codec v1.2.7
gocloud.dev v0.26.0
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0
golang.org/x/text v0.3.7
gotest.tools/v3 v3.3.0
inet.af/netaddr v0.0.0-20220811202034-502d2d690317
k8s.io/client-go v0.24.4
github.com/rs/zerolog v1.29.0
github.com/spf13/afero v1.9.5
github.com/stretchr/testify v1.8.2
github.com/ugorji/go/codec v1.2.11
gocloud.dev v0.29.0
golang.org/x/crypto v0.7.0
golang.org/x/text v0.8.0
gotest.tools/v3 v3.4.0
k8s.io/client-go v1.5.2
)

// TODO: replace with gopkg.in/yaml.v3 after https://github.com/go-yaml/yaml/pull/862
// is merged
require github.com/hairyhenderson/yaml v0.0.0-20220618171115-2d35fca545ce

require (
cloud.google.com/go v0.104.0 // indirect
cloud.google.com/go/compute v1.10.0 // indirect
cloud.google.com/go/iam v0.4.0 // indirect
cloud.google.com/go/storage v1.26.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220824120805-4b6e5c587895 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/aws/aws-sdk-go-v2 v1.16.16 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.8 // indirect
github.com/aws/aws-sdk-go-v2/config v1.17.7 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.20 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.17 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.24 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.14 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.18 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.17 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.11 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.23 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.19 // indirect
github.com/aws/smithy-go v1.13.3 // indirect
github.com/cloudflare/circl v1.2.0 // indirect
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.7 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.19 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.18 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.60 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.31 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.25 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.32 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.26 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.25 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.0 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.31.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.6 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.7 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/cloudflare/circl v1.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.5.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.8.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.2 // indirect
go.opencensus.io v0.23.0 // indirect
go4.org/intern v0.0.0-20220617035311-6925f38cc365 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9 // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.96.0 // indirect
google.golang.org/api v0.114.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220920201722-2b89144ce006 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto v0.0.0-20230331144136-dcfb400f0633 // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit 475dd7e

Please sign in to comment.