mirror of
https://github.com/ProtonMail/go-proton-api.git
synced 2025-12-23 23:57:50 -05:00
feat(GODT-3199): add package log field.
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/ProtonMail/go-crypto/openpgp/armor"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func ExtractSignatures(kr *crypto.KeyRing, arm string) ([]Signature, error) {
|
||||
@@ -152,7 +151,7 @@ func (keys Keys) Unlock(passphrase []byte, userKR *crypto.KeyRing) (*crypto.KeyR
|
||||
for _, key := range xslices.Filter(keys, func(key Key) bool { return bool(key.Active) }) {
|
||||
unlocked, err := key.Unlock(passphrase, userKR)
|
||||
if err != nil {
|
||||
logrus.WithField("KeyID", key.ID).WithError(err).Warning("Cannot unlock key")
|
||||
log.WithField("KeyID", key.ID).WithError(err).Warning("Cannot unlock key")
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
5
logging.go
Normal file
5
logging.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package proton
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
var log = logrus.WithField("pkg", "gpa")
|
||||
@@ -158,8 +158,7 @@ func catchRetryAfter(_ *resty.Client, res *resty.Response) (time.Duration, error
|
||||
// Add some jitter to the delay.
|
||||
after += rand.Intn(10)
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"pkg": "go-proton-api",
|
||||
log.WithFields(logrus.Fields{
|
||||
"status": res.StatusCode(),
|
||||
"url": res.Request.URL,
|
||||
"method": res.Request.Method,
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("pkg", "gpa/server")
|
||||
|
||||
func (s *Server) handlePostAuthInfo() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var req proton.AuthInfoReq
|
||||
@@ -19,7 +21,7 @@ func (s *Server) handlePostAuthInfo() gin.HandlerFunc {
|
||||
|
||||
info, err := s.b.NewAuthInfo(req.Username)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("User '%v' failed auth info", req.Username)
|
||||
log.WithError(err).Errorf("User '%v' failed auth info", req.Username)
|
||||
_ = c.AbortWithError(http.StatusUnauthorized, err)
|
||||
return
|
||||
}
|
||||
@@ -50,7 +52,7 @@ func (s *Server) handlePostAuth() gin.HandlerFunc {
|
||||
|
||||
auth, err := s.b.NewAuth(req.Username, clientEphemeral, clientProof, req.SRPSession)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("User '%v' not authorized", req.Username)
|
||||
log.WithError(err).Errorf("User '%v' not authorized", req.Username)
|
||||
_ = c.AbortWithError(http.StatusUnauthorized, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/go-srp"
|
||||
"github.com/google/uuid"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (b *Backend) NewAuthInfo(username string) (proton.AuthInfo, error) {
|
||||
@@ -15,13 +14,13 @@ func (b *Backend) NewAuthInfo(username string) (proton.AuthInfo, error) {
|
||||
return withAccName(b, username, func(acc *account) (proton.AuthInfo, error) {
|
||||
server, err := srp.NewServerFromSigned(modulus, acc.verifier, 2048)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("Failed to create SRP Server")
|
||||
log.WithError(err).Errorf("Failed to create SRP Server")
|
||||
return proton.AuthInfo{}, fmt.Errorf("failed to create new srp server %w", err)
|
||||
}
|
||||
|
||||
challenge, err := server.GenerateChallenge()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("Failed to generate srp challeng")
|
||||
log.WithError(err).Errorf("Failed to generate srp challeng")
|
||||
return proton.AuthInfo{}, fmt.Errorf("failed to generate srp challend %w", err)
|
||||
}
|
||||
|
||||
@@ -45,7 +44,7 @@ func (b *Backend) NewAuth(username string, ephemeral, proof []byte, session stri
|
||||
return withAccName(b, username, func(acc *account) (proton.Auth, error) {
|
||||
server, ok := b.srp[session]
|
||||
if !ok {
|
||||
logrus.Errorf("Session '%v' not found for user='%v'", session, username)
|
||||
log.Errorf("Session '%v' not found for user='%v'", session, username)
|
||||
return proton.Auth{}, fmt.Errorf("invalid session")
|
||||
}
|
||||
|
||||
|
||||
@@ -12,10 +12,13 @@ import (
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
"github.com/google/uuid"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("pkg", "gpa/server/backend")
|
||||
|
||||
type Backend struct {
|
||||
domain string
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (s *Backend) RunQuarkCommand(command string, args ...string) (any, error) {
|
||||
@@ -78,7 +77,7 @@ func (s *Backend) quarkUserCreate(args ...string) (proton.User, error) {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Infof("User '%v' created with id=%v", *name, userID)
|
||||
log.Infof("User '%v' created with id=%v", *name, userID)
|
||||
|
||||
return s.GetUser(userID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user