-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathdefaultconfig.go
200 lines (191 loc) · 5.96 KB
/
defaultconfig.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package defaults
import (
"path/filepath"
"strings"
"github.com/owncloud/ocis/v2/ocis-pkg/config/defaults"
"github.com/owncloud/ocis/v2/services/web/pkg/config"
)
// FullDefaultConfig returns a fully initialized default configuration
func FullDefaultConfig() *config.Config {
cfg := DefaultConfig()
EnsureDefaults(cfg)
Sanitize(cfg)
return cfg
}
// DefaultConfig returns a basic default configuration
func DefaultConfig() *config.Config {
return &config.Config{
Debug: config.Debug{
Addr: "127.0.0.1:9104",
Token: "",
Pprof: false,
Zpages: false,
},
HTTP: config.HTTP{
Addr: "127.0.0.1:9100",
Root: "/",
Namespace: "com.owncloud.web",
CacheTTL: 604800, // 7 days
CORS: config.CORS{
AllowedOrigins: []string{"https://localhost:9200"},
AllowedMethods: []string{
"OPTIONS",
"HEAD",
"GET",
"PUT",
"PATCH",
"POST",
"DELETE",
"MKCOL",
"PROPFIND",
"PROPPATCH",
"MOVE",
"COPY",
"REPORT",
"SEARCH",
},
AllowedHeaders: []string{
"Origin",
"Accept",
"Content-Type",
"Depth",
"Authorization",
"Ocs-Apirequest",
"If-None-Match",
"If-Match",
"Destination",
"Overwrite",
"X-Request-Id",
"X-Requested-With",
"Tus-Resumable",
"Tus-Checksum-Algorithm",
"Upload-Concat",
"Upload-Length",
"Upload-Metadata",
"Upload-Defer-Length",
"Upload-Expires",
"Upload-Checksum",
"Upload-Offset",
"X-HTTP-Method-Override",
},
AllowCredentials: false,
},
},
Service: config.Service{
Name: "web",
},
Asset: config.Asset{
CorePath: filepath.Join(defaults.BaseDataPath(), "web/assets/core"),
AppsPath: filepath.Join(defaults.BaseDataPath(), "web/assets/apps"),
ThemesPath: filepath.Join(defaults.BaseDataPath(), "web/assets/themes"),
},
GatewayAddress: "com.owncloud.api.gateway",
Web: config.Web{
ThemeServer: "https://localhost:9200",
ThemePath: "/themes/owncloud/theme.json",
Config: config.WebConfig{
Server: "https://localhost:9200",
Theme: "",
OpenIDConnect: config.OIDC{
MetadataURL: "",
Authority: "https://localhost:9200",
ClientID: "web",
ResponseType: "code",
Scope: "openid profile email",
},
Apps: []string{"files", "search", "text-editor", "pdf-viewer", "external", "admin-settings", "epub-reader", "preview", "app-store"},
Options: config.Options{
ContextHelpersReadMore: true,
AccountEditLink: &config.AccountEditLink{},
Editor: &config.Editor{},
FeedbackLink: &config.FeedbackLink{},
Embed: &config.Embed{},
ConcurrentRequests: &config.ConcurrentRequests{
Shares: &config.ConcurrentRequestsShares{},
},
Upload: &config.Upload{},
TokenStorageLocal: true,
UserListRequiresFilter: false,
},
},
},
}
}
// EnsureDefaults adds default values to the configuration if they are not set yet
func EnsureDefaults(cfg *config.Config) {
// provide with defaults for shared logging, since we need a valid destination address for "envdecode".
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
cfg.Log = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil {
cfg.Log = &config.Log{}
}
// provide with defaults for shared tracing, since we need a valid destination address for "envdecode".
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
cfg.Tracing = &config.Tracing{
Enabled: cfg.Commons.Tracing.Enabled,
Type: cfg.Commons.Tracing.Type,
Endpoint: cfg.Commons.Tracing.Endpoint,
Collector: cfg.Commons.Tracing.Collector,
}
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}
if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &config.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else if cfg.TokenManager == nil {
cfg.TokenManager = &config.TokenManager{}
}
if cfg.Commons != nil {
cfg.HTTP.TLS = cfg.Commons.HTTPServiceTLS
}
if (cfg.Commons != nil && cfg.Commons.OcisURL != "") &&
(cfg.HTTP.CORS.AllowedOrigins == nil ||
len(cfg.HTTP.CORS.AllowedOrigins) == 1 &&
cfg.HTTP.CORS.AllowedOrigins[0] == "https://localhost:9200") {
cfg.HTTP.CORS.AllowedOrigins = []string{cfg.Commons.OcisURL}
}
}
// Sanitize sanitized the configuration
func Sanitize(cfg *config.Config) {
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/")
}
// build well known openid-configuration endpoint if it is not set
if cfg.Web.Config.OpenIDConnect.MetadataURL == "" {
cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration"
}
// remove AccountEdit parent if no value is set
if cfg.Web.Config.Options.AccountEditLink.Href == "" {
cfg.Web.Config.Options.AccountEditLink = nil
}
// remove Editor parent if no value is set
if !cfg.Web.Config.Options.Editor.AutosaveEnabled {
cfg.Web.Config.Options.Editor = nil
}
// remove FeedbackLink parent if no value is set
if cfg.Web.Config.Options.FeedbackLink.Href == "" &&
cfg.Web.Config.Options.FeedbackLink.AriaLabel == "" &&
cfg.Web.Config.Options.FeedbackLink.Description == "" {
cfg.Web.Config.Options.FeedbackLink = nil
}
// remove Upload parent if no value is set
if cfg.Web.Config.Options.Upload.CompanionURL == "" {
cfg.Web.Config.Options.Upload = nil
}
// remove Embed parent if no value is set
if cfg.Web.Config.Options.Embed.Enabled == "" &&
cfg.Web.Config.Options.Embed.Target == "" &&
cfg.Web.Config.Options.Embed.MessagesOrigin == "" &&
cfg.Web.Config.Options.Embed.DelegateAuthentication &&
cfg.Web.Config.Options.Embed.DelegateAuthenticationOrigin == "" {
cfg.Web.Config.Options.Embed = nil
}
}