diff --git a/src/app/command/bootstrap.go b/src/app/command/bootstrap.go index 8879684..6a9bf0f 100644 --- a/src/app/command/bootstrap.go +++ b/src/app/command/bootstrap.go @@ -57,7 +57,7 @@ type ConfigInfo struct { ConfigType string ConfigPath string Viper configuration.ViperConfig - Readers proxy.ConfigReaders + Readers ConfigReaders } // Bootstrap represents construct that performs start up of the cli @@ -96,9 +96,9 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command { ConfigType: "yaml", ConfigPath: home, Viper: &configuration.GlobalViperConfig{}, - Readers: proxy.ConfigReaders{ - Profiles: &proxy.MsProfilesConfigReader{}, - Sampler: &proxy.MsSamplerConfigReader{}, + Readers: ConfigReaders{ + Profiles: &MsProfilesConfigReader{}, + Sampler: &MsSamplerConfigReader{}, }, }, } diff --git a/src/app/command/config-readers.go b/src/app/command/config-readers.go new file mode 100644 index 0000000..1df1682 --- /dev/null +++ b/src/app/command/config-readers.go @@ -0,0 +1,57 @@ +package command + +import ( + "fmt" + + "github.com/snivilised/cobrass/src/assistant/configuration" + "github.com/snivilised/cobrass/src/clif" + "github.com/snivilised/pixa/src/app/proxy" +) + +type MsProfilesConfigReader struct { +} + +func (r *MsProfilesConfigReader) Read(viper configuration.ViperConfig) (proxy.ProfilesConfig, error) { + // Ideally, the ProfileParameterSet would perform a check against + // the config, but extendio is not aware of config, so it can't + // check. Instead, we can check here. + // + profilesCFG := &proxy.MsProfilesConfig{ + Profiles: make(proxy.ProfilesConfigMap), + } + + if raw := viper.Get("profiles"); raw != nil { + if profiles, ok := raw.(proxy.ProfilesFlagOptionAsAnyPair); ok { + for profile, pv := range profiles { + if pair, ok := pv.(proxy.ProfilesFlagOptionAsAnyPair); ok { + profilesCFG.Profiles[profile] = make(clif.ChangedFlagsMap) + + for flag, optionAsAny := range pair { + profilesCFG.Profiles[profile][flag] = fmt.Sprint(optionAsAny) + } + } + } + } else { + return nil, fmt.Errorf("invalid type for 'profiles'") + } + } + + return profilesCFG, nil +} + +type MsSamplerConfigReader struct{} + +func (r *MsSamplerConfigReader) Read(viper configuration.ViperConfig) (proxy.SamplerConfig, error) { + var ( + samplerCFG proxy.MsSamplerConfig + ) + + err := viper.UnmarshalKey("sampler", &samplerCFG) + + return &samplerCFG, err +} + +type ConfigReaders struct { + Profiles proxy.ProfilesConfigReader + Sampler proxy.SamplerConfigReader +} diff --git a/src/app/proxy/controller-sampler_test.go b/src/app/proxy/controller-sampler_test.go index 831713b..c832eab 100644 --- a/src/app/proxy/controller-sampler_test.go +++ b/src/app/proxy/controller-sampler_test.go @@ -25,8 +25,8 @@ const ( var ( _ proxy.ProfilesConfig = proxy.MsProfilesConfig{} _ proxy.SamplerConfig = &proxy.MsSamplerConfig{} - _ proxy.ProfilesConfigReader = &proxy.MsProfilesConfigReader{} - _ proxy.SamplerConfigReader = &proxy.MsSamplerConfigReader{} + _ proxy.ProfilesConfigReader = &command.MsProfilesConfigReader{} + _ proxy.SamplerConfigReader = &command.MsSamplerConfigReader{} ) type controllerTE struct { @@ -118,7 +118,7 @@ var _ = Describe("SamplerController", Ordered, func() { co.Config.Name = helpers.PixaConfigTestFilename co.Config.ConfigPath = configPath co.Viper = &configuration.GlobalViperConfig{} - co.Config.Readers = proxy.ConfigReaders{ + co.Config.Readers = command.ConfigReaders{ Profiles: mockProfilesReader, Sampler: mockSamplerReader, } diff --git a/src/app/proxy/sampler-config.go b/src/app/proxy/sampler-config.go index 4469bb6..f98235d 100644 --- a/src/app/proxy/sampler-config.go +++ b/src/app/proxy/sampler-config.go @@ -34,11 +34,6 @@ type ( SamplerConfigReader interface { Read(configuration.ViperConfig) (SamplerConfig, error) } - - ConfigReaders struct { - Profiles ProfilesConfigReader - Sampler SamplerConfigReader - } ) type MsProfilesConfig struct { @@ -95,46 +90,3 @@ func (cfg *MsSamplerConfig) NoFiles() uint { func (cfg *MsSamplerConfig) NoFolders() uint { return cfg.Folders } - -type MsProfilesConfigReader struct { -} - -func (r *MsProfilesConfigReader) Read(viper configuration.ViperConfig) (ProfilesConfig, error) { - // Ideally, the ProfileParameterSet would perform a check against - // the config, but extendio is not aware of config, so it can't - // check. Instead, we can check here. - // - profilesCFG := &MsProfilesConfig{ - Profiles: make(ProfilesConfigMap), - } - - if raw := viper.Get("profiles"); raw != nil { - if profiles, ok := raw.(ProfilesFlagOptionAsAnyPair); ok { - for profile, pv := range profiles { - if pair, ok := pv.(ProfilesFlagOptionAsAnyPair); ok { - profilesCFG.Profiles[profile] = make(clif.ChangedFlagsMap) - - for flag, optionAsAny := range pair { - profilesCFG.Profiles[profile][flag] = fmt.Sprint(optionAsAny) - } - } - } - } else { - return nil, fmt.Errorf("invalid type for 'profiles'") - } - } - - return profilesCFG, nil -} - -type MsSamplerConfigReader struct{} - -func (r *MsSamplerConfigReader) Read(viper configuration.ViperConfig) (SamplerConfig, error) { - var ( - samplerCFG MsSamplerConfig - ) - - err := viper.UnmarshalKey("sampler", &samplerCFG) - - return &samplerCFG, err -}