Skip to content

Commit

Permalink
generate password using base64
Browse files Browse the repository at this point in the history
  • Loading branch information
hensur committed Aug 17, 2018
1 parent c71b8a0 commit d3bdfd6
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
package main

import (
"crypto/rand"
"encoding/base64"
"flag"
"time"

"github.com/golang/glog"
"github.com/mittwald/kubernetes-secret-generator/util"
"k8s.io/client-go/kubernetes"
Expand All @@ -30,9 +34,6 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
"crypto/rand"
"math/big"
"time"
)

const (
Expand All @@ -42,9 +43,6 @@ const (
SecretSecureAnnotation = "secret-generator.v1.mittwald.de/secure"
)

var runes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
var runesLen = big.NewInt(int64(len(runes)))

var namespace string
var allNamespaces bool
var kubecfg string
Expand Down Expand Up @@ -180,13 +178,8 @@ func (c *GeneratorController) SecretAdded(obj interface{}) {
}

func generateSecret(length int) (string, error) {
b := make([]rune, length)
for i := range b {
n, err := rand.Int(rand.Reader, runesLen)
if err != nil {
return "", err
}
b[i] = runes[n.Int64()]
}
return string(b), nil
b := make([]byte, length)
rand.Read(b)

return base64.StdEncoding.EncodeToString(b)[0:length], nil
}

0 comments on commit d3bdfd6

Please sign in to comment.