mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(metrics): add metrics server (#1930)
* feat(metrics): add metrics server * chore: update license headers * feat(metrics): add optional basic auth * feat(metrics): add go and process collectors --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com> Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
0d5902c8f6
commit
3f8bc0140c
16 changed files with 1191 additions and 83 deletions
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
|
@ -278,6 +279,19 @@ func main() {
|
|||
fmt.Println("Database reset and reseed completed successfully!")
|
||||
}
|
||||
|
||||
case "htpasswd":
|
||||
password, err := readPassword()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read password: %v", err)
|
||||
}
|
||||
|
||||
hash, err := CreateHtpasswdHash(string(password))
|
||||
if err != nil {
|
||||
log.Fatalf("failed to hash password: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println(hash)
|
||||
|
||||
default:
|
||||
flag.Usage()
|
||||
if cmd != "help" {
|
||||
|
@ -316,3 +330,15 @@ func readPassword() (password []byte, err error) {
|
|||
|
||||
return password, nil
|
||||
}
|
||||
|
||||
// CreateHtpasswdHash generates a bcrypt hash of the password for use in basic auth
|
||||
func CreateHtpasswdHash(password string) (string, error) {
|
||||
// Generate a bcrypt hash from the input password
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to generate hash: %v", err)
|
||||
}
|
||||
|
||||
// Return the formatted bcrypt hash (with the bcrypt marker "$2y$")
|
||||
return string(hash), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue