Skip to content

Commit

Permalink
fix: rename default notification template file (#21)
Browse files Browse the repository at this point in the history
- rename default notification template file
- add additional ctx information to notifier logs
- log failed grant revocations only when there are failures
  • Loading branch information
bsushmith authored Apr 18, 2023
1 parent a5e0740 commit 93e2973
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
4 changes: 3 additions & 1 deletion core/grant/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ func (s *Service) BulkRevoke(ctx context.Context, filter domain.RevokeGrantsFilt
result = append(result, grant)
if len(result) == totalRequests {
s.logger.Info("successful grant revocation", "count", len(successRevoke), "ids", successRevoke)
s.logger.Info("failed grant revocation", "count", len(failedRevoke), "ids", failedRevoke)
if len(failedRevoke) > 0 {
s.logger.Info("failed grant revocation", "count", len(failedRevoke), "ids", failedRevoke)
}
return result, nil
}
}
Expand Down
12 changes: 4 additions & 8 deletions jobs/grant_expiration_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ func (h *handler) RevokeExpiredGrants(ctx context.Context) error {
return err
}

h.logger.Info("successful grant revocation",
"count", len(successRevoke),
"ids", successRevoke,
)
h.logger.Info("failed grant revocation",
"count", len(failedRevoke),
"ids", failedRevoke,
)
h.logger.Info("successful grant revocation", "count", len(successRevoke), "ids", successRevoke)
if len(failedRevoke) > 0 {
h.logger.Info("failed grant revocation", "count", len(failedRevoke), "ids", failedRevoke)
}

return nil
}
6 changes: 3 additions & 3 deletions plugins/notifiers/slack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (n *Notifier) Notify(items []domain.Notification) []error {
}

if err := n.sendMessage(slackID, msg); err != nil {
errs = append(errs, err)
errs = append(errs, fmt.Errorf("error sending message to user %s - %s", item.User, err))
}
}

Expand Down Expand Up @@ -125,10 +125,10 @@ func (n *Notifier) findSlackIDByEmail(email string) (string, error) {

result, err := n.sendRequest(req)
if err != nil {
return "", err
return "", fmt.Errorf("error finding slack id for email %s - %s", email, err)
}
if result.User == nil {
return "", errors.New("user not found")
return "", errors.New(fmt.Sprintf("user not found: %s", email))
}

n.slackIDCache[email] = result.User.ID
Expand Down
5 changes: 4 additions & 1 deletion plugins/notifiers/slack/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func (s *ClientTestSuite) TestNotify() {
slackAPIResponse := `{"ok":false,"error":"users_not_found"}`
resp := &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader([]byte(slackAPIResponse)))}
s.mockHttpClient.On("Do", mock.Anything).Return(resp, nil)
expectedErrs := []error{errors.New("users_not_found"), errors.New("EOF")}
expectedErrs := []error{
errors.New("error finding slack id for email test-user@abc.com - users_not_found"),
errors.New("error sending message to user test-user@abc.com - EOF"),
}

notifications := []domain.Notification{
{
Expand Down

0 comments on commit 93e2973

Please sign in to comment.