From 08ef4518b45a92dc4caf126da7cc9bb7c70515f6 Mon Sep 17 00:00:00 2001 From: Andrew Dryga Date: Thu, 9 Mar 2023 17:44:43 -0600 Subject: [PATCH] Do not trim Ecto.Enum values in docs generator (#1495) Closes #1494 --- apps/fz_http/test/fz_http/config_test.exs | 33 +++++++++++++++++++++ apps/fz_http/test/support/docs_generator.ex | 2 -- www/docs/reference/env-vars.mdx | 4 +-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/apps/fz_http/test/fz_http/config_test.exs b/apps/fz_http/test/fz_http/config_test.exs index 606c6fb8a..e0afbf1cd 100644 --- a/apps/fz_http/test/fz_http/config_test.exs +++ b/apps/fz_http/test/fz_http/config_test.exs @@ -67,6 +67,17 @@ defmodule FzHttp.ConfigTest do |> FzHttp.Validator.normalize_url(key) end ) + + defconfig( + :enum, + {:parameterized, Ecto.Enum, Ecto.Enum.init(values: [:value1, :value2, __MODULE__])}, + default: :value1, + dump: fn + :value1 -> :foo + :value2 -> __MODULE__ + other -> other + end + ) end describe "fetch_source_and_config!/1" do @@ -327,6 +338,28 @@ defmodule FzHttp.ConfigTest do compile_config!(Test, :sensitive, %{"SENSITIVE" => "foo"}) end end + + test "returns error on invalid enum values" do + message = """ + Invalid configuration for 'enum' retrieved from environment variable ENUM. + + Errors: + + - `"foo"`: is invalid\ + """ + + assert_raise RuntimeError, message, fn -> + compile_config!(Test, :enum, %{"ENUM" => "foo"}) + end + end + + test "casts module name enums" do + assert compile_config!(Test, :enum, %{"ENUM" => "value1"}) == :foo + assert compile_config!(Test, :enum, %{"ENUM" => "value2"}) == FzHttp.ConfigTest.Test + + assert compile_config!(Test, :enum, %{"ENUM" => "Elixir.FzHttp.ConfigTest.Test"}) == + FzHttp.ConfigTest.Test + end end describe "validate_runtime_config!/0" do diff --git a/apps/fz_http/test/support/docs_generator.ex b/apps/fz_http/test/support/docs_generator.ex index 296764b1e..fbffd1fd5 100644 --- a/apps/fz_http/test/support/docs_generator.ex +++ b/apps/fz_http/test/support/docs_generator.ex @@ -105,13 +105,11 @@ defmodule DocsGenerator do # DEPRECATION 0.8: We remove legacy keys here to prevent people from using it in new installs |> Kernel.--([:smtp, :mailgun, :mandrill, :sendgrid, :post_mark, :sendmail]) |> Enum.map(&to_string/1) - |> Enum.map(&String.trim_leading(&1, "Elixir.")) |> Enum.map_join(", ", &"`#{&1}`") default = default |> Atom.to_string() - |> String.trim_leading("Elixir.") {"One of #{values}", "`#{default}`"} end diff --git a/www/docs/reference/env-vars.mdx b/www/docs/reference/env-vars.mdx index 771c4ac9f..ec5f20979 100644 --- a/www/docs/reference/env-vars.mdx +++ b/www/docs/reference/env-vars.mdx @@ -41,7 +41,7 @@ default). Required fields in **bold**. | **EXTERNAL_URL** | The external URL the web UI will be accessible at.

Must be a valid and public FQDN for ACME SSL issuance to function.

You can add a path suffix if you want to serve firezone from a non-root path, eg: `https://firezone.mycorp.com/vpn`. | string | | | PHOENIX_SECURE_COOKIES | Enable or disable requiring secure cookies. Required for HTTPS. | boolean | true | | PHOENIX_HTTP_PORT | Internal port to listen on for the Phoenix web server. | integer | 13000 | -| PHOENIX_HTTP_PROTOCOL_OPTIONS | Allows to override Cowboy HTTP server options.

Keep in mind though changing those limits can pose a security risk. Other times, browsers and proxies along the way may have equally strict limits, which means the request will still fail or the URL will be pruned.

You can see all supported options at https://ninenines.eu/docs/en/cowboy/2.5/manual/cowboy_http/. | JSON-encoded map | `"[]"` | +| PHOENIX_HTTP_PROTOCOL_OPTIONS | Allows to override Cowboy HTTP server options.

Keep in mind though changing those limits can pose a security risk. Other times, browsers and proxies along the way may have equally strict limits, which means the request will still fail or the URL will be pruned.

You can see all supported options at https://ninenines.eu/docs/en/cowboy/2.5/manual/cowboy_http/. | JSON-encoded map | `{}` | | PHOENIX_EXTERNAL_TRUSTED_PROXIES | List of trusted reverse proxies.

This is used to determine the correct IP address of the client when the application is behind a reverse proxy by skipping a trusted proxy IP from a list of possible source IPs. | JSON-encoded list | `"[]"` | | PHOENIX_PRIVATE_CLIENTS | List of trusted clients.

This is used to determine the correct IP address of the client when the application is behind a reverse proxy by picking a trusted client IP from a list of possible source IPs. | JSON-encoded list | `"[]"` | @@ -123,7 +123,7 @@ All secrets should be a **base64-encoded string**. | Env Key | Description | Format | Default | | ------ | --------------- | ------ | ------- | | OUTBOUND_EMAIL_FROM | From address to use for sending outbound emails. If not set, sending email will be disabled (default). | string | generated | -| OUTBOUND_EMAIL_ADAPTER | Method to use for sending outbound email. | One of `Swoosh.Adapters.AmazonSES`, `Swoosh.Adapters.CustomerIO`, `Swoosh.Adapters.Dyn`, `Swoosh.Adapters.ExAwsAmazonSES`, `Swoosh.Adapters.Gmail`, `Swoosh.Adapters.MailPace`, `Swoosh.Adapters.Mailgun`, `Swoosh.Adapters.Mailjet`, `Swoosh.Adapters.Mandrill`, `Swoosh.Adapters.Postmark`, `Swoosh.Adapters.ProtonBridge`, `Swoosh.Adapters.SMTP`, `Swoosh.Adapters.SMTP2GO`, `Swoosh.Adapters.Sendgrid`, `Swoosh.Adapters.Sendinblue`, `Swoosh.Adapters.Sendmail`, `Swoosh.Adapters.SocketLabs`, `Swoosh.Adapters.SparkPost`, `FzHttpWeb.Mailer.NoopAdapter` | `FzHttpWeb.Mailer.NoopAdapter` | +| OUTBOUND_EMAIL_ADAPTER | Method to use for sending outbound email. | One of `Elixir.Swoosh.Adapters.AmazonSES`, `Elixir.Swoosh.Adapters.CustomerIO`, `Elixir.Swoosh.Adapters.Dyn`, `Elixir.Swoosh.Adapters.ExAwsAmazonSES`, `Elixir.Swoosh.Adapters.Gmail`, `Elixir.Swoosh.Adapters.MailPace`, `Elixir.Swoosh.Adapters.Mailgun`, `Elixir.Swoosh.Adapters.Mailjet`, `Elixir.Swoosh.Adapters.Mandrill`, `Elixir.Swoosh.Adapters.Postmark`, `Elixir.Swoosh.Adapters.ProtonBridge`, `Elixir.Swoosh.Adapters.SMTP`, `Elixir.Swoosh.Adapters.SMTP2GO`, `Elixir.Swoosh.Adapters.Sendgrid`, `Elixir.Swoosh.Adapters.Sendinblue`, `Elixir.Swoosh.Adapters.Sendmail`, `Elixir.Swoosh.Adapters.SocketLabs`, `Elixir.Swoosh.Adapters.SparkPost`, `Elixir.FzHttpWeb.Mailer.NoopAdapter` | `Elixir.FzHttpWeb.Mailer.NoopAdapter` | | OUTBOUND_EMAIL_ADAPTER_OPTS | Adapter configuration, for list of options see [Swoosh Adapters](https://github.com/swoosh/swoosh#adapters). | JSON-encoded map | `{}` | ### Connectivity Checks