-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
51 lines (41 loc) · 914 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"crypto/rand"
"encoding/base64"
"flag"
"fmt"
"runtime"
"runtime/debug"
"strings"
)
const (
keyLen = 18
secretLen = 36
pad = '+'
devVersion = "dev"
envTemplate = "MINIO_ROOT_USER=%s\nMINIO_ROOT_PASSWORD=%s\n"
about = `minio-keygen (%s, %s)
Generates a MinIO access key and secret. You can redirect the output into an .env file.
`
)
func main() {
flag.Usage = usage
flag.Parse()
rawKey := make([]byte, keyLen)
if _, err := rand.Read(rawKey); err != nil {
panic(err)
}
rawSecret := make([]byte, secretLen)
if _, err := rand.Read(rawSecret); err != nil {
panic(err)
}
enc := base64.URLEncoding.WithPadding(pad).EncodeToString
fmt.Printf(envTemplate, strings.ToUpper(enc(rawKey)), enc(rawSecret))
}
func usage() {
ver := devVersion
if info, ok := debug.ReadBuildInfo(); ok {
ver = info.Main.Version
}
fmt.Printf(about, ver, runtime.Version())
}