Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/model/config: wrap plugin config in types #1549

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ version: "2"
Version: config.Version2,
Repo: "github.com/example/project",
Domain: "example.com",
Plugins: map[string]interface{}{
Plugins: config.PluginConfigs{
"plugin-x": map[string]interface{}{
"data-1": "single plugin datum",
},
Expand Down Expand Up @@ -144,7 +144,7 @@ plugins:
Version: config.Version2,
Repo: "github.com/example/project",
Domain: "example.com",
Plugins: map[string]interface{}{
Plugins: config.PluginConfigs{
"plugin-x": map[string]interface{}{
"data-1": "single plugin datum",
},
Expand Down
14 changes: 10 additions & 4 deletions pkg/model/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ type Config struct {
// Layout contains a key specifying which plugin created a project.
Layout string `json:"layout,omitempty"`

// Plugins is an arbitrary YAML blob that can be used by external
// plugins for plugin-specific configuration.
Plugins map[string]interface{} `json:"plugins,omitempty"`
// Plugins holds plugin-specific configs mapped by plugin key. These configs should be
// encoded/decoded using EncodePluginConfig/DecodePluginConfig, respectively.
Plugins PluginConfigs `json:"plugins,omitempty"`
}

// PluginConfigs holds a set of arbitrary plugin configuration objects mapped by plugin key.
type PluginConfigs map[string]pluginConfig

// pluginConfig is an arbitrary plugin configuration object.
type pluginConfig interface{}

// IsV1 returns true if it is a v1 project
func (c Config) IsV1() bool {
return c.Version == Version1
Expand Down Expand Up @@ -186,7 +192,7 @@ func (c *Config) EncodePluginConfig(key string, configObj interface{}) error {
return fmt.Errorf("failed to unmarshal %T object bytes: %s", configObj, err)
}
if c.Plugins == nil {
c.Plugins = make(map[string]interface{})
c.Plugins = make(map[string]pluginConfig)
}
c.Plugins[key] = fields
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/model/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var _ = Describe("Config", func() {
pluginConfig = PluginConfig{}
expectedConfig = Config{
Version: Version2,
Plugins: map[string]interface{}{
Plugins: PluginConfigs{
"plugin-x": map[string]interface{}{
"data-1": "",
"data-2": "",
Expand All @@ -72,7 +72,7 @@ var _ = Describe("Config", func() {
}
expectedConfig = Config{
Version: Version2,
Plugins: map[string]interface{}{
Plugins: PluginConfigs{
"plugin-x": map[string]interface{}{
"data-1": "plugin value 1",
"data-2": "plugin value 2",
Expand Down Expand Up @@ -106,7 +106,7 @@ var _ = Describe("Config", func() {
By("Using empty config version 2")
config = Config{
Version: Version2,
Plugins: map[string]interface{}{
Plugins: PluginConfigs{
"plugin-x": map[string]interface{}{},
},
}
Expand All @@ -125,7 +125,7 @@ var _ = Describe("Config", func() {
By("Using config version 2 with extra fields as struct")
config = Config{
Version: Version2,
Plugins: map[string]interface{}{
Plugins: PluginConfigs{
"plugin-x": map[string]interface{}{
"data-1": "plugin value 1",
"data-2": "plugin value 2",
Expand Down