Skip to content

Commit

Permalink
generate the dataplane api secret (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Siwiec <[email protected]>
  • Loading branch information
rizzza authored Oct 6, 2023
1 parent ab4fca3 commit 0a649e9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/srv/helm.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package srv

import (
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/rand"
"strconv"
"time"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
Expand Down Expand Up @@ -34,6 +37,9 @@ func (v helmvalues) generateLBHelmVals(lb *loadBalancer, s *Server) {
v.StringValues = append(v.StringValues, fmt.Sprintf("%s=%s", managedHelmKeyPrefix+".lbIP", lb.lbData.IPAddresses[0].IP))
}

// add dataplane api secret
v.StringValues = append(v.StringValues, fmt.Sprintf("%s=%s", managedHelmKeyPrefix+".dataPlaneAPICreds", generateSecret()))

// add port values
var cport, sport []interface{}

Expand Down Expand Up @@ -105,3 +111,18 @@ func (s *Server) newHelmValues(lb *loadBalancer) (map[string]interface{}, error)

return values, nil
}

// generateSecret generate base64-encoded random 32-byte alphanumeric string
func generateSecret() string {
const rlen = 32

alphaNum := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
r := make([]rune, rlen)

for i := range r {
r[i] = alphaNum[rnd.Intn(len(alphaNum))]
}

return base64.StdEncoding.EncodeToString([]byte(string(r)))
}

0 comments on commit 0a649e9

Please sign in to comment.