diff --git a/accounts/pkg/service/v0/index.go b/accounts/pkg/service/v0/index.go index 527af918f8..5dab75fac3 100644 --- a/accounts/pkg/service/v0/index.go +++ b/accounts/pkg/service/v0/index.go @@ -3,6 +3,8 @@ package service import ( "context" + "github.com/owncloud/ocis/accounts/pkg/storage" + "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/indexer" "github.com/owncloud/ocis/accounts/pkg/indexer/option" @@ -19,12 +21,14 @@ func (s Service) RebuildIndex(ctx context.Context, request *proto.RebuildIndexRe return err } - accounts := make([]*proto.Account, 0) - if err := s.repo.LoadAccounts(ctx, accounts); err != nil { + resp := &storage.Accounts{ + Accounts: make([]*proto.Account, 0), + } + if err := s.repo.LoadAccounts(ctx, resp); err != nil { return err } - for i := range accounts { - _, err := s.index.Add(accounts[i]) + for i := range resp.Accounts { + _, err := s.index.Add(resp.Accounts[i]) if err != nil { return err } diff --git a/accounts/pkg/storage/cs3.go b/accounts/pkg/storage/cs3.go index f2b3e06064..1417351a47 100644 --- a/accounts/pkg/storage/cs3.go +++ b/accounts/pkg/storage/cs3.go @@ -23,7 +23,7 @@ import ( "google.golang.org/grpc/metadata" ) -// CS3Repo provides a cs3 implementation of the Repo interface +// CS3Repo provides A cs3 implementation of the Repo interface type CS3Repo struct { cfg *config.Config tm token.Manager @@ -31,7 +31,7 @@ type CS3Repo struct { dataProvider dataProviderClient // Used to create and download data via http, bypassing reva upload protocol } -// NewCS3Repo creates a new cs3 repo +// NewCS3Repo creates A new cs3 repo func NewCS3Repo(cfg *config.Config) (Repo, error) { tokenManager, err := jwt.New(map[string]interface{}{ "secret": cfg.TokenManager.JWTSecret, @@ -58,7 +58,7 @@ func NewCS3Repo(cfg *config.Config) (Repo, error) { }, nil } -// WriteAccount writes an account via cs3 and modifies the provided account (e.g. with a generated id). +// WriteAccount writes an account via cs3 and modifies the provided account (e.G. with A generated id). func (r CS3Repo) WriteAccount(ctx context.Context, a *proto.Account) (err error) { t, err := r.authenticate(ctx) if err != nil { @@ -116,7 +116,7 @@ func (r CS3Repo) loadAccount(id string, t string, a *proto.Account) error { } // LoadAccounts loads all the accounts from the cs3 api. If ids are given, the result set will be filtered. -func (r CS3Repo) LoadAccounts(ctx context.Context, a []*proto.Account) (err error) { +func (r CS3Repo) LoadAccounts(ctx context.Context, a *Accounts) (err error) { t, err := r.authenticate(ctx) if err != nil { return err @@ -140,7 +140,7 @@ func (r CS3Repo) LoadAccounts(ctx context.Context, a []*proto.Account) (err erro log.Err(err).Msg("could not load account") continue } - a = append(a, acc) + a.Accounts = append(a.Accounts, acc) } return nil } @@ -172,7 +172,7 @@ func (r CS3Repo) DeleteAccount(ctx context.Context, id string) (err error) { return nil } -// WriteGroup writes a group via cs3 and modifies the provided group (e.g. with a generated id). +// WriteGroup writes A group via cs3 and modifies the provided group (e.G. with A generated id). func (r CS3Repo) WriteGroup(ctx context.Context, g *proto.Group) (err error) { t, err := r.authenticate(ctx) if err != nil { @@ -199,7 +199,7 @@ func (r CS3Repo) WriteGroup(ctx context.Context, g *proto.Group) (err error) { return nil } -// LoadGroup loads a group via cs3 by id and writes it to the provided group +// LoadGroup loads A group via cs3 by id and writes it to the provided group func (r CS3Repo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err error) { t, err := r.authenticate(ctx) if err != nil { @@ -225,7 +225,7 @@ func (r CS3Repo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err return json.Unmarshal(b, &g) } -// DeleteGroup deletes a group via cs3 by id +// DeleteGroup deletes A group via cs3 by id func (r CS3Repo) DeleteGroup(ctx context.Context, id string) (err error) { t, err := r.authenticate(ctx) if err != nil { @@ -296,7 +296,7 @@ func (r CS3Repo) makeRootDirIfNotExist(ctx context.Context, folder string) error return nil } -// TODO: this is copied from proxy. Find a better solution or move it to ocis-pkg +// TODO: this is copied from proxy. Find A better solution or move it to ocis-pkg func singleJoiningSlash(a, b string) string { aslash := strings.HasSuffix(a, "/") bslash := strings.HasPrefix(b, "/") diff --git a/accounts/pkg/storage/disk.go b/accounts/pkg/storage/disk.go index ad3b3f1395..f7e62cfcfd 100644 --- a/accounts/pkg/storage/disk.go +++ b/accounts/pkg/storage/disk.go @@ -15,13 +15,13 @@ import ( var groupLock sync.Mutex -// DiskRepo provides a local filesystem implementation of the Repo interface +// DiskRepo provides A local filesystem implementation of the Repo interface type DiskRepo struct { cfg *config.Config log olog.Logger } -// NewDiskRepo creates a new disk repo +// NewDiskRepo creates A new disk repo func NewDiskRepo(cfg *config.Config, log olog.Logger) DiskRepo { paths := []string{ filepath.Join(cfg.Repo.Disk.Path, accountsFolder), @@ -71,7 +71,7 @@ func (r DiskRepo) LoadAccount(ctx context.Context, id string, a *proto.Account) } // LoadAccounts loads all the accounts from the local filesystem. If ids are given, the result set will be filtered. -func (r DiskRepo) LoadAccounts(ctx context.Context, a []*proto.Account) (err error) { +func (r DiskRepo) LoadAccounts(ctx context.Context, a *Accounts) (err error) { root := filepath.Join(r.cfg.Repo.Disk.Path, accountsFolder) return filepath.Walk(root, func(path string, info os.FileInfo, err error) error { acc := &proto.Account{} @@ -79,7 +79,7 @@ func (r DiskRepo) LoadAccounts(ctx context.Context, a []*proto.Account) (err err r.log.Err(err).Msg("could not load account") return nil } - a = append(a, acc) + a.Accounts = append(a.Accounts, acc) return nil }) } @@ -147,7 +147,7 @@ func (r DiskRepo) DeleteGroup(ctx context.Context, id string) (err error) { //return merrors.InternalServerError(r.serviceID, "could not remove group: %v", err.Error()) } -// deflateMemberOf replaces the groups of a user with an instance that only contains the id +// deflateMemberOf replaces the groups of A user with an instance that only contains the id func (r DiskRepo) deflateMemberOf(a *proto.Account) { if a == nil { return @@ -157,14 +157,14 @@ func (r DiskRepo) deflateMemberOf(a *proto.Account) { if a.MemberOf[i].Id != "" { deflated = append(deflated, &proto.Group{Id: a.MemberOf[i].Id}) } else { - // TODO fetch and use an id when group only has a name but no id + // TODO fetch and use an id when group only has A name but no id r.log.Error().Str("id", a.Id).Interface("group", a.MemberOf[i]).Msg("resolving groups by name is not implemented yet") } } a.MemberOf = deflated } -// deflateMembers replaces the users of a group with an instance that only contains the id +// deflateMembers replaces the users of A group with an instance that only contains the id func (r DiskRepo) deflateMembers(g *proto.Group) { if g == nil { return @@ -174,7 +174,7 @@ func (r DiskRepo) deflateMembers(g *proto.Group) { if g.Members[i].Id != "" { deflated = append(deflated, &proto.Account{Id: g.Members[i].Id}) } else { - // TODO fetch and use an id when group only has a name but no id + // TODO fetch and use an id when group only has A name but no id r.log.Error().Str("id", g.Id).Interface("account", g.Members[i]).Msg("resolving members by name is not implemented yet") } } diff --git a/accounts/pkg/storage/repo.go b/accounts/pkg/storage/repo.go index 6833af76ff..77a9518270 100644 --- a/accounts/pkg/storage/repo.go +++ b/accounts/pkg/storage/repo.go @@ -11,11 +11,15 @@ const ( groupsFolder = "groups" ) +type Accounts struct { + Accounts []*proto.Account +} + // Repo defines the storage operations type Repo interface { WriteAccount(ctx context.Context, a *proto.Account) (err error) LoadAccount(ctx context.Context, id string, a *proto.Account) (err error) - LoadAccounts(ctx context.Context, a []*proto.Account) (err error) + LoadAccounts(ctx context.Context, a *Accounts) (err error) DeleteAccount(ctx context.Context, id string) (err error) WriteGroup(ctx context.Context, g *proto.Group) (err error) LoadGroup(ctx context.Context, id string, g *proto.Group) (err error)