-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrequest_context.go
More file actions
191 lines (155 loc) · 5.29 KB
/
request_context.go
File metadata and controls
191 lines (155 loc) · 5.29 KB
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
package context
// #include "../../API.h"
import "C"
import (
. "main/aikido_types"
"main/log"
)
type CallbackFunction func(int) string
/* Request level context cache (changes on each PHP request) */
type RequestContextData struct {
Callback CallbackFunction // callback to access data from the PHP layer (C++ extension) about the current request and current event
Method *string
Route *string
RouteParsed *string
URL *string
StatusCode *int
IP *string
RateLimitGroup *string
EndpointConfig **EndpointData
WildcardEndpointsConfigs *[]EndpointData
IsIpBypassed *bool
IsEndpointConfigured *bool
IsEndpointRateLimitingEnabled *bool
IsEndpointProtectionTurnedOff *bool
IsEndpointIpAllowed *bool
IsEndpointRateLimited bool
UserAgent *string
UserId *string
UserName *string
BodyRaw *string
BodyParsed *map[string]interface{}
BodyParsedFlattened *map[string]string
QueryParsed *map[string]interface{}
QueryParsedFlattened *map[string]string
CookiesParsed *map[string]interface{}
CookiesParsedFlattened *map[string]string
HeadersParsed *map[string]interface{}
HeadersParsedFlattened *map[string]string
RouteParamsRaw *string
RouteParamsParsed *map[string]interface{}
RouteParamsParsedFlattened *map[string]string
GraphQLParsedFlattened *map[string]string
}
var Context RequestContextData
func Init(callback CallbackFunction) bool {
Context = RequestContextData{
Callback: callback,
}
return true
}
func Clear() bool {
Context = RequestContextData{
Callback: Context.Callback,
}
ResetEventContext()
return true
}
func GetFromCache[T any](fetchDataFn func(), s **T) T {
if fetchDataFn != nil {
fetchDataFn()
}
if *s == nil {
var t T
log.Warnf("Error getting from cache. Returning default value %v...", t)
return t
}
return **s
}
func GetIp() string {
return GetFromCache(ContextSetIp, &Context.IP)
}
func GetMethod() string {
return GetFromCache(ContextSetMethod, &Context.Method)
}
func GetRoute() string {
return GetFromCache(ContextSetRoute, &Context.Route)
}
func GetParsedRoute() string {
return GetFromCache(ContextSetParsedRoute, &Context.RouteParsed)
}
func GetUrl() string {
return GetFromCache(ContextSetUrl, &Context.URL)
}
func GetStatusCode() int {
return GetFromCache(ContextSetStatusCode, &Context.StatusCode)
}
func IsIpBypassed() bool {
return GetFromCache(ContextSetIsIpBypassed, &Context.IsIpBypassed)
}
func GetBodyRaw() string {
return GetFromCache(ContextSetBody, &Context.BodyRaw)
}
func GetBodyParsed() map[string]interface{} {
return GetFromCache(ContextSetBody, &Context.BodyParsed)
}
func GetQueryParsed() map[string]interface{} {
return GetFromCache(ContextSetQuery, &Context.QueryParsed)
}
func GetCookiesParsed() map[string]interface{} {
return GetFromCache(ContextSetCookies, &Context.CookiesParsed)
}
func GetHeadersParsed() map[string]interface{} {
return GetFromCache(ContextSetHeaders, &Context.HeadersParsed)
}
func GetBodyParsedFlattened() map[string]string {
return GetFromCache(ContextSetBody, &Context.BodyParsedFlattened)
}
func GetQueryParsedFlattened() map[string]string {
return GetFromCache(ContextSetQuery, &Context.QueryParsedFlattened)
}
func GetCookiesParsedFlattened() map[string]string {
return GetFromCache(ContextSetCookies, &Context.CookiesParsedFlattened)
}
func GetRouteParamsParsedFlattened() map[string]string {
return GetFromCache(ContextSetRouteParams, &Context.RouteParamsParsedFlattened)
}
func GetHeadersParsedFlattened() map[string]string {
return GetFromCache(ContextSetHeaders, &Context.HeadersParsedFlattened)
}
func GetGraphQLParsedFlattened() map[string]string {
return GetFromCache(ContextSetGraphQL, &Context.GraphQLParsedFlattened)
}
func GetUserAgent() string {
return GetFromCache(ContextSetUserAgent, &Context.UserAgent)
}
func GetUserId() string {
return GetFromCache(ContextSetUserId, &Context.UserId)
}
func GetUserName() string {
return GetFromCache(ContextSetUserName, &Context.UserName)
}
func GetRateLimitGroup() string {
return GetFromCache(ContextSetRateLimitGroup, &Context.RateLimitGroup)
}
func GetEndpointConfig() *EndpointData {
return GetFromCache(ContextSetEndpointConfig, &Context.EndpointConfig)
}
func GetWildcardEndpointsConfig() []EndpointData {
return GetFromCache(ContextSetWildcardEndpointsConfigs, &Context.WildcardEndpointsConfigs)
}
func IsEndpointConfigured() bool {
return GetFromCache(ContextSetIsEndpointConfigured, &Context.IsEndpointConfigured)
}
func IsEndpointRateLimitingEnabled() bool {
return GetFromCache(ContextSetIsEndpointRateLimitingEnabled, &Context.IsEndpointRateLimitingEnabled)
}
func IsEndpointIpAllowed() bool {
return GetFromCache(ContextSetIsEndpointIpAllowed, &Context.IsEndpointIpAllowed)
}
func IsEndpointProtectionTurnedOff() bool {
return GetFromCache(ContextSetIsEndpointProtectionTurnedOff, &Context.IsEndpointProtectionTurnedOff)
}
func IsEndpointRateLimited() bool {
return Context.IsEndpointRateLimited
}