Fix unit tests and comments

Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
z1cheng 2023-06-29 14:11:51 +00:00 committed by k8s-infra-cherrypick-robot
parent 4b6d0c0738
commit 1d8e7f4695
7 changed files with 17 additions and 40 deletions

View file

@ -18,13 +18,14 @@ package template
import (
"bytes"
"crypto/rand"
"crypto/sha1" // #nosec
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"math/rand" // #nosec
"math/big"
"net"
"net/url"
"os"
@ -34,7 +35,6 @@ import (
"strconv"
"strings"
text_template "text/template"
"time"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/util/sets"
@ -1186,16 +1186,16 @@ func buildAuthSignURLLocation(location, authSignURL string) string {
}
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var random *rand.Rand
func init() {
random = rand.New(rand.NewSource(time.Now().UnixNano())) // #nosec
}
func randomString() string {
b := make([]rune, 32)
for i := range b {
b[i] = letters[random.Intn(len(letters))] // #nosec
idx, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
if err != nil {
klog.Errorf("unexpected error generating random index: %v", err)
return ""
}
b[i] = letters[idx.Int64()]
}
return string(b)