Skip to content

Commit 58b97ac

Browse files
committed
Properly load aliases from config
1 parent 4149b8e commit 58b97ac

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pkg/config/config.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
koanfyaml "github.com/knadh/koanf/parsers/yaml"
1212
"github.com/knadh/koanf/providers/env"
1313
"github.com/knadh/koanf/providers/rawbytes"
14+
"github.com/mitchellh/mapstructure"
1415
"golang.org/x/text/cases"
1516
"golang.org/x/text/language"
1617
)
@@ -197,12 +198,12 @@ type IncomingWebhook struct {
197198

198199
// CloudSlackChannel contains configuration bindings per channel.
199200
type CloudSlackChannel struct {
200-
ChannelBindingsByName `yaml:",inline"`
201+
ChannelBindingsByName `yaml:",inline" mapstructure:",squash"`
201202

202203
// ChannelID is the Slack ID of the channel.
203204
ChannelID string `yaml:"channelID"`
204205
// Alias is an optional public alias for a private channel.
205-
Alias *string `yaml:"alias"`
206+
Alias *string `yaml:"alias,omitempty"`
206207
}
207208

208209
// ChannelBindingsByName contains configuration bindings per channel.
@@ -725,7 +726,20 @@ func LoadWithDefaults(configs [][]byte) (*Config, LoadWithDefaultsDetails, error
725726
}
726727

727728
var cfg Config
728-
err = k.Unmarshal("", &cfg)
729+
err = k.UnmarshalWithConf("", &cfg, koanf.UnmarshalConf{
730+
DecoderConfig: &mapstructure.DecoderConfig{
731+
Squash: true, // needed to properly unmarshal CloudSlack channel's ChannelBindingsByName
732+
733+
// also use defaults from koanf.UnmarshalWithConf
734+
DecodeHook: mapstructure.ComposeDecodeHookFunc(
735+
mapstructure.StringToTimeDurationHookFunc(),
736+
mapstructure.StringToSliceHookFunc(","),
737+
mapstructure.TextUnmarshallerHookFunc()),
738+
Metadata: nil,
739+
Result: &cfg,
740+
WeaklyTypedInput: true,
741+
},
742+
})
729743
if err != nil {
730744
return nil, LoadWithDefaultsDetails{}, err
731745
}

pkg/execute/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ func (e *ConfigExecutor) renderBotkubeConfiguration() (string, error) {
8080
}
8181

8282
outChannel := channel
83-
outChannel.ChannelBindingsByName.Name = *channel.Alias
83+
outChannel.ChannelBindingsByName.Name = fmt.Sprintf("%s (public alias)", *channel.Alias)
84+
outChannel.Alias = nil
8485
val.CloudSlack.Channels[i] = outChannel
8586
}
8687

0 commit comments

Comments
 (0)