Skip to content

Commit ec58ed7

Browse files
committedFeb 26, 2024·
feat(GODT-3199): add package log field.
1 parent 30339d1 commit ec58ed7

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed
 

‎keyring.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/ProtonMail/go-crypto/openpgp/armor"
1313
"github.com/ProtonMail/gopenpgp/v2/crypto"
1414
"github.com/bradenaw/juniper/xslices"
15-
"github.com/sirupsen/logrus"
1615
)
1716

1817
func ExtractSignatures(kr *crypto.KeyRing, arm string) ([]Signature, error) {
@@ -152,7 +151,7 @@ func (keys Keys) Unlock(passphrase []byte, userKR *crypto.KeyRing) (*crypto.KeyR
152151
for _, key := range xslices.Filter(keys, func(key Key) bool { return bool(key.Active) }) {
153152
unlocked, err := key.Unlock(passphrase, userKR)
154153
if err != nil {
155-
logrus.WithField("KeyID", key.ID).WithError(err).Warning("Cannot unlock key")
154+
log.WithField("KeyID", key.ID).WithError(err).Warning("Cannot unlock key")
156155
continue
157156
}
158157

‎logging.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package proton
2+
3+
import "github.com/sirupsen/logrus"
4+
5+
var log = logrus.WithField("pkg", "gpa")

‎response.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ func catchRetryAfter(_ *resty.Client, res *resty.Response) (time.Duration, error
158158
// Add some jitter to the delay.
159159
after += rand.Intn(10)
160160

161-
logrus.WithFields(logrus.Fields{
162-
"pkg": "go-proton-api",
161+
log.WithFields(logrus.Fields{
163162
"status": res.StatusCode(),
164163
"url": res.Request.URL,
165164
"method": res.Request.Method,

‎server/auth.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/sirupsen/logrus"
1010
)
1111

12+
var log = logrus.WithField("pkg", "gpa/server")
13+
1214
func (s *Server) handlePostAuthInfo() gin.HandlerFunc {
1315
return func(c *gin.Context) {
1416
var req proton.AuthInfoReq
@@ -19,7 +21,7 @@ func (s *Server) handlePostAuthInfo() gin.HandlerFunc {
1921

2022
info, err := s.b.NewAuthInfo(req.Username)
2123
if err != nil {
22-
logrus.WithError(err).Errorf("User '%v' failed auth info", req.Username)
24+
log.WithError(err).Errorf("User '%v' failed auth info", req.Username)
2325
_ = c.AbortWithError(http.StatusUnauthorized, err)
2426
return
2527
}
@@ -50,7 +52,7 @@ func (s *Server) handlePostAuth() gin.HandlerFunc {
5052

5153
auth, err := s.b.NewAuth(req.Username, clientEphemeral, clientProof, req.SRPSession)
5254
if err != nil {
53-
logrus.WithError(err).Errorf("User '%v' not authorized", req.Username)
55+
log.WithError(err).Errorf("User '%v' not authorized", req.Username)
5456
_ = c.AbortWithError(http.StatusUnauthorized, err)
5557
return
5658
}

‎server/backend/api_auth.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ import (
77
"github.com/ProtonMail/go-proton-api"
88
"github.com/ProtonMail/go-srp"
99
"github.com/google/uuid"
10-
"github.com/sirupsen/logrus"
1110
)
1211

1312
func (b *Backend) NewAuthInfo(username string) (proton.AuthInfo, error) {
1413
return writeBackendRetErr(b, func(b *unsafeBackend) (proton.AuthInfo, error) {
1514
return withAccName(b, username, func(acc *account) (proton.AuthInfo, error) {
1615
server, err := srp.NewServerFromSigned(modulus, acc.verifier, 2048)
1716
if err != nil {
18-
logrus.WithError(err).Errorf("Failed to create SRP Server")
17+
log.WithError(err).Errorf("Failed to create SRP Server")
1918
return proton.AuthInfo{}, fmt.Errorf("failed to create new srp server %w", err)
2019
}
2120

2221
challenge, err := server.GenerateChallenge()
2322
if err != nil {
24-
logrus.WithError(err).Errorf("Failed to generate srp challeng")
23+
log.WithError(err).Errorf("Failed to generate srp challeng")
2524
return proton.AuthInfo{}, fmt.Errorf("failed to generate srp challend %w", err)
2625
}
2726

@@ -45,7 +44,7 @@ func (b *Backend) NewAuth(username string, ephemeral, proof []byte, session stri
4544
return withAccName(b, username, func(acc *account) (proton.Auth, error) {
4645
server, ok := b.srp[session]
4746
if !ok {
48-
logrus.Errorf("Session '%v' not found for user='%v'", session, username)
47+
log.Errorf("Session '%v' not found for user='%v'", session, username)
4948
return proton.Auth{}, fmt.Errorf("invalid session")
5049
}
5150

‎server/backend/backend.go

+3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import (
1212
"github.com/ProtonMail/gopenpgp/v2/crypto"
1313
"github.com/bradenaw/juniper/xslices"
1414
"github.com/google/uuid"
15+
"github.com/sirupsen/logrus"
1516
"golang.org/x/exp/maps"
1617
"golang.org/x/exp/slices"
1718
)
1819

20+
var log = logrus.WithField("pkg", "gpa/server/backend")
21+
1922
type Backend struct {
2023
domain string
2124

‎server/backend/quark.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66

77
"github.com/ProtonMail/go-proton-api"
8-
"github.com/sirupsen/logrus"
98
)
109

1110
func (s *Backend) RunQuarkCommand(command string, args ...string) (any, error) {
@@ -78,7 +77,7 @@ func (s *Backend) quarkUserCreate(args ...string) (proton.User, error) {
7877
}
7978
}
8079

81-
logrus.Infof("User '%v' created with id=%v", *name, userID)
80+
log.Infof("User '%v' created with id=%v", *name, userID)
8281

8382
return s.GetUser(userID)
8483
}

0 commit comments

Comments
 (0)
Please sign in to comment.