/
otp_legacy.go
62 lines (55 loc) · 1.26 KB
/
otp_legacy.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
package config
var _ = Schema.Add("OTPLegacyConfig", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"ratelimit": { "$ref": "#/$defs/OTPLegacyRatelimitConfig" }
}
}
`)
type OTPLegacyConfig struct {
Ratelimit *OTPLegacyRatelimitConfig `json:"ratelimit,omitempty"`
}
var _ = Schema.Add("OTPLegacyRatelimitConfig", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"failed_attempt": { "$ref": "#/$defs/OTPLegacyFailedAttemptConfig" }
}
}
`)
type OTPLegacyRatelimitConfig struct {
FailedAttempt *OTPLegacyFailedAttemptConfig `json:"failed_attempt,omitempty"`
}
var _ = Schema.Add("OTPLegacyFailedAttemptConfig", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": { "type": "boolean" },
"size": {
"type": "integer",
"minimum": 1,
"maximum": 10
},
"reset_period": { "$ref": "#/$defs/DurationString" }
}
}
`)
type OTPLegacyFailedAttemptConfig struct {
Enabled bool `json:"enabled,omitempty"`
Size int `json:"size,omitempty"`
ResetPeriod DurationString `json:"reset_period,omitempty"`
}
func (c *OTPLegacyFailedAttemptConfig) SetDefaults() {
if c.Enabled {
if c.Size == 0 {
c.Size = 5
}
if c.ResetPeriod == "" {
c.ResetPeriod = "20m"
}
}
}