Skip to content

Commit

Permalink
feat: log package in mobile webhooks (#2606)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbrm committed Jul 18, 2024
1 parent 7d05017 commit 0ad379f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 12 additions & 0 deletions services/skus/appstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ func (x *appStoreSrvNotification) shouldCancel() bool {
}
}

func (x *appStoreSrvNotification) ntfType() string {
return string(x.val.NotificationType)
}

func (x *appStoreSrvNotification) ntfSubType() string {
return string(x.val.Subtype)
}

func (x *appStoreSrvNotification) effect() string {
switch {
case x.shouldRenew():
Expand All @@ -139,6 +147,10 @@ func (x *appStoreSrvNotification) effect() string {
}
}

func (x *appStoreSrvNotification) pkg() string {
return x.val.Data.BundleID
}

func parseAppStoreSrvNotification(vrf *assnCertVerifier, spayload string) (*appStoreSrvNotification, error) {
certs, err := extractASSNCerts(spayload)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions services/skus/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ func handleWebhookPlayStoreH(w http.ResponseWriter, r *http.Request, svc *Servic
}

if err := svc.processPlayStoreNotification(ctx, ntf); err != nil {
l := lg.With().Str("ntf_type", ntf.ntfType()).Int("ntf_subtype", ntf.ntfSubType()).Str("ntf_effect", ntf.effect()).Logger()
l := lg.With().Str("ntf_type", ntf.ntfType()).Int("ntf_subtype", ntf.ntfSubType()).Str("ntf_effect", ntf.effect()).Str("ntf_package", ntf.pkg()).Logger()

switch {
case errors.Is(err, context.Canceled):
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func handleWebhookPlayStoreH(w http.ResponseWriter, r *http.Request, svc *Servic
msg = "processed play store notification"
}

lg.Info().Str("ntf_type", ntf.ntfType()).Int("ntf_subtype", ntf.ntfSubType()).Str("ntf_effect", ntf.effect()).Msg(msg)
lg.Info().Str("ntf_type", ntf.ntfType()).Int("ntf_subtype", ntf.ntfSubType()).Str("ntf_effect", ntf.effect()).Str("ntf_package", ntf.pkg()).Msg(msg)

return handlers.RenderContent(ctx, struct{}{}, w, http.StatusOK)
}
Expand Down Expand Up @@ -1126,7 +1126,7 @@ func handleWebhookAppStoreH(w http.ResponseWriter, r *http.Request, svc *Service
}

if err := svc.processAppStoreNotification(ctx, ntf); err != nil {
l := lg.With().Str("ntf_type", string(ntf.val.NotificationType)).Str("ntf_subtype", string(ntf.val.Subtype)).Str("ntf_effect", ntf.effect()).Logger()
l := lg.With().Str("ntf_type", ntf.ntfType()).Str("ntf_subtype", ntf.ntfSubType()).Str("ntf_effect", ntf.effect()).Str("ntf_package", ntf.pkg()).Logger()

switch {
case errors.Is(err, context.Canceled):
Expand Down Expand Up @@ -1176,7 +1176,7 @@ func handleWebhookAppStoreH(w http.ResponseWriter, r *http.Request, svc *Service
msg = "processed app store notification"
}

lg.Info().Str("ntf_type", string(ntf.val.NotificationType)).Str("ntf_subtype", string(ntf.val.Subtype)).Str("ntf_effect", ntf.effect()).Msg(msg)
lg.Info().Str("ntf_type", ntf.ntfType()).Str("ntf_subtype", ntf.ntfSubType()).Str("ntf_effect", ntf.effect()).Str("ntf_package", ntf.pkg()).Msg(msg)

return handlers.RenderContent(ctx, struct{}{}, w, http.StatusOK)
}
Expand Down
4 changes: 4 additions & 0 deletions services/skus/playstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func (x *playStoreDevNotification) effect() string {
}
}

func (x *playStoreDevNotification) pkg() string {
return x.PackageName
}

func (x *playStoreDevNotification) isBeforeCutoff() bool {
ems, err := x.EventTimeMilli.Int64()
if err != nil {
Expand Down

0 comments on commit 0ad379f

Please sign in to comment.