lib/omnibus/s3_helpers.rb in omnibus-5.4.0 vs lib/omnibus/s3_helpers.rb in omnibus-5.5.0
- old
+ new
@@ -12,24 +12,25 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'aws-sdk'
-require 'base64'
+require "aws-sdk"
+require "base64"
module Omnibus
module S3Helpers
def self.included(base)
base.send(:include, InstanceMethods)
end
module InstanceMethods
private
+
#
# Returns the configuration for S3. You must provide keys
- # :region,
+ # :region,
#
# @example
# {
# region: 'us-east-1',
# access_key_id: Config.s3_access_key,
@@ -63,15 +64,15 @@
#
def bucket
@s3_bucket ||= begin
bucket = client.bucket(s3_configuration[:bucket_name])
unless bucket.exists?
- bucket_config = if s3_configuration[:region] == 'us-east-1'
+ bucket_config = if s3_configuration[:region] == "us-east-1"
nil
else
{
- location_constraint: s3_configuration[:region]
+ location_constraint: s3_configuration[:region],
}
end
bucket.create(create_bucket_configuration: bucket_config)
end
bucket
@@ -91,11 +92,11 @@
def store_object(key, content, content_md5, acl)
bucket.put_object({
key: key,
body: content,
content_md5: to_base64_digest(content_md5),
- acl: acl
+ acl: acl,
})
true
end
#
@@ -108,10 +109,10 @@
#
# @return [String]
#
def to_base64_digest(content_md5)
if content_md5
- md5_digest = content_md5.unpack('a2'*16).collect {|i| i.hex.chr }.join
+ md5_digest = content_md5.unpack("a2" * 16).collect { |i| i.hex.chr }.join
Base64.encode64(md5_digest).strip
end
end
end
end