Skip to content

Commit da40158

Browse files
authored
Auth: Improve org role sync debugging (#85146)
add login to the context of the logger
1 parent 5146896 commit da40158

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

pkg/services/authn/authnimpl/sync/org_sync.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,31 @@ func (s *OrgSync) SyncOrgRolesHook(ctx context.Context, id *authn.Identity, _ *a
3333
return nil
3434
}
3535

36-
ctxLogger := s.log.FromContext(ctx)
36+
ctxLogger := s.log.FromContext(ctx).New("id", id.ID, "login", id.Login)
3737

3838
namespace, identifier := id.GetNamespacedID()
3939
if namespace != authn.NamespaceUser {
40-
ctxLogger.Warn("Failed to sync org role, invalid namespace for identity", "id", id.ID, "namespace", namespace)
40+
ctxLogger.Warn("Failed to sync org role, invalid namespace for identity", "namespace", namespace)
4141
return nil
4242
}
4343

4444
userID, err := identity.IntIdentifier(namespace, identifier)
4545
if err != nil {
46-
ctxLogger.Warn("Failed to sync org role, invalid ID for identity", "id", id.ID, "namespace", namespace, "err", err)
46+
ctxLogger.Warn("Failed to sync org role, invalid ID for identity", "namespace", namespace, "err", err)
4747
return nil
4848
}
4949

50-
ctxLogger.Debug("Syncing organization roles", "id", id.ID, "extOrgRoles", id.OrgRoles)
50+
ctxLogger.Debug("Syncing organization roles", "extOrgRoles", id.OrgRoles)
5151
// don't sync org roles if none is specified
5252
if len(id.OrgRoles) == 0 {
53-
ctxLogger.Debug("Not syncing organization roles since external user doesn't have any", "id", id.ID)
53+
ctxLogger.Debug("Not syncing organization roles since external user doesn't have any")
5454
return nil
5555
}
5656

5757
orgsQuery := &org.GetUserOrgListQuery{UserID: userID}
5858
result, err := s.orgService.GetUserOrgList(ctx, orgsQuery)
5959
if err != nil {
60-
ctxLogger.Error("Failed to get user's organizations", "id", id.ID, "error", err)
60+
ctxLogger.Error("Failed to get user's organizations", "error", err)
6161
return nil
6262
}
6363

@@ -75,7 +75,7 @@ func (s *OrgSync) SyncOrgRolesHook(ctx context.Context, id *authn.Identity, _ *a
7575
// update role
7676
cmd := &org.UpdateOrgUserCommand{OrgID: orga.OrgID, UserID: userID, Role: extRole}
7777
if err := s.orgService.UpdateOrgUser(ctx, cmd); err != nil {
78-
ctxLogger.Error("Failed to update active org user", "id", id.ID, "error", err)
78+
ctxLogger.Error("Failed to update active org user", "error", err)
7979
return err
8080
}
8181
}
@@ -93,17 +93,17 @@ func (s *OrgSync) SyncOrgRolesHook(ctx context.Context, id *authn.Identity, _ *a
9393
cmd := &org.AddOrgUserCommand{UserID: userID, Role: orgRole, OrgID: orgId}
9494
err := s.orgService.AddOrgUser(ctx, cmd)
9595
if err != nil && !errors.Is(err, org.ErrOrgNotFound) {
96-
ctxLogger.Error("Failed to update active org for user", "id", id.ID, "error", err)
96+
ctxLogger.Error("Failed to update active org for user", "error", err)
9797
return err
9898
}
9999
}
100100

101101
// delete any removed org roles
102102
for _, orgID := range deleteOrgIds {
103-
ctxLogger.Debug("Removing user's organization membership as part of syncing with OAuth login", "id", id.ID, "orgId", orgID)
103+
ctxLogger.Debug("Removing user's organization membership as part of syncing with OAuth login", "orgId", orgID)
104104
cmd := &org.RemoveOrgUserCommand{OrgID: orgID, UserID: userID}
105105
if err := s.orgService.RemoveOrgUser(ctx, cmd); err != nil {
106-
ctxLogger.Error("Failed to remove user from org", "id", id.ID, "orgId", orgID, "error", err)
106+
ctxLogger.Error("Failed to remove user from org", "orgId", orgID, "error", err)
107107
if errors.Is(err, org.ErrLastOrgAdmin) {
108108
continue
109109
}
@@ -112,7 +112,7 @@ func (s *OrgSync) SyncOrgRolesHook(ctx context.Context, id *authn.Identity, _ *a
112112
}
113113

114114
if err := s.accessControl.DeleteUserPermissions(ctx, orgID, cmd.UserID); err != nil {
115-
ctxLogger.Error("Failed to delete permissions for user", "id", id.ID, "orgId", orgID, "error", err)
115+
ctxLogger.Error("Failed to delete permissions for user", "orgId", orgID, "error", err)
116116
}
117117
}
118118

0 commit comments

Comments
 (0)