diff options
| author | Roman Chvanikov <chvanikoff@pm.me> | 2020-08-05 19:16:48 +0300 | 
|---|---|---|
| committer | Roman Chvanikov <chvanikoff@pm.me> | 2020-08-05 19:16:48 +0300 | 
| commit | 4672b61106044c3772f58b02d39531b015ad8cca (patch) | |
| tree | 0c0844bab5eae07265965b2b6dbd914afc55f9d6 /lib/mix | |
| parent | 3116a75e80144dff79232c8676bd28ed285a14d9 (diff) | |
| parent | 7755f49e281e4990db5317b33d6b8e0d12982e0c (diff) | |
| download | pleroma-4672b61106044c3772f58b02d39531b015ad8cca.tar.gz pleroma-4672b61106044c3772f58b02d39531b015ad8cca.zip | |
Merge branch 'develop' into command-available-check
Diffstat (limited to 'lib/mix')
| -rw-r--r-- | lib/mix/pleroma.ex | 24 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/config.ex | 8 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/notification_settings.ex | 18 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/release_env.ex | 76 | 
4 files changed, 109 insertions, 17 deletions
| diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 9f0bf6ecb..074492a46 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -24,8 +24,10 @@ defmodule Mix.Pleroma do        Application.put_env(:logger, :console, level: :debug)      end +    adapter = Application.get_env(:tesla, :adapter) +      apps = -      if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do +      if adapter == Tesla.Adapter.Gun do          [:gun | @apps]        else          [:hackney | @apps] @@ -33,11 +35,14 @@ defmodule Mix.Pleroma do      Enum.each(apps, &Application.ensure_all_started/1) -    children = [ -      Pleroma.Repo, -      {Pleroma.Config.TransferTask, false}, -      Pleroma.Web.Endpoint -    ] +    children = +      [ +        Pleroma.Repo, +        {Pleroma.Config.TransferTask, false}, +        Pleroma.Web.Endpoint, +        {Oban, Pleroma.Config.get(Oban)} +      ] ++ +        http_children(adapter)      cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, [])) @@ -115,4 +120,11 @@ defmodule Mix.Pleroma do    def escape_sh_path(path) do      ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')    end + +  defp http_children(Tesla.Adapter.Gun) do +    Pleroma.Gun.ConnectionPool.children() ++ +      [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}] +  end + +  defp http_children(_), do: []  end diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index d5129d410..904c5a74b 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -83,7 +83,7 @@ defmodule Mix.Tasks.Pleroma.Config do    defp migrate_from_db(opts) do      if Pleroma.Config.get([:configurable_from_database]) do -      env = opts[:env] || "prod" +      env = opts[:env] || Pleroma.Config.get(:env)        config_path =          if Pleroma.Config.get(:release) do @@ -105,6 +105,10 @@ defmodule Mix.Tasks.Pleroma.Config do        :ok = File.close(file)        System.cmd("mix", ["format", config_path]) + +      shell_info( +        "Database configuration settings have been exported to config/#{env}.exported_from_db.secret.exs" +      )      else        migration_error()      end @@ -112,7 +116,7 @@ defmodule Mix.Tasks.Pleroma.Config do    defp migration_error do      shell_error( -      "Migration is not allowed in config. You can change this behavior by setting `configurable_from_database` to true." +      "Migration is not allowed in config. You can change this behavior by setting `config :pleroma, configurable_from_database: true`"      )    end diff --git a/lib/mix/tasks/pleroma/notification_settings.ex b/lib/mix/tasks/pleroma/notification_settings.ex index 7d65f0587..00f5ba7bf 100644 --- a/lib/mix/tasks/pleroma/notification_settings.ex +++ b/lib/mix/tasks/pleroma/notification_settings.ex @@ -3,8 +3,8 @@ defmodule Mix.Tasks.Pleroma.NotificationSettings do    @moduledoc """    Example: -  > mix pleroma.notification_settings --privacy-option=false --nickname-users="parallel588"  # set false only for parallel588 user -  > mix pleroma.notification_settings --privacy-option=true # set true for all users +  > mix pleroma.notification_settings --hide-notification-contents=false --nickname-users="parallel588"  # set false only for parallel588 user +  > mix pleroma.notification_settings --hide-notification-contents=true # set true for all users    """ @@ -19,16 +19,16 @@ defmodule Mix.Tasks.Pleroma.NotificationSettings do        OptionParser.parse(          args,          strict: [ -          privacy_option: :boolean, +          hide_notification_contents: :boolean,            email_users: :string,            nickname_users: :string          ]        ) -    privacy_option = Keyword.get(options, :privacy_option) +    hide_notification_contents = Keyword.get(options, :hide_notification_contents) -    if not is_nil(privacy_option) do -      privacy_option +    if not is_nil(hide_notification_contents) do +      hide_notification_contents        |> build_query(options)        |> Pleroma.Repo.update_all([])      end @@ -36,15 +36,15 @@ defmodule Mix.Tasks.Pleroma.NotificationSettings do      shell_info("Done")    end -  defp build_query(privacy_option, options) do +  defp build_query(hide_notification_contents, options) do      query =        from(u in Pleroma.User,          update: [            set: [              notification_settings:                fragment( -                "jsonb_set(notification_settings, '{privacy_option}', ?)", -                ^privacy_option +                "jsonb_set(notification_settings, '{hide_notification_contents}', ?)", +                ^hide_notification_contents                )            ]          ] diff --git a/lib/mix/tasks/pleroma/release_env.ex b/lib/mix/tasks/pleroma/release_env.ex new file mode 100644 index 000000000..9da74ffcf --- /dev/null +++ b/lib/mix/tasks/pleroma/release_env.ex @@ -0,0 +1,76 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.ReleaseEnv do +  use Mix.Task +  import Mix.Pleroma + +  @shortdoc "Generate Pleroma environment file." +  @moduledoc File.read!("docs/administration/CLI_tasks/release_environments.md") + +  def run(["gen" | rest]) do +    {options, [], []} = +      OptionParser.parse( +        rest, +        strict: [ +          force: :boolean, +          path: :string +        ], +        aliases: [ +          p: :path, +          f: :force +        ] +      ) + +    file_path = +      get_option( +        options, +        :path, +        "Environment file path", +        "./config/pleroma.env" +      ) + +    env_path = Path.expand(file_path) + +    proceed? = +      if File.exists?(env_path) do +        get_option( +          options, +          :force, +          "Environment file already exists. Do you want to overwrite the #{env_path} file? (y/n)", +          "n" +        ) === "y" +      else +        true +      end + +    if proceed? do +      case do_generate(env_path) do +        {:error, reason} -> +          shell_error( +            File.Error.message(%{action: "write to file", reason: reason, path: env_path}) +          ) + +        _ -> +          shell_info("\nThe file generated: #{env_path}.\n") + +          shell_info(""" +          WARNING: before start pleroma app please make sure to make the file read-only and non-modifiable. +            Example: +              chmod 0444 #{file_path} +              chattr +i #{file_path} +          """) +      end +    else +      shell_info("\nThe file is exist. #{env_path}.\n") +    end +  end + +  def do_generate(path) do +    content = "RELEASE_COOKIE=#{Base.encode32(:crypto.strong_rand_bytes(32))}" + +    File.mkdir_p!(Path.dirname(path)) +    File.write(path, content) +  end +end | 
