-
Notifications
You must be signed in to change notification settings - Fork 27
/
models.go
173 lines (154 loc) · 3.64 KB
/
models.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
package testrunner
type BeforeHook struct {
Type BeforeHookType `json:"type"`
UserImport string `json:"user_import"`
CustomSQL BeforeHookCustomSQL `json:"custom_sql"`
}
var _ = TestCaseSchema.Add("AuthgearYAMLSource", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"extend": { "type": "string", "description": "Path to the base authgear.yaml" },
"override": { "type": "string", "description": "Inline snippet to override the base authgear.yaml" }
}
}
`)
type AuthgearYAMLSource struct {
Extend string `json:"extend"`
Override string `json:"override"`
}
type BeforeHookType string
const (
BeforeHookTypeUserImport BeforeHookType = "user_import"
BeforeHookTypeCustomSQL BeforeHookType = "custom_sql"
)
var _ = TestCaseSchema.Add("BeforeHookCustomSQL", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"path": { "type": "string", "description": "Path to the custom SQL script" }
},
"required": ["path"]
}
`)
type BeforeHookCustomSQL struct {
Path string `json:"path"`
}
var _ = TestCaseSchema.Add("BeforeHook", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"type": { "type": "string", "enum": ["user_import", "custom_sql"] },
"user_import": { "type": "string" },
"custom_sql": { "$ref": "#/$defs/BeforeHookCustomSQL" }
},
"required": ["type"],
"allOf": [
{
"if": { "properties": { "type": { "const": "user_import" } } },
"then": {
"required": ["user_import"]
}
},
{
"if": { "properties": { "type": { "const": "custom_sql" } } },
"then": {
"required": ["custom_sql"]
}
}
]
}
`)
var _ = TestCaseSchema.Add("Step", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"name": { "type": "string" },
"action": { "type": "string", "enum": ["create", "input", "oauth_redirect"] },
"input": { "type": "string" },
"to": { "type": "string" },
"redirect_uri": { "type": "string" },
"output": { "$ref": "#/$defs/Output" }
},
"allOf": [
{
"if": {
"properties": {
"action": { "const": "create" }
}
},
"then": {
"required": ["input"]
}
},
{
"if": {
"properties": {
"action": { "const": "input" }
}
},
"then": {
"required": ["input"]
}
},
{
"if": {
"properties": {
"action": { "const": "oauth_redirect" }
}
},
"then": {
"required": ["to", "redirect_uri"]
}
}
]
}
`)
type Step struct {
Name string `json:"name"`
Action StepAction `json:"action"`
// `action` == "create" or "input"
Input string `json:"input"`
// `action` == "oauth_redirect"
To string `json:"to"`
RedirectURI string `json:"redirect_uri"`
Output *Output `json:"output"`
}
type StepAction string
const (
StepActionCreate StepAction = "create"
StepActionInput StepAction = "input"
StepActionOAuthRedirect StepAction = "oauth_redirect"
)
var _ = TestCaseSchema.Add("Output", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"result": { "type": "string" },
"error": { "type": "string" }
}
}
`)
type Output struct {
Result string `json:"result"`
Error string `json:"error"`
}
var _ = TestCaseSchema.Add("StepResult", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"result": { "type": "string" },
"error": { "type": "string" }
}
}
`)
type StepResult struct {
Result interface{} `json:"result"`
Error error `json:"error"`
}