From 03a1e20fde158035cddc32f050a191b40788b9e2 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sun, 7 Jan 2018 12:07:33 -0300 Subject: [PATCH] Remove package to generate UUIDs --- .../ingress/controller/template/template.go | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index fe72dd6ee..76755df9c 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -17,6 +17,7 @@ limitations under the License. package template import ( + "crypto/rand" "encoding/base64" "encoding/json" "fmt" @@ -31,8 +32,6 @@ import ( "github.com/golang/glog" "github.com/pkg/errors" - "github.com/pborman/uuid" - extensions "k8s.io/api/extensions/v1beta1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/ingress-nginx/internal/file" @@ -494,7 +493,12 @@ func buildDenyVariable(a interface{}) string { } if _, ok := denyPathSlugMap[l]; !ok { - denyPathSlugMap[l] = buildRandomUUID() + s, err := randomString() + if err != nil { + return "" + } + + denyPathSlugMap[l] = s } return fmt.Sprintf("$deny_%v", denyPathSlugMap[l]) @@ -573,12 +577,6 @@ func buildNextUpstream(i, r interface{}) string { return strings.Join(nextUpstreamCodes, " ") } -// buildRandomUUID return a random string to be used in the template -func buildRandomUUID() string { - s := uuid.New() - return strings.Replace(s, "-", "", -1) -} - func isValidClientBodyBufferSize(input interface{}) bool { s, ok := input.(string) if !ok { @@ -694,3 +692,13 @@ func buildAuthSignURL(input interface{}) string { return fmt.Sprintf("%v&rd=$pass_access_scheme://$http_host$request_uri", s) } + +func randomString() (string, error) { + b := make([]byte, 16) + _, err := rand.Read(b) + if err != nil { + return "", err + } + + return string(b), nil +}