-
Notifications
You must be signed in to change notification settings - Fork 50
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
Refactor ValidateConfig of all receivers to accept only what is needed #61
Conversation
@@ -42,6 +44,10 @@ type FactoryConfig struct { | |||
Logger logging.Logger | |||
} | |||
|
|||
func (fc *FactoryConfig) Decrypt(key, fallback string) string { | |||
return fc.DecryptFunc(context.Background(), fc.Config.SecureSettings, key, fallback) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a wrapper to hide secure settings and context from notifier's config builder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured it out - this is a nice change - not sure if that context.Background()
might cause us more hard than good in the end but let's roll with it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
To hide implementation details of secrets storage from config parser, and reduce the scope for functions NewConfig. The context will be enclosed upstream (in Grafana) where it makes sense because it provides a secret service that requires context.
77f76d4
to
5bde521
Compare
5bde521
to
3825c1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please look at my comment, I think we need one more quick change.
func NewFactoryConfigForValidateConfigTesting(t *testing.T, m *receivers.NotificationChannelConfig) (receivers.FactoryConfig, error) { | ||
tmpl := templates.ForTests(t) | ||
tmpl.ExternalURL = ParseURLUnsafe("http://localhost") | ||
return receivers.NewFactoryConfig(m, nil, DecryptForTesting, tmpl, &images.UnavailableImageStore{}, func(ctx ...interface{}) logging.Logger { | ||
return &logging.FakeLogger{} | ||
}, "1.2.3") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that all this setup (the templates, the logger, etc) was never used in the places where we setup this configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much, yes
@@ -42,6 +44,10 @@ type FactoryConfig struct { | |||
Logger logging.Logger | |||
} | |||
|
|||
func (fc *FactoryConfig) Decrypt(key, fallback string) string { | |||
return fc.DecryptFunc(context.Background(), fc.Config.SecureSettings, key, fallback) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured it out - this is a nice change - not sure if that context.Background()
might cause us more hard than good in the end but let's roll with it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Currently, every ValidateConfig accepts entire
receivers.FactoryConfig
and takes only 3 fields at best: raw settings, secure settings map, and decrypt function.This PR refactors those functions to accept only two parameters (sometimes one):
func(key string, fallback string) string
as you can see it does not accept the secure settings (and context). The reason is to hide the way secure settings are stored.Also, currently, some functions return
Config
struct and some pointer*Config
. This PR refactors those that return pointer to return struct.No public API of this package are changed.