-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.go
152 lines (119 loc) · 3.96 KB
/
config.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
package core
import (
"context"
"errors"
"github.com/inoxlang/inox/internal/afs"
"github.com/rs/zerolog"
"io"
)
var (
NewDefaultGlobalState NewDefaultGlobalStateFn //default state factory
NewDefaultContext NewDefaultContextFn //default context factory
defaultScriptLimits []Limit
defaultRequestHandlingLimits []Limit
defaultMaxRequestHandlerLimits []Limit
ErrNoFilesystemProvided = errors.New("no filesystem provided")
)
// DefaultGlobalStateConfig is the configured passed to the default state factory.
type DefaultGlobalStateConfig struct {
//if set MODULE_DIRPATH_GLOBAL_NAME & MODULE_FILEPATH_GLOBAL_NAME should be defined.
AbsoluteModulePath string
//if set APP_LISTENING_ADDR
ApplicationListeningAddr Host
EnvPattern *ObjectPattern
PreinitFiles PreinitFiles
AllowMissingEnvVars bool
Out io.Writer
LogOut io.Writer //ignore if .Logger is set
Logger zerolog.Logger
LogLevels *LogLevels
}
type NewDefaultGlobalStateFn func(ctx *Context, conf DefaultGlobalStateConfig) (*GlobalState, error)
// DefaultContextConfig is the configured passed to the default context factory.
type DefaultContextConfig struct {
Permissions []Permission
ForbiddenPermissions []Permission
DoNotCheckDatabasePerms bool //used for the configuration of the created context.
Limits []Limit
HostDefinitions map[Host]Value
OwnedDatabases []DatabaseConfig
ParentContext *Context //optional
ParentStdLibContext context.Context //optional, should not be set if ParentContext is set
//if nil the parent context's filesystem is used.
Filesystem afs.Filesystem
InitialWorkingDirectory Path //optional, should be passed without modification to NewContext.
}
type NewDefaultContextFn func(config DefaultContextConfig) (*Context, error)
// setter and getters
func SetNewDefaultGlobalStateFn(fn NewDefaultGlobalStateFn) {
if NewDefaultGlobalState != nil {
panic(errors.New("default global state fn already set"))
}
NewDefaultGlobalState = fn
}
func UnsetNewDefaultGlobalStateFn() {
NewDefaultGlobalState = nil
}
func SetNewDefaultContext(fn NewDefaultContextFn) {
if NewDefaultContext != nil {
panic(errors.New("newDefaultContext is already set"))
}
NewDefaultContext = fn
}
func UnsetNewDefaultContext() {
NewDefaultContext = nil
}
func SetDefaultScriptLimits(limits []Limit) {
if defaultScriptLimits != nil {
panic(errors.New("default script limits already set"))
}
defaultScriptLimits = limits
}
func GetDefaultScriptLimits() []Limit {
if defaultScriptLimits == nil {
panic(errors.New("default script limits are not set"))
}
return defaultScriptLimits
}
func AreDefaultScriptLimitsSet() bool {
return defaultScriptLimits != nil
}
func UnsetDefaultScriptLimits() {
defaultScriptLimits = nil
}
func SetDefaultRequestHandlingLimits(limits []Limit) {
if defaultRequestHandlingLimits != nil {
panic(errors.New("default request handling limits already set"))
}
defaultRequestHandlingLimits = limits
}
func GetDefaultRequestHandlingLimits() []Limit {
if defaultRequestHandlingLimits == nil {
panic(errors.New("default request handling limits are not set"))
}
return defaultRequestHandlingLimits
}
func AreDefaultRequestHandlingLimitsSet() bool {
return defaultRequestHandlingLimits != nil
}
func UnsetDefaultRequestHandlingLimits() {
defaultRequestHandlingLimits = nil
}
func SetDefaultMaxRequestHandlerLimits(limits []Limit) {
if defaultMaxRequestHandlerLimits != nil {
panic(errors.New("default max request handler limits already set"))
}
defaultMaxRequestHandlerLimits = limits
}
func GetDefaultMaxRequestHandlerLimits() []Limit {
if defaultMaxRequestHandlerLimits == nil {
panic(errors.New("default max request handler limits are not set"))
}
return defaultMaxRequestHandlerLimits
}
func AreDefaultMaxRequestHandlerLimitsSet() bool {
return defaultMaxRequestHandlerLimits != nil
}
func UnsetDefaultMaxRequestHandlerLimits() {
defaultMaxRequestHandlerLimits = nil
}