You've already forked prometheus-fail2ban-exporter

Add new CLI parameters to enable protecting the API endpoints with basic auth authentication. Wrap the server endpoints in a new auth middleware that protects it using the provided basic auth credentials (if set). Store the provided basic auth credentials as hashed values to prevent them from being accidentally leaked. Add unit tests to ensure the new functionality works as expected.
19 lines
262 B
Go
19 lines
262 B
Go
package auth
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
)
|
|
|
|
func Hash(data []byte) []byte {
|
|
if len(data) == 0 {
|
|
return []byte{}
|
|
}
|
|
b := sha256.Sum256(data)
|
|
return b[:]
|
|
}
|
|
|
|
func HashString(data string) string {
|
|
return hex.EncodeToString(Hash([]byte(data)))
|
|
}
|