Skip to content

Commit

Permalink
johngmyers review: use sprig, fix ipv4 check
Browse files Browse the repository at this point in the history
  • Loading branch information
matkam committed May 29, 2024
1 parent 68be9bd commit 88bfa60
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/ffledgling/pdns-go v0.0.0-20180219074714-524e7daccd99
github.com/go-gandi/go-gandi v0.7.0
github.com/go-logr/logr v1.4.2
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/gophercloud/gophercloud v1.12.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b h1:/vQ+oYKu+JoyaMPDsv5FzwuL2wwWBgBbtj/YLCi4LuA=
Expand Down
14 changes: 7 additions & 7 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"time"
"unicode"

sprig "github.com/go-task/slim-sprig"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -147,12 +148,11 @@ func parseTemplate(fqdnTemplate string) (tmpl *template.Template, err error) {
if fqdnTemplate == "" {
return nil, nil
}
funcs := template.FuncMap{
"trimPrefix": strings.TrimPrefix,
"replaceAll": strings.ReplaceAll,
"isIPv6": isIPv6String,
"isIPv4": isIPv4String,
}

funcs := sprig.HermeticTxtFuncMap()
funcs["isIPv6"] = isIPv6String
funcs["isIPv4"] = isIPv4String

return template.New("endpoint").Funcs(funcs).Parse(fqdnTemplate)
}

Expand Down Expand Up @@ -399,5 +399,5 @@ func isIPv6String(ip string) bool {

func isIPv4String(input string) bool {
netIP := net.ParseIP(input)
return netIP != nil && netIP.To4() != nil
return netIP != nil && netIP.To4() != nil && !strings.Contains(input, ":")
}

0 comments on commit 88bfa60

Please sign in to comment.