Class: Fastlane::Helper::S3ClientHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::S3ClientHelper
- Defined in:
- fastlane/lib/fastlane/helper/s3_client_helper.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #delete_file(bucket_name, file_name) ⇒ Object
- #find_bucket!(bucket_name) ⇒ Object
-
#initialize(access_key: nil, secret_access_key: nil, region: nil) ⇒ S3ClientHelper
constructor
A new instance of S3ClientHelper.
- #list_buckets ⇒ Object
- #upload_file(bucket_name, file_name, file_data, acl) ⇒ Object
Constructor Details
#initialize(access_key: nil, secret_access_key: nil, region: nil) ⇒ S3ClientHelper
Returns a new instance of S3ClientHelper.
8 9 10 11 12 13 14 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 8 def initialize(access_key: nil, secret_access_key: nil, region: nil) creds = Aws::Credentials.new(access_key, secret_access_key) Aws.config.update( region: region, credentials: creds ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 6 def client @client end |
Instance Method Details
#delete_file(bucket_name, file_name) ⇒ Object
41 42 43 44 45 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 41 def delete_file(bucket_name, file_name) bucket = find_bucket!(bucket_name) file = bucket.object(file_name) file.delete end |
#find_bucket!(bucket_name) ⇒ Object
47 48 49 50 51 52 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 47 def find_bucket!(bucket_name) bucket = Aws::S3::Bucket.new(bucket_name, client: client) raise "Bucket '#{bucket_name}' not found" unless bucket.exists? return bucket end |
#list_buckets ⇒ Object
16 17 18 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 16 def list_buckets return client.list_buckets end |
#upload_file(bucket_name, file_name, file_data, acl) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 20 def upload_file(bucket_name, file_name, file_data, acl) bucket = find_bucket!(bucket_name) details = { acl: acl, key: file_name, body: file_data } obj = bucket.put_object(details) # When you enable versioning on a S3 bucket, # writing to an object will create an object version # instead of replacing the existing object. # http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/ObjectVersion.html if obj.kind_of?(Aws::S3::ObjectVersion) obj = obj.object end # Return public url obj.public_url.to_s end |