Skip to content

Commit

Permalink
feat(GODT-3199): add package log field.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuthix committed Feb 26, 2024
1 parent 30339d1 commit 6c7ea91
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
3 changes: 1 addition & 2 deletions keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package proton

import "github.com/sirupsen/logrus"

var log = logrus.WithField("pkg", "gpa")
3 changes: 1 addition & 2 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions server/backend/api_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ 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) {
return writeBackendRetErr(b, func(b *unsafeBackend) (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)
}

Expand All @@ -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")
}

Expand Down
3 changes: 3 additions & 0 deletions server/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions server/backend/quark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 6c7ea91

Please sign in to comment.