From ae883908e5102156fc6380063bf4d54ff078359c Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Fri, 16 Oct 2020 00:18:19 +0200 Subject: [PATCH] Fix linters --- accounts/pkg/config/config.go | 1 + .../pkg/indexer/index/cs3/autoincrement.go | 42 ++++++++++++------- .../pkg/indexer/index/disk/autoincrement.go | 12 +++++- accounts/pkg/storage/disk.go | 2 +- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 358d0ac895..d3730f003e 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -93,6 +93,7 @@ type Index struct { UID, GID Bound } +// Bound defines a lower and upper bound. type Bound struct { Lower, Upper int64 } diff --git a/accounts/pkg/indexer/index/cs3/autoincrement.go b/accounts/pkg/indexer/index/cs3/autoincrement.go index 86b2b50744..25351f6a6e 100644 --- a/accounts/pkg/indexer/index/cs3/autoincrement.go +++ b/accounts/pkg/indexer/index/cs3/autoincrement.go @@ -26,7 +26,8 @@ import ( "github.com/owncloud/ocis/accounts/pkg/indexer/registry" ) -type AutoincrementIndex struct { +// Autoincrement are fields for an index of type autoincrement. +type Autoincrement struct { indexBy string typeName string filesDir string @@ -51,7 +52,7 @@ func NewAutoincrementIndex(o ...option.Option) index.Index { opt(opts) } - u := &AutoincrementIndex{ + u := &Autoincrement{ indexBy: opts.IndexBy, typeName: opts.TypeName, filesDir: opts.FilesDir, @@ -76,7 +77,8 @@ func NewAutoincrementIndex(o ...option.Option) index.Index { return u } -func (idx *AutoincrementIndex) Init() error { +// Init initializes an autoincrement index. +func (idx *Autoincrement) Init() error { tokenManager, err := jwt.New(map[string]interface{}{ "secret": idx.cs3conf.JWTSecret, }) @@ -112,7 +114,8 @@ func (idx *AutoincrementIndex) Init() error { return nil } -func (idx AutoincrementIndex) Lookup(v string) ([]string, error) { +// Lookup exact lookup by value. +func (idx Autoincrement) Lookup(v string) ([]string, error) { searchPath := path.Join(idx.indexRootDir, v) oldname, err := idx.resolveSymlink(searchPath) if err != nil { @@ -126,7 +129,8 @@ func (idx AutoincrementIndex) Lookup(v string) ([]string, error) { return []string{oldname}, nil } -func (idx AutoincrementIndex) Add(id, v string) (string, error) { +// Add a new value to the index. +func (idx Autoincrement) Add(id, v string) (string, error) { var newName string if v == "" { next, err := idx.next() @@ -148,7 +152,8 @@ func (idx AutoincrementIndex) Add(id, v string) (string, error) { return newName, nil } -func (idx AutoincrementIndex) Remove(id string, v string) error { +// Remove a value v from an index. +func (idx Autoincrement) Remove(id string, v string) error { searchPath := path.Join(idx.indexRootDir, v) _, err := idx.resolveSymlink(searchPath) if err != nil { @@ -185,7 +190,8 @@ func (idx AutoincrementIndex) Remove(id string, v string) error { return err } -func (idx AutoincrementIndex) Update(id, oldV, newV string) error { +// Update index from to . +func (idx Autoincrement) Update(id, oldV, newV string) error { if err := idx.Remove(id, oldV); err != nil { return err } @@ -197,7 +203,8 @@ func (idx AutoincrementIndex) Update(id, oldV, newV string) error { return nil } -func (idx AutoincrementIndex) Search(pattern string) ([]string, error) { +// Search allows for glob search on the index. +func (idx Autoincrement) Search(pattern string) ([]string, error) { ctx := context.Background() t, err := idx.authenticate(ctx) if err != nil { @@ -234,19 +241,22 @@ func (idx AutoincrementIndex) Search(pattern string) ([]string, error) { return matches, nil } -func (idx AutoincrementIndex) IndexBy() string { +// IndexBy undocumented. +func (idx Autoincrement) IndexBy() string { return idx.indexBy } -func (idx AutoincrementIndex) TypeName() string { +// TypeName undocumented. +func (idx Autoincrement) TypeName() string { return idx.typeName } -func (idx AutoincrementIndex) FilesDir() string { +// FilesDir undocumented. +func (idx Autoincrement) FilesDir() string { return idx.filesDir } -func (idx *AutoincrementIndex) createSymlink(oldname, newname string) error { +func (idx *Autoincrement) createSymlink(oldname, newname string) error { t, err := idx.authenticate(context.TODO()) if err != nil { return err @@ -265,7 +275,7 @@ func (idx *AutoincrementIndex) createSymlink(oldname, newname string) error { } -func (idx *AutoincrementIndex) resolveSymlink(name string) (string, error) { +func (idx *Autoincrement) resolveSymlink(name string) (string, error) { t, err := idx.authenticate(context.TODO()) if err != nil { return "", err @@ -292,7 +302,7 @@ func (idx *AutoincrementIndex) resolveSymlink(name string) (string, error) { return string(b), err } -func (idx *AutoincrementIndex) makeDirIfNotExists(ctx context.Context, folder string) error { +func (idx *Autoincrement) makeDirIfNotExists(ctx context.Context, folder string) error { var rootPathRef = &provider.Reference{ Spec: &provider.Reference_Path{Path: fmt.Sprintf("/meta/%v", folder)}, } @@ -318,7 +328,7 @@ func (idx *AutoincrementIndex) makeDirIfNotExists(ctx context.Context, folder st return nil } -func (idx *AutoincrementIndex) authenticate(ctx context.Context) (token string, err error) { +func (idx *Autoincrement) authenticate(ctx context.Context) (token string, err error) { u := &user.User{ Id: &user.UserId{}, Groups: []string{}, @@ -329,7 +339,7 @@ func (idx *AutoincrementIndex) authenticate(ctx context.Context) (token string, return idx.tokenManager.MintToken(ctx, u) } -func (idx AutoincrementIndex) next() (int, error) { +func (idx Autoincrement) next() (int, error) { ctx := context.Background() t, err := idx.authenticate(ctx) if err != nil { diff --git a/accounts/pkg/indexer/index/disk/autoincrement.go b/accounts/pkg/indexer/index/disk/autoincrement.go index b26a90133f..200bc0c300 100644 --- a/accounts/pkg/indexer/index/disk/autoincrement.go +++ b/accounts/pkg/indexer/index/disk/autoincrement.go @@ -17,6 +17,7 @@ import ( "github.com/owncloud/ocis/accounts/pkg/indexer/registry" ) +// Autoincrement are fields for an index of type autoincrement. type Autoincrement struct { indexBy string typeName string @@ -34,7 +35,7 @@ func init() { registry.IndexConstructorRegistry["disk"]["autoincrement"] = NewAutoincrementIndex } -// NewAutoincrementIndex instantiates a new UniqueIndex instance. Init() should be +// NewAutoincrementIndex instantiates a new AutoincrementIndex instance. Init() should be // called afterward to ensure correct on-disk structure. func NewAutoincrementIndex(o ...option.Option) index.Index { opts := &option.Options{} @@ -72,6 +73,7 @@ var ( } ) +// Init initializes an autoincrement index. func (idx Autoincrement) Init() error { if _, err := os.Stat(idx.filesDir); err != nil { return err @@ -84,6 +86,7 @@ func (idx Autoincrement) Init() error { return nil } +// Lookup exact lookup by value. func (idx Autoincrement) Lookup(v string) ([]string, error) { searchPath := path.Join(idx.indexRootDir, v) if err := isValidSymlink(searchPath); err != nil { @@ -102,6 +105,7 @@ func (idx Autoincrement) Lookup(v string) ([]string, error) { return []string{p}, err } +// Add a new value to the index. func (idx Autoincrement) Add(id, v string) (string, error) { nextID, err := idx.next() if err != nil { @@ -122,11 +126,13 @@ func (idx Autoincrement) Add(id, v string) (string, error) { return newName, err } +// Remove a value v from an index. func (idx Autoincrement) Remove(id string, v string) error { searchPath := path.Join(idx.indexRootDir, v) return os.Remove(searchPath) } +// Update index from to . func (idx Autoincrement) Update(id, oldV, newV string) error { oldPath := path.Join(idx.indexRootDir, oldV) if err := isValidSymlink(oldPath); err != nil { @@ -150,6 +156,7 @@ func (idx Autoincrement) Update(id, oldV, newV string) error { return err } +// Search allows for glob search on the index. func (idx Autoincrement) Search(pattern string) ([]string, error) { paths, err := filepath.Glob(path.Join(idx.indexRootDir, pattern)) if err != nil { @@ -177,14 +184,17 @@ func (idx Autoincrement) Search(pattern string) ([]string, error) { return res, nil } +// IndexBy undocumented. func (idx Autoincrement) IndexBy() string { return idx.indexBy } +// TypeName undocumented. func (idx Autoincrement) TypeName() string { return idx.typeName } +// FilesDir undocumented. func (idx Autoincrement) FilesDir() string { return idx.filesDir } diff --git a/accounts/pkg/storage/disk.go b/accounts/pkg/storage/disk.go index 3490424a6d..fddfb6a0ef 100644 --- a/accounts/pkg/storage/disk.go +++ b/accounts/pkg/storage/disk.go @@ -127,7 +127,7 @@ func (r DiskRepo) DeleteGroup(ctx context.Context, id string) (err error) { } } - return nil + return //r.log.Error().Err(err).Str("id", id).Str("path", path).Msg("could not remove group") //return merrors.InternalServerError(r.serviceID, "could not remove group: %v", err.Error())