Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browse everything s3 #532

Merged
merged 9 commits into from
Apr 17, 2024
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class Application < Rails::Application
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), "../lib/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

# resolve reloading issue in dev mode
Expand Down
20 changes: 10 additions & 10 deletions config/browse_everything_providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# To make browse-everything aware of a provider, uncomment the info for that provider and add your API key information.
# The file_system provider can be a path to any directory on the server where your application is running.
#
file_system:
home: /app/samvera/hyrax-webapp/data
#file_system:
# home: /app/samvera/hyrax-webapp/data
# dropbox:
# client_id: YOUR_DROPBOX_APP_KEY
# client_secret: YOUR_DROPBOX_APP_SECRET
Expand All @@ -14,11 +14,11 @@ file_system:
# google_drive:
# client_id: YOUR_GOOGLE_API_CLIENT_ID
# client_secret: YOUR_GOOGLE_API_CLIENT_SECRET
# s3:
# bucket: YOUR_AWS_S3_BUCKET
# response_type: signed_url # set to :public_url for public urls or :s3_uri for an s3://BUCKET/KEY uri
# expires_in: 14400 # for signed_url response_type, number of seconds url will be valid for.
# app_key: YOUR_AWS_S3_KEY # :app_key, :app_secret, and :region can be specified
# app_secret: YOUR_AWS_S3_SECRET # explicitly here, or left out to use system-configured
# region: YOUR_AWS_S3_REGION # defaults.
# See https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/
s3:
bucket: temp-bl-bucket-for-browse-everything # .s3.amazonaws.com #arn:aws:s3:::temp-bl-bucket-for-browse-everything
response_type: signed_url # set to :public_url for public urls or :s3_uri for an s3://BUCKET/KEY uri
expires_in: 14400 # for signed_url response_type, number of seconds url will be valid for.
app_key: <%= ENV['AWS_ACCESS_KEY_ID'] %> # :app_key, :app_secret, and :region can be specified
app_secret: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> # explicitly here, or left out to use system-configured
region: eu-west-1 # defaults.
# See https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/
31 changes: 31 additions & 0 deletions lib/browse_everything/driver/s3_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

# OVERRIDE BrowseEverything v1.1.2 to add file_size for S3 files

module BrowseEverything
module Driver
module S3Decorator
def link_for(path)
obj = bucket.object(full_path(path))
obj_head = obj.head
file_size = obj_head.content_length

extras = {
file_name: File.basename(path),
file_size: file_size,
expires: (config[:expires_in] if config[:response_type] == :signed_url)
}.compact

url = case config[:response_type].to_sym
when :signed_url then obj.presigned_url(:get, expires_in: config[:expires_in])
when :public_url then obj.public_url
when :s3_uri then "s3://#{obj.bucket_name}/#{obj.key}"
end

[url, extras]
end
end
end
end

BrowseEverything::Driver::S3.prepend(BrowseEverything::Driver::S3Decorator)
Loading