github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/registry/regserver/handlers/admin_key.go (about)

     1  package handlers
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  )
     7  
     8  func init() {
     9  	rand.Seed(time.Now().UnixNano())
    10  }
    11  
    12  // NewAdminKey generates a randomized key for admin work
    13  // this is a lazy stopgap for now
    14  func NewAdminKey() string {
    15  	return randStringRunes(25)
    16  }
    17  
    18  // randStringRunes creates a random string of n length
    19  func randStringRunes(n int) string {
    20  	runes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
    21  	b := make([]rune, n)
    22  	for i := range b {
    23  		b[i] = runes[rand.Intn(len(runes))]
    24  	}
    25  	return string(b)
    26  }