Adjust import paths and service urls in index.js

This commit is contained in:
Juan Pablo Villafáñez
2022-01-31 09:26:23 +01:00
parent 1ff5fa4c02
commit 6c67ff765e
30 changed files with 359 additions and 323 deletions
+36 -34
View File
@@ -16,10 +16,12 @@ import (
"go.opentelemetry.io/otel/attribute"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
"github.com/gofrs/uuid"
"github.com/golang/protobuf/ptypes/empty"
fieldmask_utils "github.com/mennanov/fieldmask-utils"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/accounts/pkg/storage"
accTracing "github.com/owncloud/ocis/accounts/pkg/tracing"
"github.com/owncloud/ocis/ocis-pkg/log"
@@ -47,13 +49,13 @@ const passwordValidCacheExpiration = 10 * time.Minute
// login eq \"teddy\" and password eq \"F&1!b90t111!\"
var authQuery = regexp.MustCompile(`^login eq '(.*)' and password eq '(.*)'$`) // TODO how is ' escaped in the password?
func (s Service) expandMemberOf(a *proto.Account) {
func (s Service) expandMemberOf(a *accountsmsg.Account) {
if a == nil {
return
}
expanded := []*proto.Group{}
expanded := []*accountsmsg.Group{}
for i := range a.MemberOf {
g := &proto.Group{}
g := &accountsmsg.Group{}
// TODO resolve by name, when a create or update is issued they may not have an id? fall back to searching the group id in the index?
if err := s.repo.LoadGroup(context.Background(), a.MemberOf[i].Id, g); err == nil {
g.Members = nil // always hide members when expanding
@@ -112,8 +114,8 @@ func (s Service) serviceUserToIndex() (teardownServiceUser func()) {
return func() {}
}
func (s Service) getInMemoryServiceUser() proto.Account {
return proto.Account{
func (s Service) getInMemoryServiceUser() accountsmsg.Account {
return accountsmsg.Account{
AccountEnabled: true,
Id: s.Config.ServiceUser.UUID,
PreferredName: s.Config.ServiceUser.Username,
@@ -126,7 +128,7 @@ func (s Service) getInMemoryServiceUser() proto.Account {
// ListAccounts implements the AccountsServiceHandler interface
// the query contains account properties
func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest, out *proto.ListAccountsResponse) (err error) {
func (s Service) ListAccounts(ctx context.Context, in *accountssvc.ListAccountsRequest, out *accountssvc.ListAccountsResponse) (err error) {
var span trace.Span
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.ListAccounts")
defer span.End()
@@ -152,18 +154,18 @@ func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest
return merrors.Unauthorized(s.id, "account not found or invalid credentials")
}
ids, err := s.index.FindBy(&proto.Account{}, "OnPremisesSamAccountName", match[1])
ids, err := s.index.FindBy(&accountsmsg.Account{}, "OnPremisesSamAccountName", match[1])
if err != nil || len(ids) > 1 {
return merrors.Unauthorized(s.id, "account not found or invalid credentials")
}
if len(ids) == 0 {
ids, err = s.index.FindBy(&proto.Account{}, "Mail", match[1])
ids, err = s.index.FindBy(&accountsmsg.Account{}, "Mail", match[1])
if err != nil || len(ids) != 1 {
return merrors.Unauthorized(s.id, "account not found or invalid credentials")
}
}
a := &proto.Account{}
a := &accountsmsg.Account{}
err = s.repo.LoadAccount(ctx, ids[0], a)
if err != nil || a.PasswordProfile == nil || len(a.PasswordProfile.Password) == 0 {
return merrors.Unauthorized(s.id, "account not found or invalid credentials")
@@ -211,7 +213,7 @@ func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest
}
a.PasswordProfile.Password = ""
out.Accounts = []*proto.Account{a}
out.Accounts = []*accountsmsg.Account{a}
return nil
}
@@ -246,10 +248,10 @@ func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest
}
searchResults, err := s.findAccountsByQuery(ctx, in.Query)
out.Accounts = make([]*proto.Account, 0, len(searchResults))
out.Accounts = make([]*accountsmsg.Account, 0, len(searchResults))
for _, hit := range searchResults {
a := &proto.Account{}
a := &accountsmsg.Account{}
if hit == s.Config.ServiceUser.UUID {
acc := s.getInMemoryServiceUser()
a = &acc
@@ -276,11 +278,11 @@ func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest
}
func (s Service) findAccountsByQuery(ctx context.Context, query string) ([]string, error) {
return s.index.Query(ctx, &proto.Account{}, query)
return s.index.Query(ctx, &accountsmsg.Account{}, query)
}
// GetAccount implements the AccountsServiceHandler interface
func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, out *proto.Account) (err error) {
func (s Service) GetAccount(ctx context.Context, in *accountssvc.GetAccountRequest, out *accountsmsg.Account) (err error) {
var span trace.Span
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.GetAccount")
@@ -337,7 +339,7 @@ func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, ou
}
// CreateAccount implements the AccountsServiceHandler interface
func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountRequest, out *proto.Account) (err error) {
func (s Service) CreateAccount(ctx context.Context, in *accountssvc.CreateAccountRequest, out *accountsmsg.Account) (err error) {
var span trace.Span
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.CreateAccount")
@@ -428,8 +430,8 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
out.GidNumber = userDefaultGID
}
r := proto.ListGroupsResponse{}
err = s.ListGroups(ctx, &proto.ListGroupsRequest{}, &r)
r := accountssvc.ListGroupsResponse{}
err = s.ListGroups(ctx, &accountssvc.ListGroupsRequest{}, &r)
if err != nil {
// rollback account creation
return err
@@ -464,7 +466,7 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
}
// rollbackCreateAccount tries to rollback changes made by `CreateAccount` if parts of it failed.
func (s Service) rollbackCreateAccount(ctx context.Context, acc *proto.Account) {
func (s Service) rollbackCreateAccount(ctx context.Context, acc *accountsmsg.Account) {
err := s.index.Delete(acc)
if err != nil {
s.log.Err(err).Msg("failed to rollback account from indices")
@@ -478,7 +480,7 @@ func (s Service) rollbackCreateAccount(ctx context.Context, acc *proto.Account)
// UpdateAccount implements the AccountsServiceHandler interface
// read only fields are ignored
// TODO how can we unset specific values? using the update mask
func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountRequest, out *proto.Account) (err error) {
func (s Service) UpdateAccount(ctx context.Context, in *accountssvc.UpdateAccountRequest, out *accountsmsg.Account) (err error) {
var span trace.Span
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.UpdateAccount")
@@ -568,7 +570,7 @@ func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountReque
if in.Account.PasswordProfile != nil {
if out.PasswordProfile == nil {
out.PasswordProfile = &proto.PasswordProfile{}
out.PasswordProfile = &accountsmsg.PasswordProfile{}
}
if in.Account.PasswordProfile.Password != "" {
// encrypt password
@@ -601,7 +603,7 @@ func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountReque
}
// We need to reload the old account state to be able to compute the update
old := &proto.Account{}
old := &accountsmsg.Account{}
if err = s.repo.LoadAccount(ctx, id, old); err != nil {
s.log.Error().Err(err).Str("id", out.Id).Msg("could not load old account representation during update, maybe the account got deleted meanwhile?")
return merrors.InternalServerError(s.id, "could not load current account for update: %v", err.Error())
@@ -653,7 +655,7 @@ var updatableAccountPaths = map[string]struct{}{
}
// DeleteAccount implements the AccountsServiceHandler interface
func (s Service) DeleteAccount(ctx context.Context, in *proto.DeleteAccountRequest, out *empty.Empty) (err error) {
func (s Service) DeleteAccount(ctx context.Context, in *accountssvc.DeleteAccountRequest, out *empty.Empty) (err error) {
var span trace.Span
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.DeleteAccount")
@@ -668,7 +670,7 @@ func (s Service) DeleteAccount(ctx context.Context, in *proto.DeleteAccountReque
return merrors.InternalServerError(s.id, "could not clean up account id: %v", err.Error())
}
a := &proto.Account{}
a := &accountsmsg.Account{}
if err = s.repo.LoadAccount(ctx, id, a); err != nil {
if storage.IsNotFoundErr(err) {
return merrors.NotFound(s.id, "account not found: %v", err.Error())
@@ -680,7 +682,7 @@ func (s Service) DeleteAccount(ctx context.Context, in *proto.DeleteAccountReque
// delete member relationship in groups
for i := range a.MemberOf {
err = s.RemoveMember(ctx, &proto.RemoveMemberRequest{
err = s.RemoveMember(ctx, &accountssvc.RemoveMemberRequest{
GroupId: a.MemberOf[i].Id,
AccountId: id,
}, a.MemberOf[i])
@@ -707,7 +709,7 @@ func (s Service) DeleteAccount(ctx context.Context, in *proto.DeleteAccountReque
return
}
func validateAccount(serviceID string, a *proto.Account) error {
func validateAccount(serviceID string, a *accountsmsg.Account) error {
if err := validateAccountPreferredName(serviceID, a); err != nil {
return err
}
@@ -720,21 +722,21 @@ func validateAccount(serviceID string, a *proto.Account) error {
return nil
}
func validateAccountPreferredName(serviceID string, a *proto.Account) error {
func validateAccountPreferredName(serviceID string, a *accountsmsg.Account) error {
if !isValidUsername(a.PreferredName) {
return merrors.BadRequest(serviceID, "preferred_name '%s' must be at least the local part of an email", a.PreferredName)
}
return nil
}
func validateAccountOnPremisesSamAccountName(serviceID string, a *proto.Account) error {
func validateAccountOnPremisesSamAccountName(serviceID string, a *accountsmsg.Account) error {
if !isValidUsername(a.OnPremisesSamAccountName) {
return merrors.BadRequest(serviceID, "on_premises_sam_account_name '%s' must be at least the local part of an email", a.OnPremisesSamAccountName)
}
return nil
}
func validateAccountEmail(serviceID string, a *proto.Account) error {
func validateAccountEmail(serviceID string, a *accountsmsg.Account) error {
if !isValidEmail(a.Mail) {
return merrors.BadRequest(serviceID, "mail '%s' must be a valid email", a.Mail)
}
@@ -808,7 +810,7 @@ func validateUpdate(mask *field_mask.FieldMask, updatablePaths map[string]struct
}
// debugLogAccount returns a debug-log event with detailed account-info, and filtered password data
func (s Service) debugLogAccount(a *proto.Account) *zerolog.Event {
func (s Service) debugLogAccount(a *accountsmsg.Account) *zerolog.Event {
return s.log.Debug().Fields(map[string]interface{}{
"Id": a.Id,
"Mail": a.Mail,
@@ -834,7 +836,7 @@ func (s Service) debugLogAccount(a *proto.Account) *zerolog.Event {
func (s Service) accountExists(ctx context.Context, username, mail, id string) (exists bool, err error) {
var ids []string
ids, err = s.index.FindBy(&proto.Account{}, "preferred_name", username)
ids, err = s.index.FindBy(&accountsmsg.Account{}, "preferred_name", username)
if err != nil {
return false, err
}
@@ -842,7 +844,7 @@ func (s Service) accountExists(ctx context.Context, username, mail, id string) (
return true, nil
}
ids, err = s.index.FindBy(&proto.Account{}, "on_premises_sam_account_name", username)
ids, err = s.index.FindBy(&accountsmsg.Account{}, "on_premises_sam_account_name", username)
if err != nil {
return false, err
}
@@ -850,7 +852,7 @@ func (s Service) accountExists(ctx context.Context, username, mail, id string) (
return true, nil
}
ids, err = s.index.FindBy(&proto.Account{}, "mail", mail)
ids, err = s.index.FindBy(&accountsmsg.Account{}, "mail", mail)
if err != nil {
return false, err
}
@@ -858,7 +860,7 @@ func (s Service) accountExists(ctx context.Context, username, mail, id string) (
return true, nil
}
a := &proto.Account{}
a := &accountsmsg.Account{}
err = s.repo.LoadAccount(ctx, id, a)
if err == nil {
return true, nil
@@ -9,9 +9,11 @@ import (
"testing"
"time"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
"github.com/golang/protobuf/ptypes/empty"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
olog "github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/middleware"
"github.com/owncloud/ocis/ocis-pkg/roles"
@@ -98,10 +100,10 @@ func TestPermissionsListAccounts(t *testing.T) {
defer teardown()
ctx := buildTestCtx(t, scenario.roleIDs)
request := &proto.ListAccountsRequest{
request := &accountssvc.ListAccountsRequest{
Query: scenario.query,
}
response := &proto.ListAccountsResponse{}
response := &accountssvc.ListAccountsResponse{}
err := s.ListAccounts(ctx, request, response)
if scenario.permissionError != nil {
assert.Equal(t, scenario.permissionError, err)
@@ -145,8 +147,8 @@ func TestPermissionsGetAccount(t *testing.T) {
defer teardown()
ctx := buildTestCtx(t, scenario.roleIDs)
request := &proto.GetAccountRequest{}
response := &proto.Account{}
request := &accountssvc.GetAccountRequest{}
response := &accountsmsg.Account{}
err := s.GetAccount(ctx, request, response)
if scenario.permissionError != nil {
assert.Equal(t, scenario.permissionError, err)
@@ -193,8 +195,8 @@ func TestPermissionsCreateAccount(t *testing.T) {
defer teardown()
ctx := buildTestCtx(t, scenario.roleIDs)
request := &proto.CreateAccountRequest{}
response := &proto.Account{}
request := &accountssvc.CreateAccountRequest{}
response := &accountsmsg.Account{}
err := s.CreateAccount(ctx, request, response)
if scenario.permissionError != nil {
assert.Equal(t, scenario.permissionError, err)
@@ -241,8 +243,8 @@ func TestPermissionsUpdateAccount(t *testing.T) {
defer teardown()
ctx := buildTestCtx(t, scenario.roleIDs)
request := &proto.UpdateAccountRequest{}
response := &proto.Account{}
request := &accountssvc.UpdateAccountRequest{}
response := &accountsmsg.Account{}
err := s.UpdateAccount(ctx, request, response)
if scenario.permissionError != nil {
assert.Equal(t, scenario.permissionError, err)
@@ -289,7 +291,7 @@ func TestPermissionsDeleteAccount(t *testing.T) {
defer teardown()
ctx := buildTestCtx(t, scenario.roleIDs)
request := &proto.DeleteAccountRequest{}
request := &accountssvc.DeleteAccountRequest{}
response := &empty.Empty{}
err := s.DeleteAccount(ctx, request, response)
if scenario.permissionError != nil {
+32 -30
View File
@@ -5,22 +5,24 @@ import (
"path"
"strconv"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
"github.com/gofrs/uuid"
"github.com/golang/protobuf/ptypes/empty"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/accounts/pkg/storage"
merrors "go-micro.dev/v4/errors"
p "google.golang.org/protobuf/proto"
)
func (s Service) expandMembers(g *proto.Group) {
func (s Service) expandMembers(g *accountsmsg.Group) {
if g == nil {
return
}
expanded := []*proto.Account{}
expanded := []*accountsmsg.Account{}
for i := range g.Members {
// TODO resolve by name, when a create or update is issued they may not have an id? fall back to searching the group id in the index?
a := &proto.Account{}
a := &accountsmsg.Account{}
if err := s.repo.LoadAccount(context.Background(), g.Members[i].Id, a); err == nil {
expanded = append(expanded, a)
} else {
@@ -32,14 +34,14 @@ func (s Service) expandMembers(g *proto.Group) {
}
// deflateMembers replaces the users of a group with an instance that only contains the id
func (s Service) deflateMembers(g *proto.Group) {
func (s Service) deflateMembers(g *accountsmsg.Group) {
if g == nil {
return
}
deflated := []*proto.Account{}
deflated := []*accountsmsg.Account{}
for i := range g.Members {
if g.Members[i].Id != "" {
deflated = append(deflated, &proto.Account{Id: g.Members[i].Id})
deflated = append(deflated, &accountsmsg.Account{Id: g.Members[i].Id})
} else {
// TODO fetch and use an id when group only has a name but no id
s.log.Error().Str("id", g.Id).Interface("account", g.Members[i]).Msg("resolving members by name is not implemented yet")
@@ -49,7 +51,7 @@ func (s Service) deflateMembers(g *proto.Group) {
}
// ListGroups implements the GroupsServiceHandler interface
func (s Service) ListGroups(ctx context.Context, in *proto.ListGroupsRequest, out *proto.ListGroupsResponse) (err error) {
func (s Service) ListGroups(ctx context.Context, in *accountssvc.ListGroupsRequest, out *accountssvc.ListGroupsResponse) (err error) {
if in.Query == "" {
err = s.repo.LoadGroups(ctx, &out.Groups)
if err != nil {
@@ -68,10 +70,10 @@ func (s Service) ListGroups(ctx context.Context, in *proto.ListGroupsRequest, ou
}
searchResults, err := s.findGroupsByQuery(ctx, in.Query)
out.Groups = make([]*proto.Group, 0, len(searchResults))
out.Groups = make([]*accountsmsg.Group, 0, len(searchResults))
for _, hit := range searchResults {
g := &proto.Group{}
g := &accountsmsg.Group{}
if err = s.repo.LoadGroup(ctx, hit, g); err != nil {
s.log.Error().Err(err).Str("group", hit).Msg("could not load group, skipping")
continue
@@ -88,11 +90,11 @@ func (s Service) ListGroups(ctx context.Context, in *proto.ListGroupsRequest, ou
return
}
func (s Service) findGroupsByQuery(ctx context.Context, query string) ([]string, error) {
return s.index.Query(ctx, &proto.Group{}, query)
return s.index.Query(ctx, &accountsmsg.Group{}, query)
}
// GetGroup implements the GroupsServiceHandler interface
func (s Service) GetGroup(c context.Context, in *proto.GetGroupRequest, out *proto.Group) (err error) {
func (s Service) GetGroup(c context.Context, in *accountssvc.GetGroupRequest, out *accountsmsg.Group) (err error) {
var id string
if id, err = cleanupID(in.Id); err != nil {
return merrors.InternalServerError(s.id, "could not clean up group id: %v", err.Error())
@@ -116,7 +118,7 @@ func (s Service) GetGroup(c context.Context, in *proto.GetGroupRequest, out *pro
}
// CreateGroup implements the GroupsServiceHandler interface
func (s Service) CreateGroup(c context.Context, in *proto.CreateGroupRequest, out *proto.Group) (err error) {
func (s Service) CreateGroup(c context.Context, in *accountssvc.CreateGroupRequest, out *accountsmsg.Group) (err error) {
if in.Group == nil {
return merrors.InternalServerError(s.id, "invalid group: empty")
}
@@ -159,7 +161,7 @@ func (s Service) CreateGroup(c context.Context, in *proto.CreateGroupRequest, ou
}
// rollbackCreateGroup tries to rollback changes made by `CreateGroup` if parts of it failed.
func (s Service) rollbackCreateGroup(ctx context.Context, group *proto.Group) {
func (s Service) rollbackCreateGroup(ctx context.Context, group *accountsmsg.Group) {
err := s.index.Delete(group)
if err != nil {
s.log.Err(err).Msg("failed to rollback group from indices")
@@ -171,18 +173,18 @@ func (s Service) rollbackCreateGroup(ctx context.Context, group *proto.Group) {
}
// UpdateGroup implements the GroupsServiceHandler interface
func (s Service) UpdateGroup(c context.Context, in *proto.UpdateGroupRequest, out *proto.Group) (err error) {
func (s Service) UpdateGroup(c context.Context, in *accountssvc.UpdateGroupRequest, out *accountsmsg.Group) (err error) {
return merrors.InternalServerError(s.id, "not implemented")
}
// DeleteGroup implements the GroupsServiceHandler interface
func (s Service) DeleteGroup(c context.Context, in *proto.DeleteGroupRequest, out *empty.Empty) (err error) {
func (s Service) DeleteGroup(c context.Context, in *accountssvc.DeleteGroupRequest, out *empty.Empty) (err error) {
var id string
if id, err = cleanupID(in.Id); err != nil {
return merrors.InternalServerError(s.id, "could not clean up group id: %v", err.Error())
}
g := &proto.Group{}
g := &accountsmsg.Group{}
if err = s.repo.LoadGroup(c, id, g); err != nil {
if storage.IsNotFoundErr(err) {
return merrors.NotFound(s.id, "group not found: %v", err.Error())
@@ -192,7 +194,7 @@ func (s Service) DeleteGroup(c context.Context, in *proto.DeleteGroupRequest, ou
// delete memberof relationship in users
for i := range g.Members {
err = s.RemoveMember(c, &proto.RemoveMemberRequest{
err = s.RemoveMember(c, &accountssvc.RemoveMemberRequest{
AccountId: g.Members[i].Id,
GroupId: id,
}, g)
@@ -219,7 +221,7 @@ func (s Service) DeleteGroup(c context.Context, in *proto.DeleteGroupRequest, ou
}
// AddMember implements the GroupsServiceHandler interface
func (s Service) AddMember(c context.Context, in *proto.AddMemberRequest, out *proto.Group) (err error) {
func (s Service) AddMember(c context.Context, in *accountssvc.AddMemberRequest, out *accountsmsg.Group) (err error) {
// cleanup ids
var groupID string
if groupID, err = cleanupID(in.GroupId); err != nil {
@@ -232,7 +234,7 @@ func (s Service) AddMember(c context.Context, in *proto.AddMemberRequest, out *p
}
// load structs
a := &proto.Account{}
a := &accountsmsg.Account{}
if err = s.repo.LoadAccount(c, accountID, a); err != nil {
if storage.IsNotFoundErr(err) {
return merrors.NotFound(s.id, "group not found: %v", err.Error())
@@ -240,7 +242,7 @@ func (s Service) AddMember(c context.Context, in *proto.AddMemberRequest, out *p
return merrors.InternalServerError(s.id, "could not load group: %v", err.Error())
}
g := &proto.Group{}
g := &accountsmsg.Group{}
if err = s.repo.LoadGroup(c, groupID, g); err != nil {
if storage.IsNotFoundErr(err) {
return merrors.NotFound(s.id, "could not load group: %v", err.Error())
@@ -255,7 +257,7 @@ func (s Service) AddMember(c context.Context, in *proto.AddMemberRequest, out *p
alreadyRelated = true
}
}
aref := &proto.Account{
aref := &accountsmsg.Account{
Id: a.Id,
}
if !alreadyRelated {
@@ -271,7 +273,7 @@ func (s Service) AddMember(c context.Context, in *proto.AddMemberRequest, out *p
}
}
// only store the reference to prevent recursion when marshaling json
gref := &proto.Group{
gref := &accountsmsg.Group{
Id: g.Id,
}
if !alreadyRelated {
@@ -292,7 +294,7 @@ func (s Service) AddMember(c context.Context, in *proto.AddMemberRequest, out *p
}
// RemoveMember implements the GroupsServiceHandler interface
func (s Service) RemoveMember(c context.Context, in *proto.RemoveMemberRequest, out *proto.Group) (err error) {
func (s Service) RemoveMember(c context.Context, in *accountssvc.RemoveMemberRequest, out *accountsmsg.Group) (err error) {
// cleanup ids
var groupID string
@@ -306,7 +308,7 @@ func (s Service) RemoveMember(c context.Context, in *proto.RemoveMemberRequest,
}
// load structs
a := &proto.Account{}
a := &accountsmsg.Account{}
if err = s.repo.LoadAccount(c, accountID, a); err != nil {
if storage.IsNotFoundErr(err) {
return merrors.NotFound(s.id, "could not load account: %v", err.Error())
@@ -315,7 +317,7 @@ func (s Service) RemoveMember(c context.Context, in *proto.RemoveMemberRequest,
return merrors.InternalServerError(s.id, "could not load account: %v", err.Error())
}
g := &proto.Group{}
g := &accountsmsg.Group{}
if err = s.repo.LoadGroup(c, groupID, g); err != nil {
if storage.IsNotFoundErr(err) {
return merrors.NotFound(s.id, "could not load group: %v", err.Error())
@@ -325,7 +327,7 @@ func (s Service) RemoveMember(c context.Context, in *proto.RemoveMemberRequest,
}
//remove the account from the group if it exists
newMembers := []*proto.Account{}
newMembers := []*accountsmsg.Account{}
for i := range g.Members {
if g.Members[i].Id != a.Id {
newMembers = append(newMembers, g.Members[i])
@@ -334,7 +336,7 @@ func (s Service) RemoveMember(c context.Context, in *proto.RemoveMemberRequest,
g.Members = newMembers
// remove the group from the account if it exists
newGroups := []*proto.Group{}
newGroups := []*accountsmsg.Group{}
for i := range a.MemberOf {
if a.MemberOf[i].Id != g.Id {
newGroups = append(newGroups, a.MemberOf[i])
@@ -358,14 +360,14 @@ func (s Service) RemoveMember(c context.Context, in *proto.RemoveMemberRequest,
}
// ListMembers implements the GroupsServiceHandler interface
func (s Service) ListMembers(c context.Context, in *proto.ListMembersRequest, out *proto.ListMembersResponse) (err error) {
func (s Service) ListMembers(c context.Context, in *accountssvc.ListMembersRequest, out *accountssvc.ListMembersResponse) (err error) {
// cleanup ids
var groupID string
if groupID, err = cleanupID(in.Id); err != nil {
return merrors.InternalServerError(s.id, "could not clean up group id: %v", err.Error())
}
g := &proto.Group{}
g := &accountsmsg.Group{}
if err = s.repo.LoadGroup(c, groupID, g); err != nil {
if storage.IsNotFoundErr(err) {
return merrors.NotFound(s.id, "group not found: %v", err.Error())
+15 -13
View File
@@ -4,16 +4,18 @@ import (
"context"
"fmt"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
"github.com/owncloud/ocis/accounts/pkg/storage"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/indexer"
"github.com/owncloud/ocis/ocis-pkg/indexer/config"
"github.com/owncloud/ocis/ocis-pkg/indexer/option"
)
// RebuildIndex deletes all indices (in memory and on storage) and rebuilds them from scratch.
func (s Service) RebuildIndex(ctx context.Context, request *proto.RebuildIndexRequest, response *proto.RebuildIndexResponse) error {
func (s Service) RebuildIndex(ctx context.Context, request *accountssvc.RebuildIndexRequest, response *accountssvc.RebuildIndexResponse) error {
if err := s.index.Reset(); err != nil {
return fmt.Errorf("failed to delete index containers: %w", err)
}
@@ -36,26 +38,26 @@ func (s Service) RebuildIndex(ctx context.Context, request *proto.RebuildIndexRe
// recreateContainers adds all indices to the indexer that we have for this service.
func recreateContainers(idx *indexer.Indexer, cfg *config.Config) error {
// Accounts
if err := idx.AddIndex(&proto.Account{}, "Id", "Id", "accounts", "non_unique", nil, true); err != nil {
if err := idx.AddIndex(&accountsmsg.Account{}, "Id", "Id", "accounts", "non_unique", nil, true); err != nil {
return err
}
if err := idx.AddIndex(&proto.Account{}, "DisplayName", "Id", "accounts", "non_unique", nil, true); err != nil {
if err := idx.AddIndex(&accountsmsg.Account{}, "DisplayName", "Id", "accounts", "non_unique", nil, true); err != nil {
return err
}
if err := idx.AddIndex(&proto.Account{}, "Mail", "Id", "accounts", "unique", nil, true); err != nil {
if err := idx.AddIndex(&accountsmsg.Account{}, "Mail", "Id", "accounts", "unique", nil, true); err != nil {
return err
}
if err := idx.AddIndex(&proto.Account{}, "OnPremisesSamAccountName", "Id", "accounts", "unique", nil, true); err != nil {
if err := idx.AddIndex(&accountsmsg.Account{}, "OnPremisesSamAccountName", "Id", "accounts", "unique", nil, true); err != nil {
return err
}
if err := idx.AddIndex(&proto.Account{}, "PreferredName", "Id", "accounts", "unique", nil, true); err != nil {
if err := idx.AddIndex(&accountsmsg.Account{}, "PreferredName", "Id", "accounts", "unique", nil, true); err != nil {
return err
}
if err := idx.AddIndex(&proto.Account{}, "UidNumber", "Id", "accounts", "autoincrement", &option.Bound{
if err := idx.AddIndex(&accountsmsg.Account{}, "UidNumber", "Id", "accounts", "autoincrement", &option.Bound{
Lower: cfg.Index.UID.Lower,
Upper: cfg.Index.UID.Upper,
}, false); err != nil {
@@ -63,15 +65,15 @@ func recreateContainers(idx *indexer.Indexer, cfg *config.Config) error {
}
// Groups
if err := idx.AddIndex(&proto.Group{}, "OnPremisesSamAccountName", "Id", "groups", "unique", nil, false); err != nil {
if err := idx.AddIndex(&accountsmsg.Group{}, "OnPremisesSamAccountName", "Id", "groups", "unique", nil, false); err != nil {
return err
}
if err := idx.AddIndex(&proto.Group{}, "DisplayName", "Id", "groups", "non_unique", nil, false); err != nil {
if err := idx.AddIndex(&accountsmsg.Group{}, "DisplayName", "Id", "groups", "non_unique", nil, false); err != nil {
return err
}
if err := idx.AddIndex(&proto.Group{}, "GidNumber", "Id", "groups", "autoincrement", &option.Bound{
if err := idx.AddIndex(&accountsmsg.Group{}, "GidNumber", "Id", "groups", "autoincrement", &option.Bound{
Lower: cfg.Index.GID.Lower,
Upper: cfg.Index.GID.Upper,
}, false); err != nil {
@@ -83,7 +85,7 @@ func recreateContainers(idx *indexer.Indexer, cfg *config.Config) error {
// reindexDocuments loads all existing documents and adds them to the index.
func reindexDocuments(ctx context.Context, repo storage.Repo, index *indexer.Indexer) error {
accounts := make([]*proto.Account, 0)
accounts := make([]*accountsmsg.Account, 0)
if err := repo.LoadAccounts(ctx, &accounts); err != nil {
return err
}
@@ -94,7 +96,7 @@ func reindexDocuments(ctx context.Context, repo storage.Repo, index *indexer.Ind
}
}
groups := make([]*proto.Group, 0)
groups := make([]*accountsmsg.Group, 0)
if err := repo.LoadGroups(ctx, &groups); err != nil {
return err
}
+28 -28
View File
@@ -8,6 +8,7 @@ import (
"strings"
"time"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
"github.com/pkg/errors"
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
@@ -18,7 +19,6 @@ import (
idxerrs "github.com/owncloud/ocis/ocis-pkg/indexer/errors"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/log"
oreg "github.com/owncloud/ocis/ocis-pkg/registry"
"github.com/owncloud/ocis/ocis-pkg/roles"
@@ -162,7 +162,7 @@ func configFromSvc(cfg *config.Config) (*idxcfg.Config, error) {
}
func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
accounts := []proto.Account{
accounts := []accountsmsg.Account{
{
Id: "4c510ada-c86b-4815-8820-42cdf82c3d51",
PreferredName: "einstein",
@@ -171,11 +171,11 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
DisplayName: "Albert Einstein",
UidNumber: 20000,
GidNumber: 30000,
PasswordProfile: &proto.PasswordProfile{
PasswordProfile: &accountsmsg.PasswordProfile{
Password: "$2a$11$4WNffzgU/WrIRiDnwu8OnOwgOIIUqR/2Ptvp7WJAQCTSgSrylyuvC",
},
AccountEnabled: true,
MemberOf: []*proto.Group{
MemberOf: []*accountsmsg.Group{
{Id: "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa"}, // users
{Id: "6040aa17-9c64-4fef-9bd0-77234d71bad0"}, // sailing-lovers
{Id: "dd58e5ec-842e-498b-8800-61f2ec6f911f"}, // violin-haters
@@ -190,11 +190,11 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
DisplayName: "Marie Curie",
UidNumber: 20001,
GidNumber: 30000,
PasswordProfile: &proto.PasswordProfile{
PasswordProfile: &accountsmsg.PasswordProfile{
Password: "$2a$11$Wu2XcDnE6G2No8C88FVWluNHyXuQQi0cHzSe82Vni8AdwIO12fphC",
},
AccountEnabled: true,
MemberOf: []*proto.Group{
MemberOf: []*accountsmsg.Group{
{Id: "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa"}, // users
{Id: "7b87fd49-286e-4a5f-bafd-c535d5dd997a"}, // radium-lovers
{Id: "cedc21aa-4072-4614-8676-fa9165f598ff"}, // polonium-lovers
@@ -209,11 +209,11 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
DisplayName: "Richard Feynman",
UidNumber: 20002,
GidNumber: 30000,
PasswordProfile: &proto.PasswordProfile{
PasswordProfile: &accountsmsg.PasswordProfile{
Password: "$2a$11$6Lak4zh1xUkpObg2rrOotOTdQYGj2Uu/sowcVLhub.8qYIr.CxzEW",
},
AccountEnabled: true,
MemberOf: []*proto.Group{
MemberOf: []*accountsmsg.Group{
{Id: "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa"}, // users
{Id: "a1726108-01f8-4c30-88df-2b1a9d1cba1a"}, // quantum-lovers
{Id: "167cbee2-0518-455a-bfb2-031fe0621e5d"}, // philosophy-haters
@@ -229,11 +229,11 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
DisplayName: "Maurice Moss",
UidNumber: 20003,
GidNumber: 30000,
PasswordProfile: &proto.PasswordProfile{
PasswordProfile: &accountsmsg.PasswordProfile{
Password: "$2a$11$jvI6PHuvrimpcCHzL2Q2WOqfm1FGdYAuSYZBDahr/B48fpiFxyDy2",
},
AccountEnabled: true,
MemberOf: []*proto.Group{
MemberOf: []*accountsmsg.Group{
{Id: "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa"}, // users
},
},
@@ -245,11 +245,11 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
DisplayName: "Admin",
UidNumber: 20004,
GidNumber: 30000,
PasswordProfile: &proto.PasswordProfile{
PasswordProfile: &accountsmsg.PasswordProfile{
Password: "$2a$11$En9VIUtqOdDyUl.LuUq2KeuBb5A2n8zE0lkJ2v6IDRSaOamhNq6Uu",
},
AccountEnabled: true,
MemberOf: []*proto.Group{
MemberOf: []*accountsmsg.Group{
{Id: "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa"}, // users
},
},
@@ -262,11 +262,11 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
DisplayName: "Kopano IDP",
UidNumber: 10000,
GidNumber: 15000,
PasswordProfile: &proto.PasswordProfile{
PasswordProfile: &accountsmsg.PasswordProfile{
Password: "$2y$12$ywfGLDPsSlBTVZU0g.2GZOPO8Wap3rVOpm8e3192VlytNdGWH7x72",
},
AccountEnabled: true,
MemberOf: []*proto.Group{
MemberOf: []*accountsmsg.Group{
{Id: "34f38767-c937-4eb6-b847-1c175829a2a0"}, // sysusers
},
},
@@ -278,11 +278,11 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
DisplayName: "Reva Inter Operability Platform",
UidNumber: 10001,
GidNumber: 15000,
PasswordProfile: &proto.PasswordProfile{
PasswordProfile: &accountsmsg.PasswordProfile{
Password: "$2a$11$40xzy3rO8Tq4j2VkFbKz8Ow19BRaqaixEjAR0IbvQXxtOvMtkjwzy",
},
AccountEnabled: true,
MemberOf: []*proto.Group{
MemberOf: []*accountsmsg.Group{
{Id: "34f38767-c937-4eb6-b847-1c175829a2a0"}, // sysusers
},
},
@@ -300,7 +300,7 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
continue
}
a := &proto.Account{}
a := &accountsmsg.Account{}
err := s.repo.LoadAccount(context.Background(), accounts[i].Id, a)
if !storage.IsNotFoundErr(err) {
continue // account already exists -> do not overwrite
@@ -344,35 +344,35 @@ func (s Service) createDefaultAccounts(withDemoAccounts bool) (err error) {
}
func (s Service) createDefaultGroups(withDemoGroups bool) (err error) {
groups := []proto.Group{
{Id: "34f38767-c937-4eb6-b847-1c175829a2a0", GidNumber: 15000, OnPremisesSamAccountName: "sysusers", DisplayName: "Technical users", Description: "A group for technical users. They should not show up in sharing dialogs.", Members: []*proto.Account{
groups := []accountsmsg.Group{
{Id: "34f38767-c937-4eb6-b847-1c175829a2a0", GidNumber: 15000, OnPremisesSamAccountName: "sysusers", DisplayName: "Technical users", Description: "A group for technical users. They should not show up in sharing dialogs.", Members: []*accountsmsg.Account{
{Id: "820ba2a1-3f54-4538-80a4-2d73007e30bf"}, // idp
{Id: "bc596f3c-c955-4328-80a0-60d018b4ad57"}, // reva
}},
{Id: "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa", GidNumber: 30000, OnPremisesSamAccountName: "users", DisplayName: "Users", Description: "A group every normal user belongs to.", Members: []*proto.Account{
{Id: "509a9dcd-bb37-4f4f-a01a-19dca27d9cfa", GidNumber: 30000, OnPremisesSamAccountName: "users", DisplayName: "Users", Description: "A group every normal user belongs to.", Members: []*accountsmsg.Account{
{Id: "4c510ada-c86b-4815-8820-42cdf82c3d51"}, // einstein
{Id: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"}, // marie
{Id: "932b4540-8d16-481e-8ef4-588e4b6b151c"}, // feynman
}},
{Id: "6040aa17-9c64-4fef-9bd0-77234d71bad0", GidNumber: 30001, OnPremisesSamAccountName: "sailing-lovers", DisplayName: "Sailing lovers", Members: []*proto.Account{
{Id: "6040aa17-9c64-4fef-9bd0-77234d71bad0", GidNumber: 30001, OnPremisesSamAccountName: "sailing-lovers", DisplayName: "Sailing lovers", Members: []*accountsmsg.Account{
{Id: "4c510ada-c86b-4815-8820-42cdf82c3d51"}, // einstein
}},
{Id: "dd58e5ec-842e-498b-8800-61f2ec6f911f", GidNumber: 30002, OnPremisesSamAccountName: "violin-haters", DisplayName: "Violin haters", Members: []*proto.Account{
{Id: "dd58e5ec-842e-498b-8800-61f2ec6f911f", GidNumber: 30002, OnPremisesSamAccountName: "violin-haters", DisplayName: "Violin haters", Members: []*accountsmsg.Account{
{Id: "4c510ada-c86b-4815-8820-42cdf82c3d51"}, // einstein
}},
{Id: "7b87fd49-286e-4a5f-bafd-c535d5dd997a", GidNumber: 30003, OnPremisesSamAccountName: "radium-lovers", DisplayName: "Radium lovers", Members: []*proto.Account{
{Id: "7b87fd49-286e-4a5f-bafd-c535d5dd997a", GidNumber: 30003, OnPremisesSamAccountName: "radium-lovers", DisplayName: "Radium lovers", Members: []*accountsmsg.Account{
{Id: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"}, // marie
}},
{Id: "cedc21aa-4072-4614-8676-fa9165f598ff", GidNumber: 30004, OnPremisesSamAccountName: "polonium-lovers", DisplayName: "Polonium lovers", Members: []*proto.Account{
{Id: "cedc21aa-4072-4614-8676-fa9165f598ff", GidNumber: 30004, OnPremisesSamAccountName: "polonium-lovers", DisplayName: "Polonium lovers", Members: []*accountsmsg.Account{
{Id: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"}, // marie
}},
{Id: "a1726108-01f8-4c30-88df-2b1a9d1cba1a", GidNumber: 30005, OnPremisesSamAccountName: "quantum-lovers", DisplayName: "Quantum lovers", Members: []*proto.Account{
{Id: "a1726108-01f8-4c30-88df-2b1a9d1cba1a", GidNumber: 30005, OnPremisesSamAccountName: "quantum-lovers", DisplayName: "Quantum lovers", Members: []*accountsmsg.Account{
{Id: "932b4540-8d16-481e-8ef4-588e4b6b151c"}, // feynman
}},
{Id: "167cbee2-0518-455a-bfb2-031fe0621e5d", GidNumber: 30006, OnPremisesSamAccountName: "philosophy-haters", DisplayName: "Philosophy haters", Members: []*proto.Account{
{Id: "167cbee2-0518-455a-bfb2-031fe0621e5d", GidNumber: 30006, OnPremisesSamAccountName: "philosophy-haters", DisplayName: "Philosophy haters", Members: []*accountsmsg.Account{
{Id: "932b4540-8d16-481e-8ef4-588e4b6b151c"}, // feynman
}},
{Id: "262982c1-2362-4afa-bfdf-8cbfef64a06e", GidNumber: 30007, OnPremisesSamAccountName: "physics-lovers", DisplayName: "Physics lovers", Members: []*proto.Account{
{Id: "262982c1-2362-4afa-bfdf-8cbfef64a06e", GidNumber: 30007, OnPremisesSamAccountName: "physics-lovers", DisplayName: "Physics lovers", Members: []*accountsmsg.Account{
{Id: "4c510ada-c86b-4815-8820-42cdf82c3d51"}, // einstein
{Id: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"}, // marie
{Id: "932b4540-8d16-481e-8ef4-588e4b6b151c"}, // feynman
@@ -389,7 +389,7 @@ func (s Service) createDefaultGroups(withDemoGroups bool) (err error) {
continue
}
g := &proto.Group{}
g := &accountsmsg.Group{}
err := s.repo.LoadGroup(context.Background(), groups[i].Id, g)
if !storage.IsNotFoundErr(err) {
continue // group already exists -> do not overwrite