Skip to content

Commit

Permalink
fix: fix slack client initialization with multiple workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmatrhd committed Jul 23, 2024
1 parent 6355db6 commit d87a10b
Showing 1 changed file with 9 additions and 47 deletions.
56 changes: 9 additions & 47 deletions plugins/notifiers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,40 +89,28 @@ func NewMultiClient(notifiers *[]Config, logger log.Logger) (*NotifyManager, err
notifyManager := &NotifyManager{}
for _, notifier := range *notifiers {
if notifier.Provider == ProviderTypeSlack {

httpClient := &http.Client{Timeout: 10 * time.Second}

slackConfig, err := getSlackConfig(&notifier, notifier.Messages)
slackConfig, err := NewSlackConfig(&notifier)
if err != nil {
return nil, err

} else {
slackClient := slack.NewNotifier(slackConfig, httpClient, logger)
notifyManager.addClient(slackClient)
notifyManager.addNotifier(notifier)
}

httpClient := &http.Client{Timeout: 10 * time.Second}
slackClient := slack.NewNotifier(slackConfig, httpClient, logger)
notifyManager.addClient(slackClient)
notifyManager.addNotifier(notifier)
}
if notifier.Provider == ProviderTypeLark {

httpClient := &http.Client{Timeout: 10 * time.Second}

larkConfig, err := getLarkConfig(&notifier, notifier.Messages)
if err != nil {
return nil, err

} else {
larkClient := lark.NewNotifier(larkConfig, httpClient, logger)
notifyManager.addClient(larkClient)
notifyManager.addNotifier(notifier)
}

httpClient := &http.Client{Timeout: 10 * time.Second}
larkClient := lark.NewNotifier(larkConfig, httpClient, logger)
notifyManager.addClient(larkClient)
notifyManager.addNotifier(notifier)
}

}

return notifyManager, nil

}

func NewClient(config *Config, logger log.Logger) (Client, error) {
Expand Down Expand Up @@ -178,32 +166,6 @@ func NewSlackConfig(config *Config) (*slack.Config, error) {
return slackConfig, nil
}

func getSlackConfig(config *Config, messages domain.NotificationMessages) (*slack.Config, error) {
// validation
if config.AccessToken == "" {
return nil, errors.New("slack access token or workSpaceConfig must be provided")
}

var slackConfig *slack.Config
if config.AccessToken != "" {
workspaces := []slack.SlackWorkspace{
{
WorkspaceName: config.Provider,
AccessToken: config.AccessToken,
Criteria: config.Criteria,
},
}
slackConfig = &slack.Config{
Workspaces: workspaces,
Messages: messages,
}
return slackConfig, nil

}

return slackConfig, nil
}

func getLarkConfig(config *Config, messages domain.NotificationMessages) (*lark.Config, error) {
// validation
if config.ClientID == "" && config.ClientSecret == "" {
Expand Down

0 comments on commit d87a10b

Please sign in to comment.