Skip to content

Commit

Permalink
Generate random namespace id
Browse files Browse the repository at this point in the history
  • Loading branch information
domtes-form3 committed Feb 29, 2024
1 parent 6213128 commit 0148dd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions mimirtool/common.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package mimirtool

import (
"crypto/sha256"
"encoding/hex"
"math/rand"
)

func hash(s string) string {
sha := sha256.Sum256([]byte(s))
return hex.EncodeToString(sha[:])
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

func randStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}

func stringValueMap(src map[string]interface{}) map[string]string {
Expand Down
2 changes: 1 addition & 1 deletion mimirtool/resource_ruler_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func rulerNamespaceCreate(ctx context.Context, d *schema.ResourceData, meta any)
}
}

d.SetId(hash(namespace))
d.SetId(randStringBytes(64))
return rulerNamespaceRead(ctx, d, meta)
}

Expand Down

0 comments on commit 0148dd5

Please sign in to comment.