Skip to content

Commit

Permalink
Merge pull request #1101 from graysonchen/feature/support_custom_aws_…
Browse files Browse the repository at this point in the history
…endpoint

Feature/support custom aws endpoint
  • Loading branch information
texpert authored Oct 26, 2024
2 parents 340319a + cfc87c3 commit 4772316
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/camaleon_cms/admin/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
9 changes: 8 additions & 1 deletion app/uploaders/camaleon_cms_aws_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -140,8 +141,14 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<%= label_tag t('camaleon_cms.admin.settings.filesystem_region', default: 'filesystem_region') %> <small>(*)</small><br>
<%= text_field :options, :filesystem_region, :class => "form-control required", value: @site.get_option("filesystem_region"), placeholder: 'us-west-2' %>
</div>
<!--<div class="form-group">
<%#= label_tag t('camaleon_cms.admin.settings.filesystem_s3_endpoint', default: 'filesystem_s3_endpoint') %> <small>(*)</small><br>
<%#= text_field :options, :filesystem_s3_endpoint, :class => "form-control required", value: @site.get_option("filesystem_s3_endpoint"), placeholder: 's3-us-west-2.amazonaws.com' %>
</div>-->
<div class="form-group">
<%= label_tag t('camaleon_cms.admin.settings.filesystem_s3_endpoint', default: 'filesystem_s3_endpoint') %><br>
<%= text_field :options, :filesystem_s3_endpoint, :class => "form-control required", value: @site.get_option("filesystem_s3_endpoint"), placeholder: 's3-us-west-2.amazonaws.com' %>
</div>
<div class="form-group">
<%= label_tag t('camaleon_cms.admin.settings.filesystem_s3_cloudfront', default: 'Cloudfront URL') %><br>
<%= text_field :options, :filesystem_s3_cloudfront, :class => "form-control", value: @site.get_option("filesystem_s3_cloudfront"), placeholder: 'https://cloudfront_id.cloudfront.net' %>
</div>
</div>
</div>
</div>

0 comments on commit 4772316

Please sign in to comment.