| 1 | package exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ |
| 2 | |
| 3 | import ( |
| 4 | "crypto/subtlescip-go gomod github.com/golang/go/src go1.25.0 `crypto/subtle`/" |
| 5 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/" |
| 6 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 8 | "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/" |
| 9 | "net/urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/" |
| 10 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 11 | |
| 12 | "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/" |
| 13 | "github.com/prometheus/client_golang/prometheus/promhttpscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/" |
| 14 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/ "github.com/sirupsen/logrusscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/" |
| 15 | "golang.org/x/crypto/bcryptscip-go gomod golang.org/x/crypto v0.52.0 `golang.org/x/crypto/bcrypt`/" |
| 16 | ) |
| 17 | |
| 18 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) ServeHTTPscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#ServeHTTP().(w httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) { |
| 19 | if err := e.verifyBasicAuthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#verifyBasicAuth().(r.BasicAuthscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#BasicAuth().()); err != nil { |
| 20 | w.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("WWW-Authenticate", `Basic realm="redis-exporter, charset=UTF-8"`) |
| 21 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusUnauthorized.) |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | e.muxscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#mux..ServeHTTPscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ServeMux#ServeHTTP().(w, r) |
| 26 | } |
| 27 | |
| 28 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) healthHandlerscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#healthHandler().(w httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) { |
| 29 | _, _ = w.Writescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#Write().([]byte(`ok`)) |
| 30 | } |
| 31 | |
| 32 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) indexHandlerscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#indexHandler().(w httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) { |
| 33 | if r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Pathscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Path. != "/" { |
| 34 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.NotFoundscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/NotFound().(w, r) |
| 35 | return |
| 36 | } |
| 37 | _, _ = w.Writescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#Write().([]byte(`<html> |
| 38 | <head><title>Redis Exporter ` + e.buildInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#buildInfo..Versionscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/BuildInfo#Version. + `</title></head> |
| 39 | <body> |
| 40 | <h1>Redis Exporter ` + e.buildInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#buildInfo..Versionscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/BuildInfo#Version. + `</h1> |
| 41 | <p><a href='` + e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..MetricsPathscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#MetricsPath. + `'>Metrics</a></p> |
| 42 | </body> |
| 43 | </html> |
| 44 | `)) |
| 45 | } |
| 46 | |
| 47 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) scrapeHandlerscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#scrapeHandler().(w httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) { |
| 48 | target := r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Values#Get().("target") |
| 49 | if target == "" { |
| 50 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, "'target' parameter must be specified", httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusBadRequest.) |
| 51 | e.targetScrapeRequestErrorsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#targetScrapeRequestErrors..Incscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Counter#Inc().() |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(target, "://") { |
| 56 | target = "redis://" + target |
| 57 | } |
| 58 | |
| 59 | u, err := urlscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Parse().(target) |
| 60 | if err != nil { |
| 61 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Invalid 'target' parameter, parse err: %v ", err), httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusBadRequest.) |
| 62 | e.targetScrapeRequestErrorsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#targetScrapeRequestErrors..Incscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Counter#Inc().() |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | opts := e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options. |
| 67 | |
| 68 | // get rid of username/password info in "target" so users don't send them in plain text via http |
| 69 | // and save "user" in options so we can use it later when connecting to the redis instance |
| 70 | // the password will be looked up from the password file |
| 71 | if u.Userscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#User. != nil { |
| 72 | opts.Userscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#User. = u.Userscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Userinfo#Username().() |
| 73 | u.Userscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#User. = nil |
| 74 | } |
| 75 | target = u.Stringscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#String().() |
| 76 | |
| 77 | if ck := r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Values#Get().("check-keys"); ck != "" { |
| 78 | opts.CheckKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CheckKeys. = ck |
| 79 | } |
| 80 | |
| 81 | if csk := r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Values#Get().("check-single-keys"); csk != "" { |
| 82 | opts.CheckSingleKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CheckSingleKeys. = csk |
| 83 | } |
| 84 | |
| 85 | if cs := r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Values#Get().("check-streams"); cs != "" { |
| 86 | opts.CheckStreamsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CheckStreams. = cs |
| 87 | } |
| 88 | |
| 89 | if css := r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Values#Get().("check-single-streams"); css != "" { |
| 90 | opts.CheckSingleStreamsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CheckSingleStreams. = css |
| 91 | } |
| 92 | |
| 93 | if cntk := r.URLscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.25.0 `net/url`/Values#Get().("count-keys"); cntk != "" { |
| 94 | opts.CountKeysscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#CountKeys. = cntk |
| 95 | } |
| 96 | |
| 97 | opts.Registryscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Registry. = prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewRegistryscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewRegistry().() |
| 98 | |
| 99 | _, err = NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(target, opts) |
| 100 | if err != nil { |
| 101 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("NewRedisExporter() error: %v", err), httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusBadRequest.) |
| 102 | e.targetScrapeRequestErrorsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#targetScrapeRequestErrors..Incscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Counter#Inc().() |
| 103 | return |
| 104 | } |
| 105 | |
| 106 | promhttpscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/.HandlerForscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/HandlerFor().( |
| 107 | opts.Registryscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Registry., promhttpscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/.HandlerOptsscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/HandlerOpts#{ErrorHandlingscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/HandlerOpts#ErrorHandling.: promhttpscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/.ContinueOnErrorscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus/promhttp`/ContinueOnError.}, |
| 108 | ).ServeHTTPscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Handler#ServeHTTP().(w, r) |
| 109 | } |
| 110 | |
| 111 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) discoverClusterNodesHandlerscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#discoverClusterNodesHandler().(w httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) { |
| 112 | if !e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..IsClusterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#IsCluster. { |
| 113 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, "The discovery endpoint is only available on a redis cluster", httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusBadRequest.) |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | c, err := e.connectToRedisClusterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#connectToRedisCluster().() |
| 118 | if err != nil { |
| 119 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Couldn't connect to redis cluster: %s", err), httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusInternalServerError.) |
| 120 | return |
| 121 | } |
| 122 | defer c.Closescip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#Close().() |
| 123 | |
| 124 | nodes, err := e.getClusterNodesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#getClusterNodes().(c) |
| 125 | if err != nil { |
| 126 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Failed to fetch cluster nodes: %s", err), httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusInternalServerError.) |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | discovery := []struct { |
| 131 | Targets []string `json:"targets"` |
| 132 | Labels map[string]string `json:"labels"` |
| 133 | }{ |
| 134 | { |
| 135 | Targets: make([]string, len(nodes)), |
| 136 | Labels: make(map[string]string, 0), |
| 137 | }, |
| 138 | } |
| 139 | |
| 140 | isTls := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(e.redisAddrscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#redisAddr., "rediss://") |
| 141 | for i, node := range nodes { |
| 142 | if isTls { |
| 143 | discovery[0].Targets[i] = "rediss://" + node |
| 144 | } else { |
| 145 | discovery[0].Targets[i] = "redis://" + node |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | data, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.MarshalIndentscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/MarshalIndent().(discovery, "", " ") |
| 150 | if err != nil { |
| 151 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Failed to marshal discovery data: %s", err), httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusInternalServerError.) |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | w.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Content-Type", "application/json") |
| 156 | _, _ = w.Writescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#Write().(data) |
| 157 | } |
| 158 | |
| 159 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) reloadPwdFilescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#reloadPwdFile().(w httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) { |
| 160 | if e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..RedisPwdFilescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#RedisPwdFile. == "" { |
| 161 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, "There is no pwd file specified", httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusBadRequest.) |
| 162 | return |
| 163 | } |
| 164 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Reload redisPwdFile") |
| 165 | passwordMap, err := LoadPwdFilescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/LoadPwdFile().(e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..RedisPwdFilescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#RedisPwdFile.) |
| 166 | if err != nil { |
| 167 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Errorfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Errorf().("Error reloading redis passwords from file %s, err: %s", e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..RedisPwdFilescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#RedisPwdFile., err) |
| 168 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Error().(w, "failed to reload passwords file: "+err.Error(), httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/StatusInternalServerError.) |
| 169 | return |
| 170 | } |
| 171 | e.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Lock().() |
| 172 | e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..PasswordMapscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#PasswordMap. = passwordMap |
| 173 | e.Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Mutex#Unlock().() |
| 174 | _, _ = w.Writescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/ResponseWriter#Write().([]byte(`ok`)) |
| 175 | } |
| 176 | |
| 177 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) isBasicAuthConfiguredscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#isBasicAuthConfigured().() bool { |
| 178 | return e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..BasicAuthUsernamescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#BasicAuthUsername. != "" && (e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..BasicAuthPasswordscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#BasicAuthPassword. != "" || e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..BasicAuthHashPasswordscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#BasicAuthHashPassword. != "") |
| 179 | } |
| 180 | |
| 181 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) verifyBasicAuthscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#verifyBasicAuth().(user, password string, authHeaderSet bool) error { |
| 182 | if !e.isBasicAuthConfiguredscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#isBasicAuthConfigured().() { |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | if !authHeaderSet { |
| 187 | return errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("Unauthorized") |
| 188 | } |
| 189 | |
| 190 | userCorrect := subtlescip-go gomod github.com/golang/go/src go1.25.0 `crypto/subtle`/.ConstantTimeComparescip-go gomod github.com/golang/go/src go1.25.0 `crypto/subtle`/ConstantTimeCompare().([]byte(user), []byte(e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..BasicAuthUsernamescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#BasicAuthUsername.)) == 1 |
| 191 | passCorrect := e.validateBasicAuthPasswordscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#validateBasicAuthPassword().(password) |
| 192 | |
| 193 | if !userCorrect || !passCorrect { |
| 194 | return errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("Unauthorized") |
| 195 | } |
| 196 | |
| 197 | return nil |
| 198 | } |
| 199 | |
| 200 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) validateBasicAuthPasswordscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#validateBasicAuthPassword().(password string) bool { |
| 201 | if e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..BasicAuthHashPasswordscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#BasicAuthHashPassword. != "" { |
| 202 | return bcryptscip-go gomod golang.org/x/crypto v0.52.0 `golang.org/x/crypto/bcrypt`/.CompareHashAndPasswordscip-go gomod golang.org/x/crypto v0.52.0 `golang.org/x/crypto/bcrypt`/CompareHashAndPassword().([]byte(e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..BasicAuthHashPasswordscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#BasicAuthHashPassword.), []byte(password)) == nil |
| 203 | } else { |
| 204 | return subtlescip-go gomod github.com/golang/go/src go1.25.0 `crypto/subtle`/.ConstantTimeComparescip-go gomod github.com/golang/go/src go1.25.0 `crypto/subtle`/ConstantTimeCompare().([]byte(password), []byte(e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..BasicAuthPasswordscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#BasicAuthPassword.)) == 1 |
| 205 | } |
| 206 | } |