Skip to content

Commit

Permalink
eksconfig: update random strings
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed Feb 12, 2020
1 parent 5d5b9aa commit 17ece43
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
14 changes: 1 addition & 13 deletions eksconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -731,7 +730,7 @@ func NewDefault() *Config {
int(now.Month()),
now.Day(),
now.Hour(),
randString(10),
randString(12),
)

// ref. https://docs.aws.amazon.com/eks/latest/userguide/create-managed-node-group.html
Expand Down Expand Up @@ -1373,14 +1372,3 @@ func (cfg *Config) SSHCommands() (s string) {
}
return buf.String()
}

const ll = "0123456789abcdefghijklmnopqrstuvwxyz"

func randString(n int) string {
b := make([]byte, n)
for i := range b {
rand.Seed(time.Now().UnixNano())
b[i] = ll[rand.Intn(len(ll))]
}
return string(b)
}
26 changes: 26 additions & 0 deletions eksconfig/rand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eksconfig

import (
"math/rand"
"time"
)

const ll = "0123456789abcdefghijklmnopqrstuvwxyz"

func randString(n int) string {
b := make([]byte, n)
for i := range b {
rand.Seed(time.Now().UnixNano())
b[i] = ll[rand.Intn(len(ll))]
}
pfx := randoms[rand.Intn(len(randoms))]
s := pfx + string(b)
if len(s) > n {
s = s[:n]
}
return s
}

var randoms = []string{
"autumn", "resonance", "sun", "wood", "dream", "cherry", "tree", "fog", "frost", "voice", "morning", "sparkling", "wandering", "wild", "black", "holy", "snowy", "butterfly", "long", "lingering", "bold", "green", "river", "breeze", "proud", "floral", "divine", "polished", "ancient", "delight", "purple", "lively", "waterfall", "flower", "firefly", "feather", "grass", "haze", "glacial", "mountain", "snowflake", "silence", "misty", "dry", "summer", "icy", "delicate", "siberian", "cool", "spring", "winter", "patient", "twilight", "dawn", "blue", "coral", "bird", "everest", "brook", "rain", "wind", "sea", "morning", "snow", "lake", "sunset", "blueshift", "pine", "leaf", "dawn", "glitter", "forest", "milan", "cloud", "meadow", "sun", "sound", "sky", "shape", "surf", "water", "wildflower", "wave", "water", "amber", "damp", "reinvent", "falling", "day1", "prime", "nitro", "frosty", "paper", "star", "onion", "hawaii",
}
10 changes: 10 additions & 0 deletions eksconfig/rand_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package eksconfig

import (
"fmt"
"testing"
)

func TestRand(t *testing.T) {
fmt.Println(randString(12))
}

0 comments on commit 17ece43

Please sign in to comment.