Skip to content

Commit c981070

Browse files
committed
Runtime parameter cleanup and after hook improvements. (#248)
1 parent 261e920 commit c981070

18 files changed

+1399
-732
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
1212
- Lua runtime token generator function now returns a second value representing the token's expiry.
1313
- Add local cache for in-memory storage to the Lua runtime.
1414
- Graceful server shutdown and match termination.
15+
- Expose incoming request data in runtime after hooks.
1516

1617
### Changed
1718
- Improved Postgres compatibility on TIMESTAMPTZ types.

runtime/runtime.go

Lines changed: 126 additions & 114 deletions
Large diffs are not rendered by default.

server/api_account.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,11 @@ func (s *ApiServer) GetAccount(ctx context.Context, in *empty.Empty) (*api.Accou
4444

4545
// Extract request information and execute the hook.
4646
clientIP, clientPort := extractClientAddress(s.logger, ctx)
47-
result, err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
47+
err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort)
4848
if err != nil {
4949
return nil, status.Error(code, err.Error())
5050
}
51-
if result == nil {
52-
// If result is nil, requested resource is disabled.
53-
s.logger.Warn("Intercepted a disabled resource.", zap.Any("resource", fullMethod), zap.String("uid", userID.String()))
54-
return nil, status.Error(codes.NotFound, "Requested resource was not found.")
55-
}
56-
in = result
51+
// Empty input never overridden.
5752

5853
// Stats measurement end boundary.
5954
span.End()
@@ -143,7 +138,7 @@ func (s *ApiServer) UpdateAccount(ctx context.Context, in *api.UpdateAccountRequ
143138

144139
// Extract request information and execute the hook.
145140
clientIP, clientPort := extractClientAddress(s.logger, ctx)
146-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
141+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
147142

148143
// Stats measurement end boundary.
149144
span.End()

server/api_authenticate.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (s *ApiServer) AuthenticateCustom(ctx context.Context, in *api.Authenticate
103103

104104
// Extract request information and execute the hook.
105105
clientIP, clientPort := extractClientAddress(s.logger, ctx)
106-
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session)
106+
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in)
107107

108108
// Stats measurement end boundary.
109109
span.End()
@@ -178,7 +178,7 @@ func (s *ApiServer) AuthenticateDevice(ctx context.Context, in *api.Authenticate
178178

179179
// Extract request information and execute the hook.
180180
clientIP, clientPort := extractClientAddress(s.logger, ctx)
181-
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session)
181+
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in)
182182

183183
// Stats measurement end boundary.
184184
span.End()
@@ -260,7 +260,7 @@ func (s *ApiServer) AuthenticateEmail(ctx context.Context, in *api.AuthenticateE
260260

261261
// Extract request information and execute the hook.
262262
clientIP, clientPort := extractClientAddress(s.logger, ctx)
263-
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session)
263+
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in)
264264

265265
// Stats measurement end boundary.
266266
span.End()
@@ -336,7 +336,7 @@ func (s *ApiServer) AuthenticateFacebook(ctx context.Context, in *api.Authentica
336336

337337
// Extract request information and execute the hook.
338338
clientIP, clientPort := extractClientAddress(s.logger, ctx)
339-
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session)
339+
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in)
340340

341341
// Stats measurement end boundary.
342342
span.End()
@@ -419,7 +419,7 @@ func (s *ApiServer) AuthenticateGameCenter(ctx context.Context, in *api.Authenti
419419

420420
// Extract request information and execute the hook.
421421
clientIP, clientPort := extractClientAddress(s.logger, ctx)
422-
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session)
422+
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in)
423423

424424
// Stats measurement end boundary.
425425
span.End()
@@ -490,7 +490,7 @@ func (s *ApiServer) AuthenticateGoogle(ctx context.Context, in *api.Authenticate
490490

491491
// Extract request information and execute the hook.
492492
clientIP, clientPort := extractClientAddress(s.logger, ctx)
493-
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session)
493+
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in)
494494

495495
// Stats measurement end boundary.
496496
span.End()
@@ -565,7 +565,7 @@ func (s *ApiServer) AuthenticateSteam(ctx context.Context, in *api.AuthenticateS
565565

566566
// Extract request information and execute the hook.
567567
clientIP, clientPort := extractClientAddress(s.logger, ctx)
568-
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session)
568+
fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in)
569569

570570
// Stats measurement end boundary.
571571
span.End()

server/api_channel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (s *ApiServer) ListChannelMessages(ctx context.Context, in *api.ListChannel
9999

100100
// Extract request information and execute the hook.
101101
clientIP, clientPort := extractClientAddress(s.logger, ctx)
102-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, messageList)
102+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, messageList, in)
103103

104104
// Stats measurement end boundary.
105105
span.End()

server/api_friend.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,11 @@ func (s *ApiServer) ListFriends(ctx context.Context, in *empty.Empty) (*api.Frie
4343

4444
// Extract request information and execute the hook.
4545
clientIP, clientPort := extractClientAddress(s.logger, ctx)
46-
result, err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
46+
err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort)
4747
if err != nil {
4848
return nil, status.Error(code, err.Error())
4949
}
50-
if result == nil {
51-
// If result is nil, requested resource is disabled.
52-
s.logger.Warn("Intercepted a disabled resource.", zap.Any("resource", fullMethod), zap.String("uid", userID.String()))
53-
return nil, status.Error(codes.NotFound, "Requested resource was not found.")
54-
}
55-
in = result
50+
// Empty input never overridden.
5651

5752
// Stats measurement end boundary.
5853
span.End()
@@ -163,7 +158,7 @@ func (s *ApiServer) AddFriends(ctx context.Context, in *api.AddFriendsRequest) (
163158

164159
// Extract request information and execute the hook.
165160
clientIP, clientPort := extractClientAddress(s.logger, ctx)
166-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
161+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
167162

168163
// Stats measurement end boundary.
169164
span.End()
@@ -252,7 +247,7 @@ func (s *ApiServer) DeleteFriends(ctx context.Context, in *api.DeleteFriendsRequ
252247

253248
// Extract request information and execute the hook.
254249
clientIP, clientPort := extractClientAddress(s.logger, ctx)
255-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
250+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
256251

257252
// Stats measurement end boundary.
258253
span.End()
@@ -340,7 +335,7 @@ func (s *ApiServer) BlockFriends(ctx context.Context, in *api.BlockFriendsReques
340335

341336
// Extract request information and execute the hook.
342337
clientIP, clientPort := extractClientAddress(s.logger, ctx)
343-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
338+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
344339

345340
// Stats measurement end boundary.
346341
span.End()
@@ -398,7 +393,7 @@ func (s *ApiServer) ImportFacebookFriends(ctx context.Context, in *api.ImportFac
398393

399394
// Extract request information and execute the hook.
400395
clientIP, clientPort := extractClientAddress(s.logger, ctx)
401-
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
396+
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
402397

403398
// Stats measurement end boundary.
404399
span.End()

server/api_group.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (s *ApiServer) CreateGroup(ctx context.Context, in *api.CreateGroupRequest)
8181

8282
// Extract request information and execute the hook.
8383
clientIP, clientPort := extractClientAddress(s.logger, ctx)
84-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, group)
84+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, group, in)
8585

8686
// Stats measurement end boundary.
8787
span.End()
@@ -164,7 +164,7 @@ func (s *ApiServer) UpdateGroup(ctx context.Context, in *api.UpdateGroupRequest)
164164

165165
// Extract request information and execute the hook.
166166
clientIP, clientPort := extractClientAddress(s.logger, ctx)
167-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
167+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
168168

169169
// Stats measurement end boundary.
170170
span.End()
@@ -231,7 +231,7 @@ func (s *ApiServer) DeleteGroup(ctx context.Context, in *api.DeleteGroupRequest)
231231

232232
// Extract request information and execute the hook.
233233
clientIP, clientPort := extractClientAddress(s.logger, ctx)
234-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
234+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
235235

236236
// Stats measurement end boundary.
237237
span.End()
@@ -300,7 +300,7 @@ func (s *ApiServer) JoinGroup(ctx context.Context, in *api.JoinGroupRequest) (*e
300300

301301
// Extract request information and execute the hook.
302302
clientIP, clientPort := extractClientAddress(s.logger, ctx)
303-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
303+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
304304

305305
// Stats measurement end boundary.
306306
span.End()
@@ -367,7 +367,7 @@ func (s *ApiServer) LeaveGroup(ctx context.Context, in *api.LeaveGroupRequest) (
367367

368368
// Extract request information and execute the hook.
369369
clientIP, clientPort := extractClientAddress(s.logger, ctx)
370-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
370+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
371371

372372
// Stats measurement end boundary.
373373
span.End()
@@ -449,7 +449,7 @@ func (s *ApiServer) AddGroupUsers(ctx context.Context, in *api.AddGroupUsersRequ
449449

450450
// Extract request information and execute the hook.
451451
clientIP, clientPort := extractClientAddress(s.logger, ctx)
452-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
452+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
453453

454454
// Stats measurement end boundary.
455455
span.End()
@@ -528,7 +528,7 @@ func (s *ApiServer) KickGroupUsers(ctx context.Context, in *api.KickGroupUsersRe
528528

529529
// Extract request information and execute the hook.
530530
clientIP, clientPort := extractClientAddress(s.logger, ctx)
531-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
531+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
532532

533533
// Stats measurement end boundary.
534534
span.End()
@@ -608,7 +608,7 @@ func (s *ApiServer) PromoteGroupUsers(ctx context.Context, in *api.PromoteGroupU
608608

609609
// Extract request information and execute the hook.
610610
clientIP, clientPort := extractClientAddress(s.logger, ctx)
611-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
611+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
612612

613613
// Stats measurement end boundary.
614614
span.End()
@@ -670,7 +670,7 @@ func (s *ApiServer) ListGroupUsers(ctx context.Context, in *api.ListGroupUsersRe
670670

671671
// Extract request information and execute the hook.
672672
clientIP, clientPort := extractClientAddress(s.logger, ctx)
673-
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groupUsers)
673+
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groupUsers, in)
674674

675675
// Stats measurement end boundary.
676676
span.End()
@@ -732,7 +732,7 @@ func (s *ApiServer) ListUserGroups(ctx context.Context, in *api.ListUserGroupsRe
732732

733733
// Extract request information and execute the hook.
734734
clientIP, clientPort := extractClientAddress(s.logger, ctx)
735-
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, userGroups)
735+
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, userGroups, in)
736736

737737
// Stats measurement end boundary.
738738
span.End()
@@ -793,7 +793,7 @@ func (s *ApiServer) ListGroups(ctx context.Context, in *api.ListGroupsRequest) (
793793

794794
// Extract request information and execute the hook.
795795
clientIP, clientPort := extractClientAddress(s.logger, ctx)
796-
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groups)
796+
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groups, in)
797797

798798
// Stats measurement end boundary.
799799
span.End()

server/api_leaderboard.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (s *ApiServer) DeleteLeaderboardRecord(ctx context.Context, in *api.DeleteL
8585

8686
// Extract request information and execute the hook.
8787
clientIP, clientPort := extractClientAddress(s.logger, ctx)
88-
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{})
88+
fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in)
8989

9090
// Stats measurement end boundary.
9191
span.End()
@@ -164,7 +164,7 @@ func (s *ApiServer) ListLeaderboardRecords(ctx context.Context, in *api.ListLead
164164

165165
// Extract request information and execute the hook.
166166
clientIP, clientPort := extractClientAddress(s.logger, ctx)
167-
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records)
167+
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records, in)
168168

169169
// Stats measurement end boundary.
170170
span.End()
@@ -235,7 +235,7 @@ func (s *ApiServer) WriteLeaderboardRecord(ctx context.Context, in *api.WriteLea
235235

236236
// Extract request information and execute the hook.
237237
clientIP, clientPort := extractClientAddress(s.logger, ctx)
238-
fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, record)
238+
fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, record, in)
239239

240240
// Stats measurement end boundary.
241241
span.End()
@@ -313,7 +313,7 @@ func (s *ApiServer) ListLeaderboardRecordsAroundOwner(ctx context.Context, in *a
313313

314314
// Extract request information and execute the hook.
315315
clientIP, clientPort := extractClientAddress(s.logger, ctx)
316-
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, recordList)
316+
fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, recordList, in)
317317

318318
// Stats measurement end boundary.
319319
span.End()

0 commit comments

Comments
 (0)