Skip to content

Commit

Permalink
simplify eos storage
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Feb 13, 2020
1 parent 2081c97 commit 9250b41
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions pkg/storage/fs/eos/eos.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ func init() {
var hiddenReg = regexp.MustCompile(`\.sys\..#.`)

type eosStorage struct {
c *eosclient.Client
mountpoint string
showHiddenSys bool
conf *config
c *eosclient.Client
conf *config
}

func parseConfig(m map[string]interface{}) (*config, error) {
Expand Down Expand Up @@ -108,9 +106,6 @@ type config struct {
// UseKeyTabAuth changes will authenticate requests by using an EOS keytab.
UseKeytab bool `mapstrucuture:"use_keytab"`

// EnableHome enables the creation of home directories.
EnableHome bool `mapstructure:"enable_home"`

// SecProtocol specifies the xrootd security protocol to use between the server and EOS.
SecProtocol string `mapstructure:"sec_protocol"`

Expand All @@ -120,8 +115,11 @@ type config struct {
// SingleUsername is the username to use when SingleUserMode is enabled
SingleUsername string `mapstructure:"single_username"`

// EnableHome enables the creation of home directories.
EnableHome bool `mapstructure:"enable_home"`

// UserLayout wraps the internal path with user information.
// Example: if mountpoint is /eos/user and received path is /docs
// Example: if conf.Namespace is /eos/user and received path is /docs
// and the UserLayout is {{.Username}} the internal path will be:
// /eos/user/<username>/docs
UserLayout string `mapstructure:"layout"`
Expand Down Expand Up @@ -194,10 +192,8 @@ func New(m map[string]interface{}) (storage.FS, error) {
eosClient := eosclient.New(eosClientOpts)

eosStorage := &eosStorage{
c: eosClient,
mountpoint: c.Namespace,
showHiddenSys: c.ShowHiddenSysFiles,
conf: c,
c: eosClient,
conf: c,
}

return eosStorage, nil
Expand All @@ -216,9 +212,9 @@ func (fs *eosStorage) wrap(ctx context.Context, fn string) (internal string) {
panic(err)
}
layout := templates.WithUser(u, fs.conf.UserLayout)
internal = path.Join(fs.mountpoint, layout, fn)
internal = path.Join(fs.conf.Namespace, layout, fn)
} else {
internal = path.Join(fs.mountpoint, fn)
internal = path.Join(fs.conf.Namespace, fn)
}
return
}
Expand All @@ -231,10 +227,10 @@ func (fs *eosStorage) unwrap(ctx context.Context, np string) (external string) {
panic(err)
}
layout := templates.WithUser(u, fs.conf.UserLayout)
trim := path.Join(fs.mountpoint, layout)
trim := path.Join(fs.conf.Namespace, layout)
external = strings.TrimPrefix(np, trim)
} else {
external = strings.TrimPrefix(np, fs.mountpoint)
external = strings.TrimPrefix(np, fs.conf.Namespace)
if external == "" {
external = "/"
}
Expand Down Expand Up @@ -564,7 +560,7 @@ func (fs *eosStorage) ListFolder(ctx context.Context, ref *provider.Reference) (
finfos := []*provider.ResourceInfo{}
for _, eosFileInfo := range eosFileInfos {
// filter out sys files
if !fs.showHiddenSys {
if !fs.conf.ShowHiddenSysFiles {
base := path.Base(eosFileInfo.File)
if hiddenReg.MatchString(base) {
continue
Expand Down Expand Up @@ -862,7 +858,7 @@ func (fs *eosStorage) ListRecycle(ctx context.Context) ([]*provider.RecycleItem,
}
recycleEntries := []*provider.RecycleItem{}
for _, entry := range eosDeletedEntries {
if !fs.showHiddenSys {
if !fs.conf.ShowHiddenSysFiles {
base := path.Base(entry.RestorePath)
if hiddenReg.MatchString(base) {
continue
Expand Down

0 comments on commit 9250b41

Please sign in to comment.