Class: SuperSettings::Storage::S3Storage::Configuration
- Inherits:
-
Object
- Object
- SuperSettings::Storage::S3Storage::Configuration
- Defined in:
- lib/super_settings/storage/s3_storage.rb
Overview
Configuration for the S3 storage backend.
-
access_key_id - The AWS access key ID. Defaults to the SUPER_SETTINGS_AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY_ID environment variable or whatever is set in the ‘Aws.config` object.
-
secret_access_key - The AWS secret access key. Defaults to the SUPER_SETTINGS_AWS_SECRET_ACCESS_KEY
or AWS_SECRET_ACCESS_KEY environment variable or whatever is set in the `Aws.config` object.
-
region - The AWS region. Defaults to the SUPER_SETTINGS_AWS_REGION or AWS_REGION environment variable. This is required for AWS S3 but may be optional for S3-compatible services.
-
endpoint - The S3 endpoint URL. This is optional and should only be used for S3-compatible services. Defaults to the SUPER_SETTINGS_AWS_ENDPOINT or AWS_ENDPOINT environment variable.
-
bucket - The S3 bucket name. Defaults to the SUPER_SETTINGS_S3_BUCKET or AWS_S3_BUCKET environment variable.
-
object - The S3 object key. Defaults to “super_settings.json.gz” or the value set in the SUPER_SETTINGS_S3_OBJECT environment variable.
You can also specify the configuration using a URL in the format using the SUPER_SETTINGS_S3_URL environment variable. The URL should be in the format:
“‘
s3://access_key_id:secret_access_key@region/bucket/object
“‘
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#path ⇒ Object
Returns the value of attribute path.
-
#region ⇒ Object
Returns the value of attribute region.
-
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #url=(url) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
39 40 41 42 43 44 45 46 47 |
# File 'lib/super_settings/storage/s3_storage.rb', line 39 def initialize @access_key_id ||= ENV.fetch("SUPER_SETTINGS_AWS_ACCESS_KEY_ID", ENV["AWS_ACCESS_KEY_ID"]) @secret_access_key ||= ENV.fetch("SUPER_SETTINGS_AWS_SECRET_ACCESS_KEY", ENV["AWS_SECRET_ACCESS_KEY"]) @region ||= ENV.fetch("SUPER_SETTINGS_AWS_REGION", ENV["AWS_REGION"]) @endpoint ||= ENV.fetch("SUPER_SETTINGS_AWS_ENDPOINT", ENV["AWS_ENDPOINT"]) @bucket ||= ENV.fetch("SUPER_SETTINGS_S3_BUCKET", ENV["AWS_S3_BUCKET"]) @path ||= ENV.fetch("SUPER_SETTINGS_S3_OBJECT", DEFAULT_PATH) self.url = ENV["SUPER_SETTINGS_S3_URL"] unless ENV["SUPER_SETTINGS_S3_URL"].to_s.empty? end |
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
36 37 38 |
# File 'lib/super_settings/storage/s3_storage.rb', line 36 def access_key_id @access_key_id end |
#bucket ⇒ Object
Returns the value of attribute bucket.
36 37 38 |
# File 'lib/super_settings/storage/s3_storage.rb', line 36 def bucket @bucket end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
36 37 38 |
# File 'lib/super_settings/storage/s3_storage.rb', line 36 def endpoint @endpoint end |
#path ⇒ Object
Returns the value of attribute path.
37 38 39 |
# File 'lib/super_settings/storage/s3_storage.rb', line 37 def path @path end |
#region ⇒ Object
Returns the value of attribute region.
36 37 38 |
# File 'lib/super_settings/storage/s3_storage.rb', line 36 def region @region end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
36 37 38 |
# File 'lib/super_settings/storage/s3_storage.rb', line 36 def secret_access_key @secret_access_key end |
Instance Method Details
#hash ⇒ Object
67 68 69 |
# File 'lib/super_settings/storage/s3_storage.rb', line 67 def hash [self.class, access_key_id, secret_access_key, region, endpoint, bucket, path].hash end |
#url=(url) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/super_settings/storage/s3_storage.rb', line 49 def url=(url) return if url.to_s.empty? uri = URI.parse(url) raise ArgumentError, "Invalid S3 URL" unless uri.scheme == "s3" self.access_key_id = uri.user if uri.user self.secret_access_key = uri.password if uri.password self.region = uri.host if uri.host _, bucket, path = uri.path.split("/", 3) if uri.path self.bucket = bucket if bucket self.path = path if path end |