Skip to content

Commit

Permalink
refine initialization logic again
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 7fcf6f5 commit af5c9f5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
15 changes: 13 additions & 2 deletions settings/pkg/store/metadata/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ import (
// 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 {
if s.mdc == nil && len(bundleIDs) == 1 {
return defaultBundle(bundleType, bundleIDs[0]), nil
}
//s.Init()
s.Init()

if len(bundleIDs) == 0 {
bIDs, err := s.mdc.ReadDir(nil, bundleFolderLocation)
if err != nil {
return nil, err
}

bundleIDs = bIDs
}
var bundles []*settingsmsg.Bundle
for _, id := range bundleIDs {
b, err := s.mdc.SimpleDownload(nil, bundlePath(id))
Expand Down Expand Up @@ -53,6 +62,7 @@ func (s *Store) ReadBundle(bundleID string) (*settingsmsg.Bundle, error) {

// ReadSetting tries to find a setting by the given id within the dataPath.
func (s *Store) ReadSetting(settingID string) (*settingsmsg.Setting, error) {
fmt.Println("ReadSetting not implemented")
return nil, errors.New("not implemented")
}

Expand Down Expand Up @@ -88,6 +98,7 @@ func (s *Store) AddSettingToBundle(bundleID string, setting *settingsmsg.Setting

// RemoveSettingFromBundle removes the setting from the bundle with the given ids.
func (s *Store) RemoveSettingFromBundle(bundleID string, settingID string) error {
fmt.Println("RemoveSettingFromBundle not implemented")
return errors.New("not implemented")
}

Expand Down
37 changes: 34 additions & 3 deletions settings/pkg/store/metadata/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,41 @@ func (s *Store) initMetadataClient(mdc MetadataClient) error {
}
}

s.mdc = mdc
if s.initStore != nil {
s.initStore(s)
for _, p := range defaults.GenerateBundlesDefaultRoles() {
b, err := json.Marshal(p)
if err != nil {
return err
}
err = mdc.SimpleUpload(nil, bundlePath(p.Id), b)
if err != nil {
return err
}
}

for _, p := range defaults.DefaultRoleAssignments() {
accountUUID := p.AccountUuid
roleID := p.RoleId
err = mdc.MakeDirIfNotExist(nil, accountPath(accountUUID))
if err != nil {
return err
}

ass := &settingsmsg.UserRoleAssignment{
Id: uuid.Must(uuid.NewV4()).String(),
AccountUuid: accountUUID,
RoleId: roleID,
}
b, err := json.Marshal(ass)
if err != nil {
return err
}
err = mdc.SimpleUpload(nil, assignmentPath(accountUUID, ass.Id), b)
if err != nil {
return err
}
}

s.mdc = mdc
return nil
}

Expand Down

0 comments on commit af5c9f5

Please sign in to comment.