-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_chat.go
36 lines (32 loc) · 1.06 KB
/
common_chat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package cmd
import (
"github.com/jenkins-x/jx/pkg/auth"
"github.com/jenkins-x/jx/pkg/chats"
"github.com/jenkins-x/jx/pkg/config"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/jenkins-x/jx/pkg/log"
)
func (o *CommonOptions) createChatProvider(chatConfig *config.ChatConfig) (chats.ChatProvider, error) {
u := chatConfig.URL
if u == "" {
return nil, nil
}
authConfigSvc, err := o.CreateChatAuthConfigService()
if err != nil {
return nil, err
}
config := authConfigSvc.Config()
server := config.GetOrCreateServer(u)
userAuth, err := config.PickServerUserAuth(server, "user to access the chat service at "+u, o.BatchMode, "", o.In, o.Out, o.Err)
if err != nil {
return nil, err
}
return chats.CreateChatProvider(server.Kind, server, userAuth, o.BatchMode)
}
func (o *CommonOptions) CreateChatAuthConfigService() (auth.AuthConfigService, error) {
secrets, err := o.LoadPipelineSecrets(kube.ValueKindChat, "")
if err != nil {
log.Warnf("The current user cannot query pipeline chat secrets: %s", err)
}
return o.Factory.CreateChatAuthConfigService(secrets)
}