Skip to content

Commit

Permalink
fix(registry): update repo profile on successful registration
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Sep 3, 2019
1 parent e3f0238 commit fcdfc05
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (m *ConfigMethods) SetConfig(update *config.Config, set *bool) (err error)
}

if err = update.Validate(); err != nil {
return fmt.Errorf("error validating config: %s", err)
return fmt.Errorf("validating config: %s", err)
}

return m.inst.ChangeConfig(update)
Expand Down
3 changes: 3 additions & 0 deletions lib/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (

// ProfileMethods encapsulates business logic for this node's
// user profile
// TODO (b5) - alterations to user profile are a subset of configuration
// changes. all of this code should be refactored into subroutines of general
// configuration getters & setters
type ProfileMethods struct {
inst *Instance
}
Expand Down
22 changes: 18 additions & 4 deletions lib/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"github.com/qri-io/qri/config"
"github.com/qri-io/qri/registry"
"github.com/qri-io/qri/repo/profile"
)

// RegistryClientMethods defines business logic for working with registries
Expand Down Expand Up @@ -37,8 +38,7 @@ func (m RegistryClientMethods) CreateProfile(p *RegistryProfile, ok *bool) (err
log.Errorf("create profile response: %v", pro)
*p = *pro

cfg := m.configChanges(pro)
return m.inst.ChangeConfig(cfg)
return m.updateConfig(pro)
}

// ProveProfileKey asserts to a registry that this user has control of a
Expand All @@ -56,8 +56,7 @@ func (m RegistryClientMethods) ProveProfileKey(p *RegistryProfile, ok *bool) err
log.Errorf("prove profile response: %v", pro)
*p = *pro

cfg := m.configChanges(pro)
return m.inst.ChangeConfig(cfg)
return m.updateConfig(pro)
}

func (m RegistryClientMethods) configChanges(pro *registry.Profile) *config.Config {
Expand All @@ -74,3 +73,18 @@ func (m RegistryClientMethods) configChanges(pro *registry.Profile) *config.Conf

return cfg
}

func (m RegistryClientMethods) updateConfig(pro *registry.Profile) error {
cfg := m.configChanges(pro)

// TODO (b5) - this should be automatically done by m.inst.ChangeConfig
repoPro, err := profile.NewProfile(cfg.Profile)
if err != nil {
return err
}
if err := m.inst.Repo().SetProfile(repoPro); err != nil {
return err
}

return m.inst.ChangeConfig(cfg)
}

0 comments on commit fcdfc05

Please sign in to comment.