File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ require (
6
6
github.com/aws/aws-sdk-go v1.44.271
7
7
github.com/creasty/defaults v1.7.0
8
8
github.com/go-logr/logr v1.2.4
9
- github.com/google/uuid v1.6.0
10
9
github.com/hashicorp/go-multierror v1.1.1
11
10
github.com/joho/godotenv v1.5.1
12
11
github.com/spf13/viper v1.15.0
@@ -38,6 +37,7 @@ require (
38
37
github.com/google/gnostic v0.5.7-v3refs // indirect
39
38
github.com/google/go-cmp v0.5.9 // indirect
40
39
github.com/google/gofuzz v1.1.0 // indirect
40
+ github.com/google/uuid v1.6.0 // indirect
41
41
github.com/hashicorp/errwrap v1.0.0 // indirect
42
42
github.com/hashicorp/hcl v1.0.0 // indirect
43
43
github.com/imdario/mergo v0.3.12 // indirect
Original file line number Diff line number Diff line change 20
20
package cloudfront
21
21
22
22
import (
23
+ "crypto/md5"
23
24
"fmt"
24
25
"strings"
25
26
26
27
awscloudfront "github.com/aws/aws-sdk-go/service/cloudfront"
27
- "github.com/google/uuid"
28
28
)
29
29
30
30
const (
@@ -62,14 +62,19 @@ func oacName(distributionName, s3Host string) string {
62
62
63
63
// generates a short name to avoid AWS limits.
64
64
hostName := strings .Split (distributionName , "." )[0 ]
65
- return fmt .Sprintf ("%s-%s" , hostName , generateShortID ())
65
+ return fmt .Sprintf ("%s-%s" , hostName , generateShortID (distributionName , s3Name ))
66
66
}
67
67
68
68
func oacDescription (originName string ) string {
69
69
return fmt .Sprintf ("OAC for %s, managed by cdn-origin-controller" , originName )
70
70
}
71
71
72
- func generateShortID () string {
73
- id := uuid .New ().String ()
74
- return strings .Split (id , "-" )[0 ]
72
+ func generateShortID (distrName , domainName string ) string {
73
+ md5 := generateMD5 (fmt .Sprintf ("%s-%s" , distrName , domainName ))
74
+ return md5 [:8 ]
75
+ }
76
+
77
+ func generateMD5 (text string ) string {
78
+ data := []byte (text )
79
+ return fmt .Sprintf ("%x" , md5 .Sum (data ))
75
80
}
Original file line number Diff line number Diff line change 20
20
package cloudfront
21
21
22
22
import (
23
- "strings"
24
23
"testing"
25
24
26
25
"github.com/stretchr/testify/suite"
@@ -43,6 +42,6 @@ func (s *OACTestSuite) TestNewOACWithDefaultNamePattern() {
43
42
44
43
func (s * OACTestSuite ) TestNewOACWithShortNamePattern () {
45
44
oac := NewOAC ("wellz-accounts-fe-develop-nv.nv.dev.us.gympass.cloud" , "gympass-develop-nv-wellz-accounts-fe-develop-nv.s3.us-east-1.amazonaws.com" )
46
- s .True ( strings . HasPrefix ( oac . Name , "wellz-accounts-fe-develop-nv-" ) )
45
+ s .Equal ( "wellz-accounts-fe-develop-nv-51d6956b" , oac . Name )
47
46
s .True (len (oac .Name ) <= 63 )
48
47
}
You can’t perform that action at this time.
0 commit comments