Skip to content

Commit d5c4d1e

Browse files
authored
Remove dead code from cloud.go (#449)
1 parent fff90c1 commit d5c4d1e

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

task/common/cloud.go

-35
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
package common
22

33
import (
4-
"bytes"
54
"errors"
6-
"fmt"
7-
"regexp"
8-
"strings"
95
"time"
10-
11-
"crypto/sha256"
12-
13-
"github.com/aohorodnyk/uid"
146
)
157

168
type Cloud struct {
@@ -46,30 +38,3 @@ func (c *Cloud) GetClosestRegion(regions map[string]Region) (string, error) {
4638

4739
return "", errors.New("native region not found")
4840
}
49-
50-
// NormalizeIdentifier normalizes user-provided identifiers by adapting them to
51-
// the most strict cloud provider naming requisites.
52-
func NormalizeIdentifier(identifier string, long bool) string {
53-
lowercase := strings.ToLower(identifier)
54-
normalized := regexp.MustCompile("[^a-z0-9]+").ReplaceAllString(lowercase, "-")
55-
normalized = regexp.MustCompile("(^-)|(-$)").ReplaceAllString(normalized, "")
56-
if len(normalized) > 50 {
57-
normalized = normalized[:50]
58-
}
59-
if long {
60-
return fmt.Sprintf("tpi-%s-%s", normalized, generateSuffix(identifier, 8))
61-
}
62-
return generateSuffix(identifier, 8)
63-
}
64-
65-
// generateSuffix deterministically generates a Base36 suffix of `size`
66-
// characters using `identifier` as the seed. This is useful to enhance
67-
// user-provided identifiers so they become valid "globally unique names" for
68-
// AWS S3, Google Storage and other services that require them.
69-
func generateSuffix(identifier string, size uint32) string {
70-
digest := sha256.Sum256([]byte(identifier))
71-
random := uid.NewRandCustom(bytes.NewReader(digest[:]))
72-
encoder := uid.NewEncoderBase36()
73-
provider := uid.NewProviderCustom(size, random, encoder)
74-
return provider.MustGenerate().String()
75-
}

0 commit comments

Comments
 (0)