forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
52 lines (46 loc) · 931 Bytes
/
server.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
package auth
import (
"fmt"
"sort"
"github.com/jenkins-x/jx/pkg/util"
)
func (s *AuthServer) Label() string {
if s.Name != "" {
return s.Name
}
return s.URL
}
func (s *AuthServer) Description() string {
if s.Name != "" {
return s.Name + " at " + s.URL
}
return s.URL
}
func (s *AuthServer) DeleteUser(username string) error {
idx := -1
for i, user := range s.Users {
if user.Username == username {
idx = i
break
}
}
if idx < 0 {
if len(s.Users) == 0 {
return fmt.Errorf("Cannot remote user %s as there are no users for this server", username)
}
return util.InvalidArg(username, s.GetUsernames())
}
s.Users = append(s.Users[0:idx], s.Users[idx+1:]...)
return nil
}
func (s *AuthServer) GetUsernames() []string {
answer := []string{}
for _, user := range s.Users {
name := user.Username
if name != "" {
answer = append(answer, name)
}
}
sort.Strings(answer)
return answer
}