web: add TLSConfig.IsEnabled() method - #422
Merged
Merged
Conversation
Add an exported IsEnabled() method on TLSConfig that reports whether TLS is configured, i.e. whether at least one TLS-related field is set. This mirrors the existing check in validateTLSPaths, which is refactored to call it, so behaviour is unchanged. The method lets callers determine whether the server will serve HTTPS without duplicating the field list or reading the certificate files from disk (as ConfigToTLSConfig does). For example, Prometheus infers the scheme of its external URL from the web config file, and previously had to reimplement this check. Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
SuperQ
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Made with LLM for prometheus/prometheus#19241
What
Adds an exported
IsEnabled()method onweb.TLSConfigthat reports whether TLS is configured, i.e. whether at least one TLS-related field (cert/cert_file,key/key_file,client_ca/client_ca_file,client_auth_type) is set.The internal
validateTLSPathsalready performs exactly this check to decide whether to returnerrNoTLSConfig; it is refactored to call the new method, so there is no behavioural change and the single source of truth stays inside the package.Why
Callers sometimes need to know whether the server will serve HTTPS without going through the full
ConfigToTLSConfigpath, which:errNoTLSConfigsentinel, so callers can't distinguish "no TLS configured" from "TLS misconfigured" via the public API; andConcretely, Prometheus infers the scheme of its
--web.external-urlfrom the web config file. Today it has to reimplement this check with a light YAML unmarshal and a presence test for thetls_server_configkey (see prometheus/prometheus#19241, fixing prometheus/prometheus#17236). A presence test is also subtly wrong: an emptytls_server_config:section makes the server serve plain HTTP, but the key is present. ExposingIsEnabled()lets downstream reuse the toolkit's exact semantics instead.Testing
TestTLSConfigIsEnabledcovering empty config, non-enabling fields only, and each enabling field.go test ./web/,go vet ./web/,gofmt, andgolangci-lint run ./web/all clean.