Feat: support HTTPS URLs in the -c/--config flag - #950
Conversation
Allow Bento to fetch its configuration from an HTTPS URL at startup in addition to a local file path. Adds an optional --config-header flag (repeatable) for authenticated endpoints. - URL detection in config loading layer (reader.go, lint.go) - --watcher + HTTPS URL exits with a clear fatal error - env var interpolation works after fetch - bento lint supports HTTPS URLs as positional args - Unit tests for fetchRemoteConfig and ReadYAMLFileLinted Closes warpstreamlabs#939
jem-davies
left a comment
There was a problem hiding this comment.
Would need to document the new feature by changing the documentation strings for the -c / --config flag as well
| var lints []docs.Lint | ||
| var err error | ||
|
|
||
| if strings.HasPrefix(path, "https://") { |
There was a problem hiding this comment.
| if strings.HasPrefix(path, "https://") { | |
| parsedPath, err := url.Parse(path) | |
| if err != nil { | |
| ... | |
| } | |
| if parsedPath.Scheme == "https" || parsedPath.Scheme == "http" { | |
| ... | |
| } |
Could use url.Parse here - if the provided path is a relative filepath ./config.yaml scheme should be empty string, you could also have a scheme file too - file:///Users/.../config.yaml
| } | ||
|
|
||
| func fetchRemoteConfig(url string, headers []string) ([]byte, error) { | ||
| req, err := http.NewRequest(http.MethodGet, url, nil) |
There was a problem hiding this comment.
could use a http.NewRequestWithContext() and pass a context with a short deadline.
| req.Header.Add(strings.TrimSpace(name), strings.TrimSpace(value)) | ||
| } | ||
|
|
||
| client := &http.Client{ |
There was a problem hiding this comment.
I think we might want to expose some more options for the client - such it could work with TLS certificates that are signed with private CA's etc.
There was a problem hiding this comment.
Hello @jem-davies
Thanks for the feedback, i'm just wondering should this reuse existing CLI flags or
env vars, or would you prefer dedicated flags like --config-tls-ca-file ?
|
Hi @Omar1H1 Me and @gregfurman have just been discussing this PR. I am in the position that the config options for this new http client could be handled similarly to the That it would be possible to provide this to Bento in a ./resources.yaml - such it could then subsequently fetch a stream config. Added multiple CLI flags I think wouldn't be the way to go, there is precedent for the majority of config be provided via YAML files. @gregfurman - perhaps was more critical that there is other ways to handle this situation i.e. sidecar / init containers, posting into bento running streams_mode, that we discussed on discord before. That adding this feature is moving the complexity from already existing solutions into Bento. Also Greg mentioned that we could perhaps have the concept of 'hooks', such there would be an 'on_init' hook that would evoke some user-defined logic at start-up and there we could fetch the config. |
|
Hi @jem-davies thanks for the detailed direction. I think what you have suggested is the right way to go. If I may add, maybe naming it I totally understand @gregfurman concerns, the alternatives he mentioned are valid. That said, I do think there's value in making this a first-class feature rather than pushing it to the infrastructure layer. Happy to implement this direction if there's alignment. If not, that's completely fine and I can close the PR for now. maybe a clearer need will come up in the future. |
Summary
Implements #939, allows
-c/--configto accept anhttps://URLin addition to a local file path.
Changes
internal/config/reader.go— URL detection, fetch logic, watcher guardinternal/config/lint.go— URL support forReadYAMLFileLintedinternal/cli/run.go—--config-headerflag definitioninternal/cli/common/reader.go— watcher fatal error, headers wired intoNewReaderinternal/config/reader_test.go— added unit tests forfetchRemoteConfigand remote reader behaviourinternal/config/lint_test.go— new file, unit tests forReadYAMLFileLintedwith remote URLsBehaviour
https://prefix → remote fetch before config parsing--watcher+ URL → exits with fatal error immediately${FOO:default}) still works after fetch--config-header "Name: Value"(repeatable) for auth headersTesting
Known limitations
Only
https://URLs are supported. plainhttp://falls back tofile path behaviour.
bento lint <url>works for public endpoints but does not support--config-header.ReadYAMLFileLintedhas no access to CLI flagsat that call site. Can be addressed in a follow-up.
Open question
As noted in #939. happy to move to a dedicated
--config-urlflag if that is preferred over extending-c.