-
Notifications
You must be signed in to change notification settings - Fork 787
/
auth_config_service.go
56 lines (47 loc) · 1.5 KB
/
auth_config_service.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package auth
// Config gets the AuthConfig from the service
func (s *AuthConfigService) Config() *AuthConfig {
if s.config == nil {
s.config = &AuthConfig{}
}
return s.config
}
// SetConfig sets the AuthConfig object
func (s *AuthConfigService) SetConfig(c *AuthConfig) {
s.config = c
}
// SaveUserAuth saves the given user auth for the server url
func (s *AuthConfigService) SaveUserAuth(url string, userAuth *UserAuth) error {
config := s.config
config.SetUserAuth(url, userAuth)
user := userAuth.Username
if user != "" {
config.DefaultUsername = user
}
// Set Pipeline user once only.
if config.PipeLineUsername == "" {
config.PipeLineUsername = user
config.PipeLineServer = url
}
config.CurrentServer = url
return s.saver.SaveConfig(s.config)
}
// DeleteServer removes the given server from the configuration
func (s *AuthConfigService) DeleteServer(url string) error {
s.config.DeleteServer(url)
return s.saver.SaveConfig(s.config)
}
// LoadConfig loads the configuration from the users JX config directory
func (s *AuthConfigService) LoadConfig() (*AuthConfig, error) {
var err error
s.config, err = s.saver.LoadConfig()
return s.config, err
}
// SaveConfig saves the configuration to disk
func (s *AuthConfigService) SaveConfig() error {
return s.saver.SaveConfig(s.Config())
}
// NewAuthConfigService generates a AuthConfigService with a custom saver. This should not be used directly
func NewAuthConfigService(saver ConfigSaver) *AuthConfigService {
return &AuthConfigService{saver: saver}
}