@@ -2,6 +2,8 @@ package applicationmonitoring
22
33import (
44 "bytes"
5+ "crypto/rand"
6+ "encoding/base64"
57 "fmt"
68 "io/ioutil"
79 "os"
@@ -21,6 +23,7 @@ const (
2123 PrometheusOperatorServiceAccountName = "prometheus-operator-service-account"
2224 PrometheusCrName = "prometheus"
2325 PrometheusRouteName = "prometheus-route"
26+ PrometheusProxySecretsName = "prometheus-proxy-secret"
2427 PrometheusServiceAccountName = "prometheus-service-account"
2528 PrometheusServiceName = "prometheus-service"
2629 AlertManagerServiceAccountName = "alertmanager-service-account"
@@ -45,6 +48,7 @@ type Parameters struct {
4548 PrometheusCrName string
4649 PrometheusRouteName string
4750 PrometheusServiceName string
51+ PrometheusSessionSecret string
4852 AlertManagerServiceAccountName string
4953 AlertManagerCrName string
5054 AlertManagerServiceName string
@@ -76,6 +80,7 @@ func newTemplateHelper(cr *applicationmonitoring.ApplicationMonitoring, extraPar
7680 PrometheusCrName : PrometheusCrName ,
7781 PrometheusRouteName : PrometheusRouteName ,
7882 PrometheusServiceName : PrometheusServiceName ,
83+ PrometheusSessionSecret : PopulatePrometheusProxySecret (),
7984 AlertManagerServiceAccountName : AlertManagerServiceAccountName ,
8085 AlertManagerCrName : AlertManagerCrName ,
8186 AlertManagerServiceName : AlertManagerServiceName ,
@@ -102,6 +107,15 @@ func newTemplateHelper(cr *applicationmonitoring.ApplicationMonitoring, extraPar
102107 }
103108}
104109
110+ // Populate the PrometheusServiceName values
111+ func PopulatePrometheusProxySecret () string {
112+ p , err := GeneratePassword (43 )
113+ if err != nil {
114+ log .Info ("Error creating PopulatePrometheusProxySecret" )
115+ }
116+ return p
117+ }
118+
105119// load a templates from a given resource name. The templates must be located
106120// under ./templates and the filename must be <resource-name>.yaml
107121func (h * TemplateHelper ) loadTemplate (name string ) ([]byte , error ) {
@@ -124,3 +138,14 @@ func (h *TemplateHelper) loadTemplate(name string) ([]byte, error) {
124138
125139 return buffer .Bytes (), nil
126140}
141+
142+ // GeneratePassword returns a base64 encoded securely random bytes.
143+ func GeneratePassword (n int ) (string , error ) {
144+ b := make ([]byte , n )
145+ _ , err := rand .Read (b )
146+ if err != nil {
147+ return "" , err
148+ }
149+
150+ return base64 .StdEncoding .EncodeToString (b ), err
151+ }
0 commit comments