github.com/cs3org/reva/v2@v2.27.7/pkg/storage/fs/localhome/localhome.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 localhome 20 21 import ( 22 "github.com/cs3org/reva/v2/pkg/events" 23 "github.com/cs3org/reva/v2/pkg/storage" 24 "github.com/cs3org/reva/v2/pkg/storage/fs/registry" 25 "github.com/cs3org/reva/v2/pkg/storage/utils/localfs" 26 "github.com/mitchellh/mapstructure" 27 "github.com/pkg/errors" 28 "github.com/rs/zerolog" 29 ) 30 31 func init() { 32 registry.Register("localhome", New) 33 } 34 35 type config struct { 36 Root string `mapstructure:"root" docs:"/var/tmp/reva/;Path of root directory for user storage."` 37 ShareFolder string `mapstructure:"share_folder" docs:"/MyShares;Path for storing share references."` 38 UserLayout string `mapstructure:"user_layout" docs:"{{.Username}};Template for user home directories"` 39 } 40 41 func parseConfig(m map[string]interface{}) (*config, error) { 42 c := &config{} 43 if err := mapstructure.Decode(m, c); err != nil { 44 err = errors.Wrap(err, "error decoding conf") 45 return nil, err 46 } 47 return c, nil 48 } 49 50 // New returns an implementation to of the storage.FS interface that talks to 51 // a local filesystem with user homes. 52 func New(m map[string]interface{}, _ events.Stream, _ *zerolog.Logger) (storage.FS, error) { 53 c, err := parseConfig(m) 54 if err != nil { 55 return nil, err 56 } 57 58 conf := localfs.Config{ 59 Root: c.Root, 60 ShareFolder: c.ShareFolder, 61 UserLayout: c.UserLayout, 62 } 63 return localfs.NewLocalFS(&conf) 64 }