forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode.go
44 lines (37 loc) · 801 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-workflows/v3/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 (m Modes) GetMode(authorisation string) (Mode, bool) {
if m[SSO] && strings.HasPrefix(authorisation, sso.Prefix) {
return SSO, true
}
if m[Client] && (strings.HasPrefix(authorisation, "Bearer ") || strings.HasPrefix(authorisation, "Basic ")) {
return Client, true
}
if m[Server] {
return Server, true
}
return "", false
}