github.com/cs3org/reva/v2@v2.27.7/pkg/micro/ocdav/option.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package ocdav 20 21 import ( 22 "context" 23 "crypto/tls" 24 "time" 25 26 gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" 27 "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav" 28 "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/config" 29 "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" 30 "github.com/cs3org/reva/v2/pkg/storage/favorite" 31 "github.com/rs/zerolog" 32 "go-micro.dev/v4/broker" 33 "go.opentelemetry.io/otel/trace" 34 "google.golang.org/grpc/credentials" 35 ) 36 37 // Option defines a single option function. 38 type Option func(o *Options) 39 40 // Options defines the available options for this package. 41 type Options struct { 42 TLSConfig *tls.Config 43 Broker broker.Broker 44 Address string 45 Logger zerolog.Logger 46 Context context.Context 47 // Metrics *metrics.Metrics 48 // Flags []cli.Flag 49 Name string 50 JWTSecret string 51 52 FavoriteManager favorite.Manager 53 GatewaySelector pool.Selectable[gateway.GatewayAPIClient] 54 55 TracingEnabled bool 56 TracingInsecure bool 57 TracingEndpoint string 58 TracingTransportCredentials credentials.TransportCredentials 59 60 TraceProvider trace.TracerProvider 61 62 MetricsEnabled bool 63 MetricsNamespace string 64 MetricsSubsystem string 65 66 // ocdav.* is internal so we need to set config options individually 67 config config.Config 68 lockSystem ocdav.LockSystem 69 AllowCredentials bool 70 AllowedOrigins []string 71 AllowedHeaders []string 72 AllowedMethods []string 73 AllowDepthInfinity bool 74 75 RegisterTTL time.Duration 76 RegisterInterval time.Duration 77 } 78 79 // newOptions initializes the available default options. 80 func newOptions(opts ...Option) Options { 81 opt := Options{} 82 83 for _, o := range opts { 84 o(&opt) 85 } 86 87 return opt 88 } 89 90 // TLSConfig provides a function to set the TLSConfig option. 91 func TLSConfig(config *tls.Config) Option { 92 return func(o *Options) { 93 o.TLSConfig = config 94 } 95 } 96 97 // Broker provides a function to set the Broker option. 98 func Broker(b broker.Broker) Option { 99 return func(o *Options) { 100 o.Broker = b 101 } 102 } 103 104 // Address provides a function to set the address option. 105 func Address(val string) Option { 106 return func(o *Options) { 107 o.Address = val 108 } 109 } 110 111 func AllowDepthInfinity(val bool) Option { 112 return func(o *Options) { 113 o.AllowDepthInfinity = val 114 } 115 } 116 117 // JWTSecret provides a function to set the jwt secret option. 118 func JWTSecret(s string) Option { 119 return func(o *Options) { 120 o.JWTSecret = s 121 } 122 } 123 124 // MachineAuthAPIKey provides a function to set the machine auth api key option. 125 func MachineAuthAPIKey(s string) Option { 126 return func(o *Options) { 127 o.config.MachineAuthAPIKey = s 128 } 129 } 130 131 // Context provides a function to set the context option. 132 func Context(val context.Context) Option { 133 return func(o *Options) { 134 o.Context = val 135 } 136 } 137 138 // Logger provides a function to set the logger option. 139 func Logger(val zerolog.Logger) Option { 140 return func(o *Options) { 141 o.Logger = val 142 } 143 } 144 145 // Name provides a function to set the Name option. 146 func Name(val string) Option { 147 return func(o *Options) { 148 o.Name = val 149 } 150 } 151 152 // Prefix provides a function to set the prefix config option. 153 func Prefix(val string) Option { 154 return func(o *Options) { 155 o.config.Prefix = val 156 } 157 } 158 159 // FilesNamespace provides a function to set the FilesNamespace config option. 160 func FilesNamespace(val string) Option { 161 return func(o *Options) { 162 o.config.FilesNamespace = val 163 } 164 } 165 166 // WebdavNamespace provides a function to set the WebdavNamespace config option. 167 func WebdavNamespace(val string) Option { 168 return func(o *Options) { 169 o.config.WebdavNamespace = val 170 } 171 } 172 173 // SharesNamespace provides a function to set the SharesNamespace config option. 174 func SharesNamespace(val string) Option { 175 return func(o *Options) { 176 o.config.SharesNamespace = val 177 } 178 } 179 180 // OCMNamespace provides a function to set the OCMNamespace config option. 181 func OCMNamespace(val string) Option { 182 return func(o *Options) { 183 o.config.OCMNamespace = val 184 } 185 } 186 187 // GatewaySvc provides a function to set the GatewaySvc config option. 188 func GatewaySvc(val string) Option { 189 return func(o *Options) { 190 o.config.GatewaySvc = val 191 } 192 } 193 194 // Timeout provides a function to set the Timeout config option. 195 func Timeout(val int64) Option { 196 return func(o *Options) { 197 o.config.Timeout = val 198 } 199 } 200 201 // Insecure provides a function to set the Insecure config option. 202 func Insecure(val bool) Option { 203 return func(o *Options) { 204 o.config.Insecure = val 205 } 206 } 207 208 // PublicURL provides a function to set the PublicURL config option. 209 func PublicURL(val string) Option { 210 return func(o *Options) { 211 o.config.PublicURL = val 212 } 213 } 214 215 // FavoriteManager provides a function to set the FavoriteManager option. 216 func FavoriteManager(val favorite.Manager) Option { 217 return func(o *Options) { 218 o.FavoriteManager = val 219 } 220 } 221 222 // GatewaySelector provides a function to set the GatewaySelector option. 223 func GatewaySelector(val pool.Selectable[gateway.GatewayAPIClient]) Option { 224 return func(o *Options) { 225 o.GatewaySelector = val 226 } 227 } 228 229 // LockSystem provides a function to set the LockSystem option. 230 func LockSystem(val ocdav.LockSystem) Option { 231 return func(o *Options) { 232 o.lockSystem = val 233 } 234 } 235 236 // Tracing enables tracing 237 // Deprecated: use WithTracingEndpoint and WithTracingEnabled, Collector is unused 238 func Tracing(endpoint, collector string) Option { 239 return func(o *Options) { 240 o.TracingEnabled = true 241 o.TracingEndpoint = endpoint 242 } 243 } 244 245 // WithTracingEnabled option 246 func WithTracingEnabled(enabled bool) Option { 247 return func(o *Options) { 248 o.TracingEnabled = enabled 249 } 250 } 251 252 // WithTracingEndpoint option 253 func WithTracingEndpoint(endpoint string) Option { 254 return func(o *Options) { 255 o.TracingEndpoint = endpoint 256 } 257 } 258 259 // WithTracingInsecure option 260 func WithTracingInsecure() Option { 261 return func(o *Options) { 262 o.TracingInsecure = true 263 } 264 } 265 266 // WithTracingExporter option 267 // Deprecated: unused 268 func WithTracingExporter(exporter string) Option { 269 return func(o *Options) {} 270 } 271 272 // WithTracingTransportCredentials option 273 func WithTracingTransportCredentials(v credentials.TransportCredentials) Option { 274 return func(o *Options) { 275 o.TracingTransportCredentials = v 276 } 277 } 278 279 // WithTraceProvider option 280 func WithTraceProvider(provider trace.TracerProvider) Option { 281 return func(o *Options) { 282 o.TraceProvider = provider 283 } 284 } 285 286 // Version provides a function to set the Version config option. 287 func Version(val string) Option { 288 return func(o *Options) { 289 o.config.Version = val 290 } 291 } 292 293 // VersionString provides a function to set the VersionString config option. 294 func VersionString(val string) Option { 295 return func(o *Options) { 296 o.config.VersionString = val 297 } 298 } 299 300 // Edition provides a function to set the Edition config option. 301 func Edition(val string) Option { 302 return func(o *Options) { 303 o.config.Edition = val 304 } 305 } 306 307 // Product provides a function to set the Product config option. 308 func Product(val string) Option { 309 return func(o *Options) { 310 o.config.Product = val 311 } 312 } 313 314 // ProductName provides a function to set the ProductName config option. 315 func ProductName(val string) Option { 316 return func(o *Options) { 317 o.config.ProductName = val 318 } 319 } 320 321 // ProductVersion provides a function to set the ProductVersion config option. 322 func ProductVersion(val string) Option { 323 return func(o *Options) { 324 o.config.ProductVersion = val 325 } 326 } 327 328 // MetricsEnabled provides a function to set the MetricsEnabled config option. 329 func MetricsEnabled(val bool) Option { 330 return func(o *Options) { 331 o.MetricsEnabled = val 332 } 333 } 334 335 // MetricsNamespace provides a function to set the MetricsNamespace config option. 336 func MetricsNamespace(val string) Option { 337 return func(o *Options) { 338 o.MetricsNamespace = val 339 } 340 } 341 342 // MetricsSubsystem provides a function to set the MetricsSubsystem config option. 343 func MetricsSubsystem(val string) Option { 344 return func(o *Options) { 345 o.MetricsSubsystem = val 346 } 347 } 348 349 // AllowCredentials provides a function to set the AllowCredentials option. 350 func AllowCredentials(val bool) Option { 351 return func(o *Options) { 352 o.AllowCredentials = val 353 } 354 } 355 356 // AllowedOrigins provides a function to set the AllowedOrigins option. 357 func AllowedOrigins(val []string) Option { 358 return func(o *Options) { 359 o.AllowedOrigins = val 360 } 361 } 362 363 // AllowedMethods provides a function to set the AllowedMethods option. 364 func AllowedMethods(val []string) Option { 365 return func(o *Options) { 366 o.AllowedMethods = val 367 } 368 } 369 370 // AllowedHeaders provides a function to set the AllowedHeaders option. 371 func AllowedHeaders(val []string) Option { 372 return func(o *Options) { 373 o.AllowedHeaders = val 374 } 375 } 376 377 // ItemNameInvalidChars provides a function to set forbidden characters in file or folder names 378 func ItemNameInvalidChars(chars []string) Option { 379 return func(o *Options) { 380 o.config.NameValidation.InvalidChars = chars 381 } 382 } 383 384 // ItemNameMaxLength provides a function to set the maximum length of a file or folder name 385 func ItemNameMaxLength(i int) Option { 386 return func(o *Options) { 387 o.config.NameValidation.MaxLength = i 388 } 389 } 390 391 // RegisterTTL provides a function to set the RegisterTTL option. 392 func RegisterTTL(ttl time.Duration) Option { 393 return func(o *Options) { 394 o.RegisterTTL = ttl 395 } 396 } 397 398 // RegisterInterval provides a function to set the RegisterInterval option. 399 func RegisterInterval(interval time.Duration) Option { 400 return func(o *Options) { 401 o.RegisterInterval = interval 402 } 403 }