Skip to content

Commit af55fa3

Browse files
fix(artifacthub): Reduce log noise and merge log messages for better visibility (#476)
## 📝 Description Merges claims and paths log message so it is easier to correlate the requested paths and source of the request. ## ✅ Checklist - [ ] I have tested this change - [ ] This change requires documentation update
1 parent e040449 commit af55fa3

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

artifacthub/pkg/server/public/publicserver.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ func getAuthTokenFromContext(ctx context.Context) (string, error) {
7878
// artifact storage, and deleting as well.
7979
func (s *Server) GenerateSignedURLs(ctx context.Context,
8080
q *artifacts.GenerateSignedURLsRequest) (*artifacts.GenerateSignedURLsResponse, error) {
81-
log.Info("[GenerateSignedURLs] Received", zap.Reflect("request", q))
82-
8381
response := &artifacts.GenerateSignedURLsResponse{}
8482
token, err := getAuthTokenFromContext(ctx)
8583
if err != nil {
@@ -93,12 +91,22 @@ func (s *Server) GenerateSignedURLs(ctx context.Context,
9391
return response, nil
9492
}
9593

96-
artifact, err := s.authenticate(token, q.Paths)
94+
artifact, claims, err := s.authenticateAndGetClaims(token, q.Paths)
9795
if err != nil {
9896
log.Error("Error authenticating request", zap.Error(err))
9997
return nil, err
10098
}
10199

100+
log.Info("[GenerateSignedURLs] Authenticated request",
101+
zap.String("type", q.Type.String()),
102+
zap.Int("paths_count", len(q.Paths)),
103+
zap.Strings("paths", q.Paths),
104+
zap.String("artifact", claims.ArtifactID),
105+
zap.String("project", claims.Project),
106+
zap.String("job", claims.Job),
107+
zap.String("workflow", claims.Workflow),
108+
)
109+
102110
var us []*artifacts.SignedURL
103111
switch q.Type {
104112
case artifacts.GenerateSignedURLsRequest_PUSH:
@@ -177,26 +185,23 @@ func getMaxReceiveMessageSize() int {
177185
return maxReceiveMsgSize
178186
}
179187

180-
func (s *Server) authenticate(token string, paths []string) (*models.Artifact, error) {
188+
func (s *Server) authenticateAndGetClaims(token string, paths []string) (*models.Artifact, *jwt.Claims, error) {
181189
resourceType, resourceID, err := s.findAndValidateResource(paths)
182190
if err != nil {
183-
return nil, err
191+
return nil, nil, err
184192
}
185193

186194
claims, err := s.validateJWT(resourceType, resourceID, token)
187195
if err != nil {
188-
return nil, status.Error(codes.PermissionDenied, err.Error())
196+
return nil, nil, status.Error(codes.PermissionDenied, err.Error())
189197
}
190198

191-
log.Info(
192-
"Granted access to artifact storage through JWT",
193-
zap.String("artifact", claims.ArtifactID),
194-
zap.String("project", claims.Project),
195-
zap.String("job", claims.Job),
196-
zap.String("workflow", claims.Workflow),
197-
)
199+
artifacts, err := models.FindArtifactByID(claims.ArtifactID)
200+
if err != nil {
201+
return nil, nil, err
202+
}
198203

199-
return models.FindArtifactByID(claims.ArtifactID)
204+
return artifacts, claims, nil
200205
}
201206

202207
func (s *Server) validateJWT(resourceType, resourceID, token string) (*jwt.Claims, error) {

0 commit comments

Comments
 (0)