File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ require (
66 github.com/aws/aws-sdk-go v1.44.271
77 github.com/creasty/defaults v1.7.0
88 github.com/go-logr/logr v1.2.4
9- github.com/google/uuid v1.6.0
109 github.com/hashicorp/go-multierror v1.1.1
1110 github.com/joho/godotenv v1.5.1
1211 github.com/spf13/viper v1.15.0
@@ -38,6 +37,7 @@ require (
3837 github.com/google/gnostic v0.5.7-v3refs // indirect
3938 github.com/google/go-cmp v0.5.9 // indirect
4039 github.com/google/gofuzz v1.1.0 // indirect
40+ github.com/google/uuid v1.6.0 // indirect
4141 github.com/hashicorp/errwrap v1.0.0 // indirect
4242 github.com/hashicorp/hcl v1.0.0 // indirect
4343 github.com/imdario/mergo v0.3.12 // indirect
Original file line number Diff line number Diff line change 2020package cloudfront
2121
2222import (
23+ "crypto/md5"
2324 "fmt"
2425 "strings"
2526
2627 awscloudfront "github.com/aws/aws-sdk-go/service/cloudfront"
27- "github.com/google/uuid"
2828)
2929
3030const (
@@ -62,14 +62,19 @@ func oacName(distributionName, s3Host string) string {
6262
6363 // generates a short name to avoid AWS limits.
6464 hostName := strings .Split (distributionName , "." )[0 ]
65- return fmt .Sprintf ("%s-%s" , hostName , generateShortID ())
65+ return fmt .Sprintf ("%s-%s" , hostName , generateShortID (distributionName , s3Name ))
6666}
6767
6868func oacDescription (originName string ) string {
6969 return fmt .Sprintf ("OAC for %s, managed by cdn-origin-controller" , originName )
7070}
7171
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 ))
7580}
Original file line number Diff line number Diff line change 2020package cloudfront
2121
2222import (
23- "strings"
2423 "testing"
2524
2625 "github.com/stretchr/testify/suite"
@@ -43,6 +42,6 @@ func (s *OACTestSuite) TestNewOACWithDefaultNamePattern() {
4342
4443func (s * OACTestSuite ) TestNewOACWithShortNamePattern () {
4544 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 )
4746 s .True (len (oac .Name ) <= 63 )
4847}
You can’t perform that action at this time.
0 commit comments