Class: Fastlane::Helper::S3ClientHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::S3ClientHelper
- Defined in:
- fastlane/lib/fastlane/helper/s3_client_helper.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
- #delete_file(bucket_name, file_name) ⇒ Object
- #download_file(bucket_name, key, destination_path) ⇒ Object
- #find_bucket!(bucket_name) ⇒ Object
-
#initialize(access_key: nil, secret_access_key: nil, session_token: nil, region: nil, s3_client: 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, session_token: nil, region: nil, s3_client: nil) ⇒ S3ClientHelper
Returns a new instance of S3ClientHelper.
9 10 11 12 13 14 15 16 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 9 def initialize(access_key: nil, secret_access_key: nil, session_token: nil, region: nil, s3_client: nil) @access_key = access_key @secret_access_key = secret_access_key @session_token = session_token @region = region @client = s3_client end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
6 7 8 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 6 def access_key @access_key end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
7 8 9 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 7 def region @region end |
Instance Method Details
#delete_file(bucket_name, file_name) ⇒ Object
47 48 49 50 51 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 47 def delete_file(bucket_name, file_name) bucket = find_bucket!(bucket_name) file = bucket.object(file_name) file.delete end |
#download_file(bucket_name, key, destination_path) ⇒ Object
43 44 45 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 43 def download_file(bucket_name, key, destination_path) Aws::S3::TransferManager.new(client: client).download_file(destination_path, bucket: bucket_name, key: key) end |
#find_bucket!(bucket_name) ⇒ Object
53 54 55 56 57 58 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 53 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
18 19 20 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 18 def list_buckets return client.list_buckets end |
#upload_file(bucket_name, file_name, file_data, acl) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 22 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 |