Skip to content

Commit

Permalink
Browse everything s3 (#532)
Browse files Browse the repository at this point in the history
* config for be-s3

* set bucket name and region direct in deploy yaml

* use existing iam user so no need for these here

* use existing defaults for s3 access

* 🐛 Override BrowseEverything for S3 file size

This commit will bring in an override for the BrowseEverything gem to
retrieve the file size from an S3 object and pass it into the params so
that the Bulkrax importer can use it.

* remove file-system option from BE providers

---------

Co-authored-by: Kirk Wang <[email protected]>
  • Loading branch information
cziaarm and kirkkwang authored Apr 17, 2024
1 parent 4d310a3 commit edfb209
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
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)

0 comments on commit edfb209

Please sign in to comment.