forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode.go
44 lines (37 loc) · 788 Bytes
/
mode.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
package auth
import (
"errors"
"strings"
"github.com/argoproj/argo/server/auth/sso"
)
type Modes map[Mode]bool
type Mode string
const (
Client Mode = "client"
Server Mode = "server"
SSO Mode = "sso"
)
func (m Modes) Add(value string) error {
switch value {
case "client", "server", "sso":
m[Mode(value)] = true
case "hybrid":
m[Client] = true
m[Server] = true
default:
return errors.New("invalid mode")
}
return nil
}
func GetMode(authorisation string) (Mode, error) {
if authorisation == "" {
return Server, nil
}
if strings.HasPrefix(authorisation, sso.Prefix) {
return SSO, nil
}
if strings.HasPrefix(authorisation, "Bearer ") || strings.HasPrefix(authorisation, "Basic ") {
return Client, nil
}
return "", errors.New("unrecognized token")
}