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

Active Storage can be configured by STORAGE_URL #50477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zzak
Copy link
Member

@zzak zzak commented Dec 29, 2023

Fixes #50448

NOTE: This is a proof-of-concept, that I came up with based on my understanding of ActiveRecord::DatabaseConfigurations and try to find a tiny seam to add support for this feature. Open to feedback and suggestions, but wanted to take a stab at this while it was fresh in my head.

@@ -32,5 +32,16 @@ def resolve(class_name)
rescue LoadError
raise "Missing service adapter for #{class_name.inspect}"
end

def build_configurations(configurations)
if storage_url = ENV["STORAGE_URL"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be comparison or is it an assignment here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a conditional assignment, in order to give ENV["STORAGE_URL"] priority over the rest of the configuration.

Active Storage doesn't need to support multiple configurations if the URL is set, unlike AR where you can have 2 or 3-tierd configs, so this is a simpler approach.

attr_reader :uri

def build_url_hash
service = uri.scheme && uri.scheme.tr("-", "_")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be refactored:

uri.scheme&.tr("-", "_")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just code I copied from AR:

adapter = uri.scheme && @uri.scheme.tr("-", "_")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add STORAGE_URL to Active Storage
2 participants