logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 8b28dce82ac244c6c5e67d8379e68e5742bfe875
parent 5453038ce92597fe2d26cb843d48e9aa660d1ee9
Author: Mark Felder <feld@feld.me>
Date:   Tue, 12 Jan 2021 16:31:35 -0600

Deprecate Pleroma.Uploaders.S3, :public_endpoint

Diffstat:

Mconfig/config.exs15++++++++++++---
Mconfig/description.exs8+-------
Mconfig/test.exs3+--
Mdocs/configuration/cheatsheet.md5+----
Mlib/pleroma/config/deprecation_warnings.ex24+++++++++++++++++++++++-
Mpriv/templates/sample_config.eex10++++++++--
Mtest/pleroma/config/deprecation_warnings_test.exs9+++++++++
7 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/config/config.exs b/config/config.exs @@ -64,14 +64,23 @@ config :pleroma, Pleroma.Upload, link_name: false, proxy_remote: false, filename_display_max_length: 30, - default_description: nil + default_description: nil, + base_url: nil config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads" config :pleroma, Pleroma.Uploaders.S3, bucket: nil, - streaming_enabled: true, - public_endpoint: "https://s3.amazonaws.com" + bucket_namespace: nil, + truncated_namespace: false, + streaming_enabled: true + +config :ex_aws, :s3, + # host: "s3.wasabisys.com", # required if not Amazon AWS + access_key_id: nil, + secret_access_key: nil, + # region: nil, # example: "us-east-1" + scheme: "https://" config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"], diff --git a/config/description.exs b/config/description.exs @@ -150,17 +150,11 @@ config :pleroma, :config_description, [ suggestions: ["pleroma"] }, %{ - key: :public_endpoint, - type: :string, - description: "S3 endpoint", - suggestions: ["https://s3.amazonaws.com"] - }, - %{ key: :truncated_namespace, type: :string, description: "If you use S3 compatible service such as Digital Ocean Spaces or CDN, set folder name or \"\" etc." <> - " For example, when using CDN to S3 virtual host format, set \"\". At this time, write CNAME to CDN in public_endpoint." + " For example, when using CDN to S3 virtual host format, set \"\". At this time, write CNAME to CDN in Upload base_url." }, %{ key: :streaming_enabled, diff --git a/config/test.exs b/config/test.exs @@ -117,8 +117,7 @@ config :pleroma, Pleroma.Web.ApiSpec.CastAndValidate, strict: true config :pleroma, Pleroma.Uploaders.S3, bucket: nil, - streaming_enabled: true, - public_endpoint: nil + streaming_enabled: true config :tzdata, :autoupdate, :disabled diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md @@ -549,7 +549,7 @@ the source code is here: [kocaptcha](https://github.com/koto-bank/kocaptcha). Th * `uploader`: Which one of the [uploaders](#uploaders) to use. * `filters`: List of [upload filters](#upload-filters) to use. * `link_name`: When enabled Pleroma will add a `name` parameter to the url of the upload, for example `https://instance.tld/media/corndog.png?name=corndog.png`. This is needed to provide the correct filename in Content-Disposition headers when using filters like `Pleroma.Upload.Filter.Dedupe` -* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host. +* `base_url`: The base URL to access a user-uploaded file. Useful when you want to host the media files via another domain or are using a 3rd party S3 provider. * `proxy_remote`: If you're using a remote uploader, Pleroma will proxy media requests instead of redirecting to it. * `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation. * `filename_display_max_length`: Set max length of a filename to display. 0 = no limit. Default: 30. @@ -570,10 +570,7 @@ Don't forget to configure [Ex AWS S3](#ex-aws-s3-settings) * `bucket`: S3 bucket name. * `bucket_namespace`: S3 bucket namespace. -* `public_endpoint`: S3 endpoint that the user finally accesses(ex. "https://s3.dualstack.ap-northeast-1.amazonaws.com") * `truncated_namespace`: If you use S3 compatible service such as Digital Ocean Spaces or CDN, set folder name or "" etc. -For example, when using CDN to S3 virtual host format, set "". -At this time, write CNAME to CDN in public_endpoint. * `streaming_enabled`: Enable streaming uploads, when enabled the file will be sent to the server in chunks as it's being read. This may be unsupported by some providers, try disabling this if you have upload problems. #### Ex AWS S3 settings diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex @@ -40,7 +40,8 @@ defmodule Pleroma.Config.DeprecationWarnings do :ok <- check_welcome_message_config(), :ok <- check_gun_pool_options(), :ok <- check_activity_expiration_config(), - :ok <- check_remote_ip_plug_name() do + :ok <- check_remote_ip_plug_name(), + :ok <- check_uploders_s3_public_endpoint() do :ok else _ -> @@ -193,4 +194,25 @@ defmodule Pleroma.Config.DeprecationWarnings do warning_preface ) end + + @spec check_uploders_s3_public_endpoint() :: :ok | nil + def check_uploders_s3_public_endpoint do + s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3]) + + use_old_config = Keyword.has_key?(s3_config, :public_endpoint) + + if use_old_config do + Logger.error(""" + !!!DEPRECATION WARNING!!! + Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n + Please make the following change at your earliest convenience.\n + \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to: + \n* `config :pleroma, Pleroma.Upload, base_url` + """) + + :error + else + :ok + end + end end diff --git a/priv/templates/sample_config.eex b/priv/templates/sample_config.eex @@ -49,12 +49,18 @@ config :pleroma, Pleroma.Uploaders.Local, uploads: "<%= uploads_dir %>" # sts: true # Configure S3 support if desired. -# The public S3 endpoint is different depending on region and provider, +# The public S3 endpoint (base_url) is different depending on region and provider, # consult your S3 provider's documentation for details on what to use. # +# config :pleroma, Pleroma.Upload, +# uploader: Pleroma.Uploaders.S3, +# base_url: "https://s3.amazonaws.com" +# # config :pleroma, Pleroma.Uploaders.S3, # bucket: "some-bucket", -# public_endpoint: "https://s3.amazonaws.com" +# bucket_namespace: "my-namespace", +# truncated_namespace: false, +# streaming_enabled: true # # Configure S3 credentials: # config :ex_aws, :s3, diff --git a/test/pleroma/config/deprecation_warnings_test.exs b/test/pleroma/config/deprecation_warnings_test.exs @@ -94,6 +94,15 @@ defmodule Pleroma.Config.DeprecationWarningsTest do end) =~ "Your config is using old namespace for activity expiration configuration." end + test "check_uploders_s3_public_endpoint/0" do + clear_config(Pleroma.Uploaders.S3, public_endpoint: "https://fake.amazonaws.com/bucket/") + + assert capture_log(fn -> + DeprecationWarnings.check_uploders_s3_public_endpoint() + end) =~ + "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket." + end + describe "check_gun_pool_options/0" do test "await_up_timeout" do config = Config.get(:connections_pool)