-
Notifications
You must be signed in to change notification settings - Fork 2
/
caddyfile.go
119 lines (101 loc) · 2.57 KB
/
caddyfile.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
package caddydiscord
import (
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
)
// parseCaddyfileGlobalOption implements caddyfile.Unmarshaler.
func parseCaddyfileGlobalOption(d *caddyfile.Dispenser, _ any) (any, error) {
dpApp := new(DiscordPortalApp)
for d.Next() {
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "client_id":
if d.NextArg() {
dpApp.ClientID = d.Val()
}
if d.NextArg() {
return nil, d.ArgErr()
}
case "redirect":
if d.NextArg() {
dpApp.RedirectURL = d.Val()
}
if d.NextArg() {
return nil, d.ArgErr()
}
case "client_secret":
if d.NextArg() {
dpApp.ClientSecret = d.Val()
}
if d.NextArg() {
return nil, d.ArgErr()
}
case "realm":
realmBuilder := NewRealmBuilder()
if d.NextArg() {
realmBuilder.Name(d.Val())
//ag.Ref = d.Val()
}
for subNesting := d.Nesting(); d.NextBlock(subNesting); {
switch d.Val() {
case "guild":
if !d.NextArg() {
return nil, d.Errf("unrecognized subdirective '%s'", d.Val())
}
guildID := d.Val()
for subSubNesting := d.Nesting(); d.NextBlock(subSubNesting); {
switch d.Val() {
case "role":
if d.NextArg() {
realmBuilder.AllowGuildRole(guildID, d.Val())
}
if d.NextArg() {
return nil, d.ArgErr()
}
case "user":
if d.NextArg() {
realmBuilder.AllowGuildMember(guildID, d.Val())
}
if d.NextArg() {
return nil, d.ArgErr()
}
case "*":
realmBuilder.AllowAllGuildMembers(guildID)
if d.NextArg() {
return nil, d.ArgErr()
}
break
default:
return nil, d.Errf("unrecognized subdirective '%s'", d.Val())
}
}
case "user":
if d.NextArg() {
realmBuilder.AllowDiscordUser(d.Val())
}
if d.NextArg() {
return nil, d.ArgErr()
}
case "*":
// Anyone with a Discord Account...
realmBuilder.AllowAllDiscordUsers()
if d.NextArg() {
return nil, d.ArgErr()
}
break
default:
return nil, d.Errf("unrecognized subdirective '%s'", d.Val())
}
}
dpApp.Realms = append(dpApp.Realms, realmBuilder.Build())
default:
return nil, d.Errf("unrecognized subdirective '%s'", d.Val())
}
}
}
return httpcaddyfile.App{
Name: "discord",
Value: caddyconfig.JSON(dpApp, nil),
}, nil
}