Use logrus for logging

This commit is contained in:
eikendev 2022-04-11 23:46:02 +02:00
parent c96baf40a5
commit f839f248b9
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
19 changed files with 192 additions and 87 deletions

View file

@ -1,9 +1,8 @@
package credentials
import (
"log"
"github.com/pushbits/server/internal/configuration"
"github.com/pushbits/server/internal/log"
"github.com/alexedwards/argon2id"
)
@ -16,7 +15,7 @@ type Manager struct {
// CreateManager instanciates a credential manager.
func CreateManager(checkHIBP bool, c configuration.CryptoConfig) *Manager {
log.Println("Setting up credential manager.")
log.L.Println("Setting up credential manager.")
argon2Params := &argon2id.Params{
Memory: c.Argon2.Memory,

View file

@ -4,9 +4,10 @@ import (
"crypto/sha1" //#nosec G505 -- False positive, see the use below.
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"github.com/pushbits/server/internal/log"
)
const (
@ -27,7 +28,7 @@ func IsPasswordPwned(password string) (bool, error) {
lookup := hashStr[0:5]
match := hashStr[5:]
log.Printf("Checking HIBP for hashes starting with '%s'.", lookup)
log.L.Printf("Checking HIBP for hashes starting with '%s'.", lookup)
resp, err := http.Get(pwnedHashesURL + lookup)
if err != nil {
@ -35,13 +36,13 @@ func IsPasswordPwned(password string) (bool, error) {
}
if resp.StatusCode != http.StatusOK {
log.Fatalf("Request failed with HTTP %s.", resp.Status)
log.L.Fatalf("Request failed with HTTP %s.", resp.Status)
}
defer resp.Body.Close()
bodyText, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
log.L.Fatal(err)
}
bodyStr := string(bodyText)

View file

@ -2,9 +2,10 @@ package credentials
import (
"errors"
"log"
"github.com/alexedwards/argon2id"
"github.com/pushbits/server/internal/log"
)
// CreatePasswordHash returns a hashed version of the given password.
@ -21,7 +22,7 @@ func (m *Manager) CreatePasswordHash(password string) ([]byte, error) {
hash, err := argon2id.CreateHash(password, m.argon2Params)
if err != nil {
log.Fatal(err)
log.L.Fatal(err)
panic(err)
}
@ -33,7 +34,7 @@ func ComparePassword(hash, password []byte) bool {
match, err := argon2id.ComparePasswordAndHash(string(password), string(hash))
if err != nil {
log.Fatal(err)
log.L.Fatal(err)
return false
}