Packages
drab
0.3.4
0.10.5
0.10.4
0.10.3
0.10.2
0.10.1
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.6.0-pre.1
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Remote controlled frontend framework for Phoenix.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/drab.gen.cipher.ex
# defmodule Mix.Tasks.Drab.Gen.Cipher do
# use Mix.Task
# @shortdoc "Generates a Cipher part of config"
# @moduledoc """
# Generates a Cipher keys and add the to the config.
# mix drab.gen.cipher
# This will generate a config for Cipher and show it on the screen (will not modify any file).
# mix drab.gen.cipher dev
# This will generate a config for Cipher and add it to the `config/dev.exs` file.
# mix drab.gen.cipher prod.secret
# Analogically, it will add Cipher part to the `config/prod.secret.exs` file.
# """
# def run([]) do
# Mix.shell.info """
# Add the following line to your config file (config/dev.exs, config/prod.secret.exs etc):
# #{generate_keys()}
# """
# end
# def run(args) do
# [config_file] = validate_args!(args)
# config_file_path = "config/#{config_file}.exs"
# keys = generate_keys()
# unless File.exists?(config_file_path), do: file_unwritable!(config_file_path, "file does not exist", keys)
# case File.open(config_file_path, [:append]) do
# {:ok, file} -> IO.write(file, keys)
# {:error, reason} -> file_unwritable!(config_file_path, reason, keys)
# end
# Mix.shell.info """
# The following lines were added to your `#{config_file_path}`:
# #{keys}
# """
# end
# defp file_unwritable!(config_file_path, reason, keys) do
# Mix.raise """
# Can't open the config file: #{config_file_path} (#{reason}).
# Please add the following:
# #{keys}
# manually to your real config file.
# """
# end
# defp generate_keys() do
# source_file_path = "drab.gen.cipher.exs"
# binding = [keyphrase: random_string(),
# ivphrase: random_string(),
# magic_token: random_string()]
# roots = Enum.map(paths(), &to_app_source(&1, "priv/templates/"))
# source =
# Enum.find_value(roots, fn root ->
# source = Path.join(root, source_file_path)
# if File.exists?(source), do: source
# end)
# EEx.eval_file(source, binding)
# end
# defp validate_args!(args) do
# unless length(args) == 1 do
# Mix.raise """
# mix drab.gen.cipher expects config file name:
# mix drab.gen.cipher dev
# """
# end
# args
# end
# defp random_string() do
# :crypto.strong_rand_bytes(64) |> Base.encode64 |> binary_part(0, 64)
# end
# defp paths do
# [".", :drab]
# end
# defp to_app_source(path, source_dir) when is_binary(path),
# do: Path.join(path, source_dir)
# defp to_app_source(app, source_dir) when is_atom(app),
# do: Application.app_dir(app, source_dir)
# end