Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from ibuildthecloud/main
Browse files Browse the repository at this point in the history
Add SafeHashConcatName
  • Loading branch information
ibuildthecloud committed Apr 10, 2023
2 parents d0e1bdc + 4402b17 commit f08516a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/name/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ func SafeConcatNameWithSeparatorAndLength(length int, sep string, name ...string
func SafeConcatName(name ...string) string {
return SafeConcatNameWithSeparatorAndLength(64, "-", name...)
}

func SafeHashConcatName(name ...string) string {
d := sha256.New()
for _, part := range name {
d.Write([]byte(part))
d.Write([]byte{'\x00'})
}
hash := d.Sum(nil)
suffix := hex.EncodeToString(hash[:])[:8]
return SafeConcatName(append(name, suffix)...)
}

0 comments on commit f08516a

Please sign in to comment.