Class: Fastlane::Helper::S3ClientHelper

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/helper/s3_client_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key: nil, secret_access_key: nil, region: nil, s3_client: nil) ⇒ S3ClientHelper

Returns a new instance of S3ClientHelper.



9
10
11
12
13
14
15
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 9

def initialize(access_key: nil, secret_access_key: nil, region: nil, s3_client: nil)
  @access_key = access_key
  @secret_access_key = secret_access_key
  @region = region

  @client = s3_client
end

Instance Attribute Details

#access_keyObject (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

#regionObject (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



42
43
44
45
46
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 42

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



48
49
50
51
52
53
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 48

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_bucketsObject



17
18
19
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 17

def list_buckets
  return client.list_buckets
end

#upload_file(bucket_name, file_name, file_data, acl) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'fastlane/lib/fastlane/helper/s3_client_helper.rb', line 21

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