Skip to content

Commit ef18861

Browse files
authored
Feature: Migrate to New CDN (#79)
* force virtual_host true in ActiveStorage redirects * Update blob and representation redirect controllers to use S3 vhosts * Update bucket name
1 parent ad21f31 commit ef18861

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
# Take a signed permanent reference for a blob and turn it into an expiring service URL for download.
4+
#
5+
# WARNING: All Active Storage controllers are publicly accessible by default. The
6+
# generated URLs are hard to guess, but permanent by design. If your files
7+
# require a higher level of protection consider implementing
8+
# {Authenticated Controllers}[https://guides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
9+
class ActiveStorage::Blobs::RedirectController < ActiveStorage::BaseController
10+
include ActiveStorage::SetBlob
11+
12+
def show
13+
expires_in ActiveStorage.service_urls_expire_in
14+
redirect_to @blob.url(disposition: params[:disposition], virtual_host: true), allow_other_host: true
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# Take a signed permanent reference for a blob and turn it into an expiring service URL for download.
4+
# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the
5+
# security-through-obscurity factor of the signed blob references, you'll need to implement your own
6+
# authenticated redirection controller.
7+
class ActiveStorage::BlobsController < ActiveStorage::BaseController
8+
include ActiveStorage::SetBlob
9+
10+
def show
11+
expires_in ActiveStorage::Blob.service.url_expires_in
12+
redirect_to @blob.service_url(disposition: params[:disposition], virtual_host: true)
13+
end
14+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# Take a signed permanent reference for a blob representation and turn it into an expiring service URL for download.
4+
#
5+
# WARNING: All Active Storage controllers are publicly accessible by default. The
6+
# generated URLs are hard to guess, but permanent by design. If your files
7+
# require a higher level of protection consider implementing
8+
# {Authenticated Controllers}[https://guides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
9+
class ActiveStorage::Representations::RedirectController < ActiveStorage::Representations::BaseController
10+
def show
11+
expires_in ActiveStorage.service_urls_expire_in
12+
redirect_to @representation.url(disposition: params[:disposition], virtual_host: true), allow_other_host: true
13+
end
14+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# Take a signed permanent reference for a blob representation and turn it into an expiring service URL for download.
4+
# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the
5+
# security-through-obscurity factor of the signed blob and variation reference, you'll need to implement your own
6+
# authenticated redirection controller.
7+
class ActiveStorage::RepresentationsController < ActiveStorage::BaseController
8+
include ActiveStorage::SetBlob
9+
10+
def show
11+
expires_in ActiveStorage::Blob.service.url_expires_in
12+
redirect_to @blob.representation(params[:variation_key]).processed.service_url(disposition: params[:disposition], virtual_host: true)
13+
end
14+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module ActiveStorage::SetBlob # :nodoc:
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
before_action :set_blob
8+
end
9+
10+
private
11+
12+
def set_blob
13+
@blob = ActiveStorage::Blob.find_signed(params[:signed_blob_id] || params[:signed_id])
14+
rescue ActiveSupport::MessageVerifier::InvalidSignature
15+
head :not_found
16+
end
17+
end

config/credentials.yml.enc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9N+Y5OCkoacvxgKG3Mt2W9aHW8dNhVQ4uek0tyDDaj9p0gkBuCBqjq9XFMBl4LMwPS6E7/naUjTwKIOYKhOiCcdjV2RqWiYB1ubkAhs4y0naScGf879XSX1kl2j0rTCmdkJujKNYjrYS0COSSHmut5XuLYnRpQAGb0bjIGyXVC4dt+wrhVGKPn9fGluIC0UbZz2vdyCr8CE2/5+bW1/b2AktfDaxdSjLlYslZMMW3I2W0iv/QK0HHDv+YZVlQNeZWPX0rp/e09BlGsw8ygXS1GYhutKByQhA3Shmpfv9Q76FjisS9eyrN1VhJn56T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