refactor(docker): allow webPush configuration to be configured using env variables in Docker
Closes #1383 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -5,7 +5,6 @@ defmodule Mix.Tasks.Mobilizon.WebPush.Gen.Keypair do
|
||||
Taken from https://github.com/danhper/elixir-web-push-encryption/blob/8fd0f71f3222b466d389f559be9800c49f9bb641/lib/mix/tasks/web_push_gen_keypair.ex
|
||||
"""
|
||||
use Mix.Task
|
||||
import Mix.Tasks.Mobilizon.Common, only: [mix_shell?: 0]
|
||||
|
||||
@shortdoc "Manages Mobilizon users"
|
||||
|
||||
@@ -13,20 +12,28 @@ defmodule Mix.Tasks.Mobilizon.WebPush.Gen.Keypair do
|
||||
def run(_) do
|
||||
{public, private} = :crypto.generate_key(:ecdh, :prime256v1)
|
||||
|
||||
IO.puts("# Put the following in your #{file_name()} config file:")
|
||||
IO.puts("")
|
||||
IO.puts("config :web_push_encryption, :vapid_details,")
|
||||
IO.puts(" subject: \"mailto:administrator@example.com\",")
|
||||
IO.puts(" public_key: \"#{ub64(public)}\",")
|
||||
IO.puts(" private_key: \"#{ub64(private)}\"")
|
||||
IO.puts("Public and private VAPID keys have been generated.")
|
||||
IO.puts("")
|
||||
|
||||
if is_nil(System.get_env("MOBILIZON_DOCKER")) do
|
||||
IO.puts("# Put the following in your runtime.exs config file:")
|
||||
IO.puts("")
|
||||
IO.puts("config :web_push_encryption, :vapid_details,")
|
||||
IO.puts(" subject: \"mailto:administrator@example.com\",")
|
||||
IO.puts(" public_key: \"#{ub64(public)}\",")
|
||||
IO.puts(" private_key: \"#{ub64(private)}\"")
|
||||
IO.puts("")
|
||||
else
|
||||
IO.puts("# Set the following environment variables in your .env file:")
|
||||
IO.puts("")
|
||||
IO.puts("MOBILIZON_WEB_PUSH_ENCRYPTION_SUBJECT=\"mailto:administrator@example.com\"")
|
||||
IO.puts("MOBILIZON_WEB_PUSH_ENCRYPTION_PUBLIC_KEY=\"#{ub64(public)}\"")
|
||||
IO.puts("MOBILIZON_WEB_PUSH_ENCRYPTION_PRIVATE_KEY=\"#{ub64(private)}\"")
|
||||
IO.puts("")
|
||||
end
|
||||
end
|
||||
|
||||
defp ub64(value) do
|
||||
Base.url_encode64(value, padding: false)
|
||||
end
|
||||
|
||||
defp file_name do
|
||||
if mix_shell?(), do: "runtime.exs", else: "config.exs"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user