Update to use sha224 and base62 text.

This commit is contained in:
Norihiro Seto 2023-07-09 21:52:17 +09:00
parent 969bd8f0b5
commit 00a0deb8e6
No known key found for this signature in database
GPG Key ID: 67E147406EF9333C
2 changed files with 7 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import (
"encoding/json"
"fmt"
"io"
"math/big"
"os"
"os/user"
"path/filepath"
@ -173,7 +174,11 @@ func cacheFilePath(kopsStateStore string, clusterName string) string {
b.WriteString(clusterName)
b.WriteByte(0)
hash := fmt.Sprintf("%x", sha256.Sum256(b.Bytes()))
var i big.Int
hb := sha256.Sum224(b.Bytes())
i.SetBytes(hb[:])
hash := i.Text(62)
return filepath.Join(homedir.HomeDir(), ".kube", "cache", "kops-authentication", hash)
}

View File

@ -38,7 +38,7 @@ func Test_cacheFilePath(t *testing.T) {
output1 := cacheFilePath(inputs[0].kopsStateStore, inputs[0].clusterName)
_, file := path.Split(output1)
if len(file) > 64 {
if len(file) > 38 {
t.Errorf("cacheFilePath() got %v, too long(%v)", output1, len(file))
}
}