@@ -20,6 +20,7 @@ import (
2020 "time"
2121
2222 as "github.com/aerospike/aerospike-client-go"
23+ "github.com/aerospike/aerospike-client-go/pkg/bcrypt"
2324 "github.com/prometheus/client_golang/prometheus"
2425 "github.com/prometheus/client_golang/prometheus/promhttp"
2526)
@@ -136,7 +137,13 @@ func (asc *asCollector) Collect(ch chan<- prometheus.Metric) {
136137 return
137138 }
138139 if asc .username != "" {
139- if err := conn .Authenticate (asc .username , []byte (asc .password )); err != nil {
140+ hp , err := hashPassword (asc .password )
141+ if err != nil {
142+ log .Printf ("hashPassword: %s" , err )
143+ ch <- prometheus .MustNewConstMetric (upDesc , prometheus .GaugeValue , 0.0 )
144+ return
145+ }
146+ if err := conn .Authenticate (asc .username , hp ); err != nil {
140147 log .Printf ("auth error: %s" , err )
141148 ch <- prometheus .MustNewConstMetric (upDesc , prometheus .GaugeValue , 0.0 )
142149 return
@@ -150,3 +157,14 @@ func (asc *asCollector) Collect(ch chan<- prometheus.Metric) {
150157 c .collect (conn , ch )
151158 }
152159}
160+
161+ // take from github.com/aerospike/aerospike-client-go/admin_command.go
162+ func hashPassword (password string ) ([]byte , error ) {
163+ // Hashing the password with the cost of 10, with a static salt
164+ const salt = "$2a$10$7EqJtq98hPqEX7fNZaFWoO"
165+ hashedPassword , err := bcrypt .Hash (password , salt )
166+ if err != nil {
167+ return nil , err
168+ }
169+ return []byte (hashedPassword ), nil
170+ }
0 commit comments