Skip to content

Commit

Permalink
fix proto
Browse files Browse the repository at this point in the history
  • Loading branch information
senk8 committed Feb 22, 2024
1 parent 9bda66a commit 614d836
Show file tree
Hide file tree
Showing 30 changed files with 1,610 additions and 472 deletions.
7 changes: 4 additions & 3 deletions pkg/server/alert/alert_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,12 @@ func (a *AlertService) TestNotification(ctx context.Context, req *alert.TestNoti
return &empty.Empty{}, nil
}

func (a *AlertService) RequestNotification(ctx context.Context, req *alert.SendNotificationRequest) (*empty.Empty, error) {
func (a *AlertService) RequestAuthzNotification(ctx context.Context, req *alert.RequestAuthzNotificationRequest) (*empty.Empty, error) {
if err := req.Validate(); err != nil {
return nil, err
}
notification, err := a.repository.GetNotification(ctx, req.ProjectId, req.NotificationId)
notifications, err := a.repository.ListNotification(ctx, req.ProjectId, "slack", 0, time.Now().Unix())
notification := &(*notifications)[0]
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return &empty.Empty{}, nil
Expand All @@ -232,7 +233,7 @@ func (a *AlertService) RequestNotification(ctx context.Context, req *alert.SendN
}
switch notification.Type {
case "slack":
err = a.sendSlackRequestNotification(ctx, a.baseURL, notification.NotifySetting, a.defaultLocale, "s", "k")
err = a.sendSlackRequestAuthzNotification(ctx, a.baseURL, notification.NotifySetting, a.defaultLocale, req.ProjectName, req.UserName)
if err != nil {
a.logger.Errorf(ctx, "Error occured when sending test slack notification. err: %v", err)
return nil, err
Expand Down
28 changes: 14 additions & 14 deletions pkg/server/alert/alert_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ const (
- Remove the root cause of the problem
- If it is an intentional setup/operation and the risk is small, archive it
- If the nature of the problem is not urgent and immediate action is difficult, set a target deadline and PEND`
slackNotificationAttachmentJa = "その他、%d件すべてのFindingは <%s/alert/alert?project_id=%d&from=slack|アラート画面> からご確認ください。"
slackNotificationAttachmentEn = "Please check all %d Findings from <%s/alert/alert?project_id=%d&from=slack|Alert screen>."
slackNotificationTestMessageJa = "RISKENからのテスト通知です"
slackNotificationTestMessageEn = "This is a test notification from RISKEN"
slackRequestNotificationMessageJa = `%sさんが
slackNotificationAttachmentJa = "その他、%d件すべてのFindingは <%s/alert/alert?project_id=%d&from=slack|アラート画面> からご確認ください。"
slackNotificationAttachmentEn = "Please check all %d Findings from <%s/alert/alert?project_id=%d&from=slack|Alert screen>."
slackNotificationTestMessageJa = "RISKENからのテスト通知です"
slackNotificationTestMessageEn = "This is a test notification from RISKEN"
slackRequestAuthzNotificationMessageJa = `%sさんが
あなたのプロジェクト%sへの権限を申請しました。
問題なければ次のリンクから%sさんを追加してください。`
slackRequestNotificationMessageEn = `%s %s %s`
slackRequestAuthzNotificationMessageEn = `%s %s %s`
)

func (a *AlertService) sendSlackNotification(
Expand Down Expand Up @@ -115,7 +115,7 @@ func (a *AlertService) sendSlackTestNotification(ctx context.Context, url, notif
return nil
}

func (a *AlertService) sendSlackRequestNotification(ctx context.Context, url, notifySetting, defaultLocale, userName, projectName string) error {
func (a *AlertService) sendSlackRequestAuthzNotification(ctx context.Context, url, notifySetting, defaultLocale, userName, projectName string) error {
var setting slackNotifySetting
if err := json.Unmarshal([]byte(notifySetting), &setting); err != nil {
return err
Expand All @@ -132,13 +132,13 @@ func (a *AlertService) sendSlackRequestNotification(ctx context.Context, url, no
}

if setting.WebhookURL != "" {
webhookMsg := getRequestWebhookMessage(setting.Data.Channel, locale, userName, projectName)
webhookMsg := getRequestAuthzWebhookMessage(setting.Data.Channel, locale, userName, projectName)
if err := slack.PostWebhook(setting.WebhookURL, webhookMsg); err != nil {
return fmt.Errorf("failed to send slack(webhookurl): %w", err)
}
} else if setting.ChannelID != "" {
if err := a.postMessageSlackWithRetry(ctx,
setting.ChannelID, slack.MsgOptionText(getRequestSlackMessageText(locale, userName, projectName), false)); err != nil {
setting.ChannelID, slack.MsgOptionText(getRequestAuthzSlackMessageText(locale, userName, projectName), false)); err != nil {
return fmt.Errorf("failed to send slack(postmessage): %w", err)
}
}
Expand Down Expand Up @@ -284,9 +284,9 @@ func getTestSlackMessageText(locale string) string {
return msgText
}

func getRequestWebhookMessage(channel, locale, userName, projectName string) *slack.WebhookMessage {
func getRequestAuthzWebhookMessage(channel, locale, userName, projectName string) *slack.WebhookMessage {
msg := slack.WebhookMessage{
Text: getRequestSlackMessageText(locale, userName, projectName),
Text: getRequestAuthzSlackMessageText(locale, userName, projectName),
}
// override message
if channel != "" {
Expand All @@ -295,13 +295,13 @@ func getRequestWebhookMessage(channel, locale, userName, projectName string) *sl
return &msg
}

func getRequestSlackMessageText(locale, userName, projectName string) string {
func getRequestAuthzSlackMessageText(locale, userName, projectName string) string {
var msgText string
switch locale {
case LocaleJa:
msgText = slackRequestNotificationMessageJa
msgText = slackRequestAuthzNotificationMessageJa
default:
msgText = slackRequestNotificationMessageEn
msgText = slackRequestAuthzNotificationMessageEn
}
return fmt.Sprintf(msgText, userName, projectName, userName)
}
Expand Down
4 changes: 2 additions & 2 deletions proto/alert/entity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 614d836

Please sign in to comment.