From 27e7535a427c2a573183886b4b241407abf2cecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Nov 2022 16:03:50 +0100 Subject: [PATCH] Make configs consistent --- README.md | 7 ++++--- config/config.exs | 8 +++++--- lib/livebook/config.ex | 9 ++++++++- lib/livebook_web/endpoint.ex | 6 ++---- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 615b096ec..14e53c7e9 100644 --- a/README.md +++ b/README.md @@ -206,9 +206,6 @@ The following environment variables configure Livebook: * LIVEBOOK_SHUTDOWN_ENABLED - controls if a shutdown button should be shown in the homepage. Set it to "true" to enable it. - * LIVEBOOK_WITHIN_IFRAME - controls if the application is running inside an - iframe. Set it to "true" to enable it. - * LIVEBOOK_TOKEN_ENABLED - controls whether token authentication is enabled. Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to disable it. @@ -216,6 +213,10 @@ The following environment variables configure Livebook: * LIVEBOOK_UPDATE_INSTRUCTIONS_URL - sets the URL to direct the user to for updating Livebook when a new version becomes available. + * LIVEBOOK_WITHIN_IFRAME - controls if the application is running inside an + iframe. Set it to "true" to enable it. If you do enable it, then the application + must run with HTTPS. + If running Livebook as a Docker image or an Elixir release, [the environment diff --git a/config/config.exs b/config/config.exs index 79c8130f4..595f4bf85 100644 --- a/config/config.exs +++ b/config/config.exs @@ -23,12 +23,14 @@ config :livebook, app_service_name: nil, app_service_url: nil, authentication_mode: :token, - learn_notebooks: [], feature_flags: [], + force_ssl_host: nil, + learn_notebooks: [], plugs: [], shutdown_enabled: false, - within_iframe: false, - storage: Livebook.Storage.Ets + storage: Livebook.Storage.Ets, + update_instructions_url: nil, + within_iframe: false # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index 349dc6741..efbb8c61c 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -143,7 +143,14 @@ defmodule Livebook.Config do """ @spec update_instructions_url() :: String.t() | nil def update_instructions_url() do - Application.get_env(:livebook, :update_instructions_url) + Application.fetch_env!(:livebook, :update_instructions_url) + end + + @doc """ + Returns the force ssl host if any. + """ + def force_ssl_host do + Application.fetch_env!(:livebook, :force_ssl_host) end @feature_flags Application.compile_env(:livebook, :feature_flags) diff --git a/lib/livebook_web/endpoint.ex b/lib/livebook_web/endpoint.ex index 7db173b56..56b8bdb4d 100644 --- a/lib/livebook_web/endpoint.ex +++ b/lib/livebook_web/endpoint.ex @@ -94,11 +94,9 @@ defmodule LivebookWeb.Endpoint do end end - @plug_ssl Plug.SSL.init(host: {Application, :get_env, [:livebook, :force_ssl_host, nil]}) + @plug_ssl Plug.SSL.init(host: {Livebook.Config, :force_ssl_host, []}) def force_ssl(conn, _opts) do - force_ssl_host = Application.get_env(:livebook, :force_ssl_host, nil) - - if force_ssl_host do + if Livebook.Config.force_ssl_host() do Plug.SSL.call(conn, @plug_ssl) else conn