Skip to content

Commit

Permalink
fix: violation of users_email_key on pool users creation
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed Jul 18, 2022
1 parent 9ff99e6 commit 70c09af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions internal/webhooks/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ func (p *processor) Serve(amqpUrl, channel string) error {
for d := range msgs {
err := p.handler(d.Body)
if err != nil {
sentry.CaptureException(err)
sentry.CaptureEvent(&sentry.Event{
Level: sentry.LevelError,
Contexts: map[string]interface{}{
"message": string(d.Body),
},
Message: err.Error(),
})

if errors.Is(err, ErrInvalidWebhook) {
goto ACK
Expand Down Expand Up @@ -145,18 +151,18 @@ func (p *processor) handler(data []byte) error {
// Marshal the payload to the expected format for the github processor
// FUTURE: rework it
b, err := json.Marshal(md.Payload)
if err != nil {
if err != nil {
log.Error().Err(err).Msg("Failed to marshal payload")
return err
}
return err
}

return p.githubHandler(b)
}

return p.duoHandler(data)
}

// githubHandler is the processor for the github webhooks.
// githubHandler is the processor for the github webhooks.
func (p *processor) githubHandler(data []byte) error {
webhookPayload := &GithubSponsorshipWebhook{}
if err := json.Unmarshal(data, &webhookPayload); err != nil {
Expand Down Expand Up @@ -207,7 +213,7 @@ func (p *processor) githubHandler(data []byte) error {
return err
}

// duoHandler is the processor for the duo webhooks.
// duoHandler is the processor for the duo webhooks.
func (p *processor) duoHandler(data []byte) error {
mdDuo := &duoapi.Webhook{}
if err := json.Unmarshal(data, &mdDuo); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/webhooks/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (p *userProcessor) Create(u *duoapi.User, metadata *duoapi.WebhookMetadata)
SetEmail(u.Email).
SetIsStaff(u.Staff).
SetNillableUsualFirstName(&u.UsualFirstName).
OnConflictColumns(user.FieldDuoID).
OnConflictColumns(user.FieldDuoID, user.FieldDuoLogin, user.FieldEmail).
UpdateNewValues().
Exec(p.ctx)
}
Expand Down

0 comments on commit 70c09af

Please sign in to comment.