Skip to content

Commit

Permalink
return default values when mdc is not initialized
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Mar 1, 2022
1 parent 492419e commit 3048563
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
14 changes: 14 additions & 0 deletions settings/pkg/store/metadata/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import (

"github.com/gofrs/uuid"
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v0"
"github.com/owncloud/ocis/settings/pkg/store/defaults"
)

// ListRoleAssignments loads and returns all role assignments matching the given assignment identifier.
func (s *Store) ListRoleAssignments(accountUUID string) ([]*settingsmsg.UserRoleAssignment, error) {
if s.mdc == nil {
return defaultRoleAssignments(accountUUID), nil
}
s.Init()
assIDs, err := s.mdc.ReadDir(nil, accountPath(accountUUID))
if err != nil {
Expand Down Expand Up @@ -86,6 +90,16 @@ func (s *Store) RemoveRoleAssignment(assignmentID string) error {
return fmt.Errorf("assignmentID '%s' not found", assignmentID)
}

func defaultRoleAssignments(accID string) []*settingsmsg.UserRoleAssignment {
var assmnts []*settingsmsg.UserRoleAssignment
for _, r := range defaults.DefaultRoleAssignments() {
if r.AccountUuid == accID {
assmnts = append(assmnts, r)
}
}
return assmnts
}

func accountPath(accountUUID string) string {
return fmt.Sprintf("%s/%s", accountsFolderLocation, accountUUID)
}
Expand Down
37 changes: 14 additions & 23 deletions settings/pkg/store/metadata/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,16 @@ import (

"github.com/gofrs/uuid"
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v0"
"github.com/owncloud/ocis/settings/pkg/store/defaults"
)

// ListBundles returns all bundles in the dataPath folder that match the given type.
func (s *Store) ListBundles(bundleType settingsmsg.Bundle_Type, bundleIDs []string) ([]*settingsmsg.Bundle, error) {
// TODO: this is needed for initialization - we need to find a better way to fix this
if s.mdc == nil && len(bundleIDs) == 1 && bundleIDs[0] == "71881883-1768-46bd-a24d-a356a2afdf7f" {
return []*settingsmsg.Bundle{{
Id: "71881883-1768-46bd-a24d-a356a2afdf7f",
Settings: []*settingsmsg.Setting{
{
Id: "8e587774-d929-4215-910b-a317b1e80f73",
Name: "account-management",
DisplayName: "Account Management",
Description: "This permission gives full access to everything that is related to account management.",
Resource: &settingsmsg.Resource{
Type: settingsmsg.Resource_TYPE_USER,
Id: "all",
},
Value: &settingsmsg.Setting_PermissionValue{
PermissionValue: &settingsmsg.Permission{
Operation: settingsmsg.Permission_OPERATION_READWRITE,
Constraint: settingsmsg.Permission_CONSTRAINT_ALL,
},
},
},
},
}}, nil
if s.mdc == nil {
return defaultBundle(bundleType, bundleIDs[0]), nil
}
s.Init()
//s.Init()
var bundles []*settingsmsg.Bundle
for _, id := range bundleIDs {
b, err := s.mdc.SimpleDownload(nil, bundlePath(id))
Expand Down Expand Up @@ -113,3 +94,13 @@ func (s *Store) RemoveSettingFromBundle(bundleID string, settingID string) error
func bundlePath(id string) string {
return fmt.Sprintf("%s/%s", bundleFolderLocation, id)
}

func defaultBundle(bundleType settingsmsg.Bundle_Type, bundleID string) []*settingsmsg.Bundle {
var bundles []*settingsmsg.Bundle
for _, b := range defaults.GenerateBundlesDefaultRoles() {
if b.Type == bundleType && b.Id == bundleID {
bundles = append(bundles, b)
}
}
return bundles
}
31 changes: 13 additions & 18 deletions settings/pkg/store/metadata/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,22 @@ type Store struct {

// Init initialize the store once, later calls are noops
func (s *Store) Init() {
if s.mdc != nil {
return
}

s.l.Lock()
defer s.l.Unlock()

var err error
s.init.Do(func() {
//b := backoff.NewExponentialBackOff()
//b.MaxElapsedTime = 4 * time.Second
//backoff.Retry(func() error {
err = s.initMetadataClient(NewMetadataClient(s.cfg))
//return err
//s.init.Do(func() {
//b := backoff.NewExponentialBackOff()
//b.MaxElapsedTime = 4 * time.Second
//backoff.Retry(func() error {
err = s.initMetadataClient(NewMetadataClient(s.cfg))
//return err

//}, b)
//}, b)

})
//})
if err != nil {
log.Fatal(err)
log.Fatal("error initializing metadata client: ", err)
}
}

Expand Down Expand Up @@ -98,10 +95,7 @@ func NewMetadataClient(cfg *config.Config) MetadataClient {

// we need to lazy initialize the MetadataClient because metadata service might not be ready
func (s *Store) initMetadataClient(mdc MetadataClient) error {
s.mdc = mdc

// TODO: this fails because of authentication issues
err := s.mdc.Init(nil, settingsSpaceID)
err := mdc.Init(nil, settingsSpaceID)
if err != nil {
return err
}
Expand All @@ -112,12 +106,13 @@ func (s *Store) initMetadataClient(mdc MetadataClient) error {
bundleFolderLocation,
valuesFolderLocation,
} {
err = s.mdc.MakeDirIfNotExist(nil, p)
err = mdc.MakeDirIfNotExist(nil, p)
if err != nil {
return err
}
}

s.mdc = mdc
if s.initStore != nil {
s.initStore(s)
}
Expand Down

0 comments on commit 3048563

Please sign in to comment.