-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
types.go
212 lines (182 loc) · 5.86 KB
/
types.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package config
import (
"fmt"
"log/slog"
"net/url"
"strings"
"text/template"
"time"
"golang.org/x/oauth2"
)
type Config struct {
ConfigFile string `koanf:"config"`
Debug Debug `koanf:"debug"`
Log Log `koanf:"log"`
HTTP HTTP `koanf:"http"`
OpenVpn OpenVpn `koanf:"openvpn"`
OAuth2 OAuth2 `koanf:"oauth2"`
}
type HTTP struct {
Listen string `koanf:"listen"`
CertFile string `koanf:"cert"`
KeyFile string `koanf:"key"`
TLS bool `koanf:"tls"`
BaseURL *url.URL `koanf:"baseurl"`
Secret Secret `koanf:"secret"`
CallbackTemplate *template.Template `koanf:"template"`
Check HTTPCheck `koanf:"check"`
EnableProxyHeaders bool `koanf:"enable-proxy-headers"`
AssetPath string `koanf:"assets-path"`
}
type HTTPCheck struct {
IPAddr bool `koanf:"ipaddr"`
}
type Log struct {
Format string `koanf:"format"`
Level slog.Level `koanf:"level"`
VPNClientIP bool `koanf:"vpn-client-ip"`
}
type OpenVpn struct {
Addr *url.URL `koanf:"addr"`
Password Secret `koanf:"password"`
Bypass OpenVpnBypass `koanf:"bypass"`
AuthTokenUser bool `koanf:"auth-token-user"`
AuthPendingTimeout time.Duration `koanf:"auth-pending-timeout"`
CommonName OpenVPNCommonName `koanf:"common-name"`
Passthrough OpenVPNPassthrough `koanf:"pass-through"`
}
type OpenVpnBypass struct {
CommonNames StringSlice `koanf:"common-names"`
}
type OpenVPNCommonName struct {
EnvironmentVariableName string `koanf:"environment-variable-name"`
Mode OpenVPNCommonNameMode `koanf:"mode"`
}
type OAuth2 struct {
AuthStyle OAuth2AuthStyle `koanf:"auth-style"`
AuthorizeParams string `koanf:"authorize-params"`
Client OAuth2Client `koanf:"client"`
Endpoints OAuth2Endpoints `koanf:"endpoint"`
Issuer *url.URL `koanf:"issuer"`
Nonce bool `koanf:"nonce"`
PKCE bool `koanf:"pkce"`
Provider string `koanf:"provider"`
Refresh OAuth2Refresh `koanf:"refresh"`
Scopes StringSlice `koanf:"scopes"`
Validate OAuth2Validate `koanf:"validate"`
}
type OAuth2Client struct {
ID string `koanf:"id"`
Secret Secret `koanf:"secret"`
}
type OAuth2Endpoints struct {
Discovery *url.URL `koanf:"discovery"`
Auth *url.URL `koanf:"auth"`
Token *url.URL `koanf:"token"`
}
type OAuth2Validate struct {
Acr StringSlice `koanf:"acr"`
Groups StringSlice `koanf:"groups"`
Roles StringSlice `koanf:"roles"`
IPAddr bool `koanf:"ipaddr"`
Issuer bool `koanf:"issuer"`
CommonName string `koanf:"common-name"`
CommonNameCaseSensitive bool `koanf:"common-name-case-sensitive"`
}
type OAuth2Refresh struct {
Enabled bool `koanf:"enabled"`
Expires time.Duration `koanf:"expires"`
Secret Secret `koanf:"secret"`
UseSessionID bool `koanf:"use-session-id"`
ValidateUser bool `koanf:"validate-user"`
}
type OpenVPNPassthrough struct {
Enabled bool `koanf:"enabled"`
Address *url.URL `koanf:"address"`
Password Secret `koanf:"password"`
SocketMode uint `koanf:"socket-mode"`
SocketGroup string `koanf:"socket-group"`
}
type Debug struct {
Pprof bool `koanf:"pprof"`
Listen string `koanf:"listen"`
}
type OpenVPNCommonNameMode int
const (
CommonNameModePlain OpenVPNCommonNameMode = iota
CommonNameModeOmit
CommonNameModeOmitValue = "-"
)
//goland:noinspection GoMixedReceiverTypes
func (s OpenVPNCommonNameMode) String() string {
text, err := s.MarshalText()
if err != nil {
panic(err)
}
return string(text)
}
//goland:noinspection GoMixedReceiverTypes
func (s OpenVPNCommonNameMode) MarshalText() ([]byte, error) {
switch s {
case CommonNameModePlain:
return []byte("plain"), nil
case CommonNameModeOmit:
return []byte("omit"), nil
default:
return nil, fmt.Errorf("unknown identitfer %d", s)
}
}
//goland:noinspection GoMixedReceiverTypes
func (s *OpenVPNCommonNameMode) UnmarshalText(text []byte) error {
config := strings.ToLower(string(text))
switch config {
case "plain":
*s = CommonNameModePlain
case "omit":
*s = CommonNameModeOmit
default:
return fmt.Errorf("invalid value %s", config)
}
return nil
}
type OAuth2AuthStyle oauth2.AuthStyle
//goland:noinspection GoMixedReceiverTypes
func (s OAuth2AuthStyle) String() string {
text, err := s.MarshalText()
if err != nil {
panic(err)
}
return string(text)
}
//goland:noinspection GoMixedReceiverTypes
func (s OAuth2AuthStyle) AuthStyle() oauth2.AuthStyle {
return oauth2.AuthStyle(s)
}
//goland:noinspection GoMixedReceiverTypes
func (s OAuth2AuthStyle) MarshalText() ([]byte, error) {
switch s {
case OAuth2AuthStyle(oauth2.AuthStyleAutoDetect):
return []byte("AuthStyleAutoDetect"), nil
case OAuth2AuthStyle(oauth2.AuthStyleInParams):
return []byte("AuthStyleInParams"), nil
case OAuth2AuthStyle(oauth2.AuthStyleInHeader):
return []byte("AuthStyleInHeader"), nil
default:
return nil, fmt.Errorf("unknown auth-style %d", s)
}
}
//goland:noinspection GoMixedReceiverTypes
func (s *OAuth2AuthStyle) UnmarshalText(text []byte) error {
config := strings.ToLower(string(text))
switch config {
case strings.ToLower("AuthStyleAutoDetect"):
*s = OAuth2AuthStyle(oauth2.AuthStyleAutoDetect)
case strings.ToLower("AuthStyleInParams"):
*s = OAuth2AuthStyle(oauth2.AuthStyleInParams)
case strings.ToLower("AuthStyleInHeader"):
*s = OAuth2AuthStyle(oauth2.AuthStyleInHeader)
default:
return fmt.Errorf("unknown auth-style %d", s)
}
return nil
}