github.com/cs3org/reva/v2@v2.27.7/pkg/storage/utils/decomposedfs/options/options.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 options 20 21 import ( 22 "path/filepath" 23 "strings" 24 "time" 25 26 "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" 27 "github.com/cs3org/reva/v2/pkg/sharedconf" 28 "github.com/cs3org/reva/v2/pkg/storage/cache" 29 "github.com/mitchellh/mapstructure" 30 "github.com/pkg/errors" 31 ) 32 33 // Option defines a single option function. 34 type Option func(o *Options) 35 36 // Options defines the available options for this package. 37 type Options struct { 38 39 // the gateway address 40 GatewayAddr string `mapstructure:"gateway_addr"` 41 42 // the metadata backend to use, currently supports `xattr` or `ini` 43 MetadataBackend string `mapstructure:"metadata_backend"` 44 45 // the propagator to use for this fs. currently only `sync` is fully supported, `async` is available as an experimental feature 46 Propagator string `mapstructure:"propagator"` 47 // Options specific to the async propagator 48 AsyncPropagatorOptions AsyncPropagatorOptions `mapstructure:"async_propagator_options"` 49 50 // ocis fs works on top of a dir of uuid nodes 51 Root string `mapstructure:"root"` 52 53 // the upload directory where uploads in progress are stored 54 UploadDirectory string `mapstructure:"upload_directory"` 55 56 // UserLayout describes the relative path from the storage's root node to the users home node. 57 UserLayout string `mapstructure:"user_layout"` 58 59 // ProjectLayout describes the relative path from the storage's root node to the project spaces root directory. 60 ProjectLayout string `mapstructure:"project_layout"` 61 62 // propagate mtime changes as tmtime (tree modification time) to the parent directory when user.ocis.propagation=1 is set on a node 63 TreeTimeAccounting bool `mapstructure:"treetime_accounting"` 64 65 // propagate size changes as treesize 66 TreeSizeAccounting bool `mapstructure:"treesize_accounting"` 67 68 // permissions service to use when checking permissions 69 PermissionsSVC string `mapstructure:"permissionssvc"` 70 PermissionsClientTLSMode string `mapstructure:"permissionssvc_tls_mode"` 71 PermTLSMode pool.TLSMode 72 73 PersonalSpaceAliasTemplate string `mapstructure:"personalspacealias_template"` 74 PersonalSpacePathTemplate string `mapstructure:"personalspacepath_template"` 75 GeneralSpaceAliasTemplate string `mapstructure:"generalspacealias_template"` 76 GeneralSpacePathTemplate string `mapstructure:"generalspacepath_template"` 77 78 AsyncFileUploads bool `mapstructure:"asyncfileuploads"` 79 80 Events EventOptions `mapstructure:"events"` 81 82 Tokens TokenOptions `mapstructure:"tokens"` 83 84 StatCache cache.Config `mapstructure:"statcache"` 85 FileMetadataCache cache.Config `mapstructure:"filemetadatacache"` 86 IDCache cache.Config `mapstructure:"idcache"` 87 88 MaxAcquireLockCycles int `mapstructure:"max_acquire_lock_cycles"` 89 LockCycleDurationFactor int `mapstructure:"lock_cycle_duration_factor"` 90 MaxConcurrency int `mapstructure:"max_concurrency"` 91 92 MaxQuota uint64 `mapstructure:"max_quota"` 93 94 DisableVersioning bool `mapstructure:"disable_versioning"` 95 96 MountID string `mapstructure:"mount_id"` 97 } 98 99 // AsyncPropagatorOptions holds the configuration for the async propagator 100 type AsyncPropagatorOptions struct { 101 PropagationDelay time.Duration `mapstructure:"propagation_delay"` 102 } 103 104 // EventOptions are the configurable options for events 105 type EventOptions struct { 106 NumConsumers int `mapstructure:"numconsumers"` 107 } 108 109 // TokenOptions are the configurable option for tokens 110 type TokenOptions struct { 111 DownloadEndpoint string `mapstructure:"download_endpoint"` 112 DataGatewayEndpoint string `mapstructure:"datagateway_endpoint"` 113 TransferSharedSecret string `mapstructure:"transfer_shared_secret"` 114 TransferExpires int64 `mapstructure:"transfer_expires"` 115 } 116 117 // New returns a new Options instance for the given configuration 118 func New(m map[string]interface{}) (*Options, error) { 119 o := &Options{} 120 if err := mapstructure.Decode(m, o); err != nil { 121 err = errors.Wrap(err, "error decoding conf") 122 return nil, err 123 } 124 125 o.GatewayAddr = sharedconf.GetGatewaySVC(o.GatewayAddr) 126 127 if o.MetadataBackend == "" { 128 o.MetadataBackend = "xattrs" 129 } 130 131 // ensure user layout has no starting or trailing / 132 o.UserLayout = strings.Trim(o.UserLayout, "/") 133 134 // c.DataDirectory should never end in / unless it is the root 135 o.Root = filepath.Clean(o.Root) 136 137 if o.PersonalSpaceAliasTemplate == "" { 138 o.PersonalSpaceAliasTemplate = "{{.SpaceType}}/{{.User.Username}}" 139 } 140 141 if o.GeneralSpaceAliasTemplate == "" { 142 o.GeneralSpaceAliasTemplate = "{{.SpaceType}}/{{.SpaceName | replace \" \" \"-\" | lower}}" 143 } 144 145 if o.PermissionsClientTLSMode != "" { 146 var err error 147 o.PermTLSMode, err = pool.StringToTLSMode(o.PermissionsClientTLSMode) 148 if err != nil { 149 return nil, err 150 } 151 } else { 152 sharedOpt := sharedconf.GRPCClientOptions() 153 var err error 154 155 if o.PermTLSMode, err = pool.StringToTLSMode(sharedOpt.TLSMode); err != nil { 156 return nil, err 157 } 158 } 159 160 if o.MaxConcurrency <= 0 { 161 o.MaxConcurrency = 5 162 } 163 164 if o.Propagator == "" { 165 o.Propagator = "sync" 166 } 167 if o.AsyncPropagatorOptions.PropagationDelay == 0 { 168 o.AsyncPropagatorOptions.PropagationDelay = 5 * time.Second 169 } 170 171 if o.UploadDirectory == "" { 172 o.UploadDirectory = filepath.Join(o.Root, "uploads") 173 } 174 175 return o, nil 176 }