Skip to content

web: add TLSConfig.IsEnabled() method - #422

Merged
SuperQ merged 1 commit into
masterfrom
tlsconfig-isenabled
Jul 23, 2026
Merged

web: add TLSConfig.IsEnabled() method#422
SuperQ merged 1 commit into
masterfrom
tlsconfig-isenabled

Conversation

@krajorama

@krajorama krajorama commented Jul 21, 2026

Copy link
Copy Markdown
Member

Made with LLM for prometheus/prometheus#19241

What

Adds an exported IsEnabled() method on web.TLSConfig that 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 validateTLSPaths already performs exactly this check to decide whether to return errNoTLSConfig; 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 ConfigToTLSConfig path, which:

  • returns the unexported errNoTLSConfig sentinel, so callers can't distinguish "no TLS configured" from "TLS misconfigured" via the public API; and
  • eagerly reads the certificate/key files from disk, which fails when the files don't exist yet — undesirable for callers that only want to know the intended scheme.

Concretely, Prometheus infers the scheme of its --web.external-url from the web config file. Today it has to reimplement this check with a light YAML unmarshal and a presence test for the tls_server_config key (see prometheus/prometheus#19241, fixing prometheus/prometheus#17236). A presence test is also subtly wrong: an empty tls_server_config: section makes the server serve plain HTTP, but the key is present. Exposing IsEnabled() lets downstream reuse the toolkit's exact semantics instead.

Testing

  • New table-driven TestTLSConfigIsEnabled covering empty config, non-enabling fields only, and each enabling field.
  • go test ./web/, go vet ./web/, gofmt, and golangci-lint run ./web/ all clean.

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
SuperQ merged commit 482b52b into master Jul 23, 2026
6 checks passed
@SuperQ
SuperQ deleted the tlsconfig-isenabled branch July 23, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants