From 2495737b5640be03a966a3b42fcc4842420900d7 Mon Sep 17 00:00:00 2001 From: Grayson Chen Date: Mon, 21 Oct 2024 13:09:30 +0800 Subject: [PATCH 1/5] custom aws endpoint --- app/uploaders/camaleon_cms_aws_uploader.rb | 8 +++++++- .../admin/settings/_file_system_settings.html.erb | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/uploaders/camaleon_cms_aws_uploader.rb b/app/uploaders/camaleon_cms_aws_uploader.rb index fa3d397ab..c1cd71b09 100644 --- a/app/uploaders/camaleon_cms_aws_uploader.rb +++ b/app/uploaders/camaleon_cms_aws_uploader.rb @@ -5,6 +5,7 @@ def after_initialize @aws_akey = @aws_settings[:access_key] || @current_site.get_option('filesystem_s3_access_key') @aws_asecret = @aws_settings[:secret_key] || @current_site.get_option('filesystem_s3_secret_key') @aws_bucket = @aws_settings[:bucket] || @current_site.get_option('filesystem_s3_bucket_name') + @aws_endpoint = @aws_settings[:endpoint] || @current_site.get_option('filesystem_s3_endpoint') @aws_settings[:aws_file_upload_settings] ||= ->(settings) { settings } @aws_settings[:aws_file_read_settings] ||= ->(data, _s3_file) { data } end @@ -140,8 +141,13 @@ def delete_file(key) def bucket @bucket ||= lambda { Aws.config.update({ region: @aws_region, credentials: Aws::Credentials.new(@aws_akey, @aws_asecret) }) - s3 = Aws::S3::Resource.new + s3 = Aws::S3::Resource.new(resource_parameters) s3.bucket(@aws_bucket) }.call end + + def resource_parameters + return {} if @aws_endpoint.blank? + { endpoint: @aws_endpoint } + end end diff --git a/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb b/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb index 50fbf2f82..2c66d3acc 100644 --- a/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb +++ b/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb @@ -20,13 +20,13 @@ <%= label_tag t('camaleon_cms.admin.settings.filesystem_region', default: 'filesystem_region') %> (*)
<%= text_field :options, :filesystem_region, :class => "form-control required", value: @site.get_option("filesystem_region"), placeholder: 'us-west-2' %> - +
+ <%= label_tag t('camaleon_cms.admin.settings.filesystem_s3_endpoint', default: 'filesystem_s3_endpoint') %> (*)
+ <%= text_field :options, :filesystem_s3_endpoint, :class => "form-control required", value: @site.get_option("filesystem_s3_endpoint"), placeholder: 's3-us-west-2.amazonaws.com' %> +
<%= label_tag t('camaleon_cms.admin.settings.filesystem_s3_cloudfront', default: 'Cloudfront URL') %>
<%= text_field :options, :filesystem_s3_cloudfront, :class => "form-control", value: @site.get_option("filesystem_s3_cloudfront"), placeholder: 'https://cloudfront_id.cloudfront.net' %>
- \ No newline at end of file + From 2e7a645c58d754661a9e7c4d0bfccbdeef8caba9 Mon Sep 17 00:00:00 2001 From: Grayson Chen Date: Mon, 21 Oct 2024 13:14:34 +0800 Subject: [PATCH 2/5] s3 endpoint option. --- .../camaleon_cms/admin/settings/_file_system_settings.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb b/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb index 2c66d3acc..fb8f0d3b0 100644 --- a/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb +++ b/app/views/camaleon_cms/admin/settings/_file_system_settings.html.erb @@ -21,7 +21,7 @@ <%= text_field :options, :filesystem_region, :class => "form-control required", value: @site.get_option("filesystem_region"), placeholder: 'us-west-2' %>
- <%= label_tag t('camaleon_cms.admin.settings.filesystem_s3_endpoint', default: 'filesystem_s3_endpoint') %> (*)
+ <%= label_tag t('camaleon_cms.admin.settings.filesystem_s3_endpoint', default: 'filesystem_s3_endpoint') %>
<%= text_field :options, :filesystem_s3_endpoint, :class => "form-control required", value: @site.get_option("filesystem_s3_endpoint"), placeholder: 's3-us-west-2.amazonaws.com' %>
From 14c37b2c2c7e6adfa8e1df4292bfd31ff75724fc Mon Sep 17 00:00:00 2001 From: Grayson Chen Date: Tue, 22 Oct 2024 22:40:28 +0800 Subject: [PATCH 3/5] Update app/uploaders/camaleon_cms_aws_uploader.rb --- app/uploaders/camaleon_cms_aws_uploader.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/uploaders/camaleon_cms_aws_uploader.rb b/app/uploaders/camaleon_cms_aws_uploader.rb index c1cd71b09..5bf9191e4 100644 --- a/app/uploaders/camaleon_cms_aws_uploader.rb +++ b/app/uploaders/camaleon_cms_aws_uploader.rb @@ -148,6 +148,7 @@ def bucket def resource_parameters return {} if @aws_endpoint.blank? + { endpoint: @aws_endpoint } end end From d9dde8066cc367de0c4256f1c836a5cc62d9fe9f Mon Sep 17 00:00:00 2001 From: texpert Date: Sat, 26 Oct 2024 10:23:44 +0300 Subject: [PATCH 4/5] Fix Style/SafeNavigation in sessions_controller.rb --- app/controllers/camaleon_cms/admin/sessions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/camaleon_cms/admin/sessions_controller.rb b/app/controllers/camaleon_cms/admin/sessions_controller.rb index 022aafc6f..fcf2dfba7 100644 --- a/app/controllers/camaleon_cms/admin/sessions_controller.rb +++ b/app/controllers/camaleon_cms/admin/sessions_controller.rb @@ -26,7 +26,7 @@ def login_post hooks_run('user_before_login', r) return if r[:stop_process] # permit to redirect for data completion - if captcha_validate && @user && @user.authenticate(data_user[:password]) + if captcha_validate && @user&.authenticate(data_user[:password]) # Email validation if is necessary if @user.is_valid_email? || !current_site.need_validate_email? cama_captcha_reset_attack('login') From cfc87c34235a9c94739741a0a79d4547d61dd688 Mon Sep 17 00:00:00 2001 From: texpert Date: Sat, 26 Oct 2024 13:10:25 +0300 Subject: [PATCH 5/5] Add changelog entry [skip ci] --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d973545ec..225aad7cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- **Feature:** Support custom aws endpoint + - Thanks [Grayson Chen](https://github.com/graysonchen) for crafting a PR adding this feature + # [2.8.3](https://github.com/owen2345/camaleon-cms/tree/2.8.3) (2024-09-16) - Remove unused underscore.js