Class: Fastlane::Actions::S3DownloadAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/s3_actions/actions/s3_download_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



40
41
42
# File 'lib/fastlane/plugin/s3_actions/actions/s3_download_action.rb', line 40

def self.authors
  ["Fernando Saragoca"]
end

.available_optionsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fastlane/plugin/s3_actions/actions/s3_download_action.rb', line 44

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :access_key_id,
                            env_name: "S3_ACTIONS_ACCESS_KEY_ID",
                         description: "AWS Access Key",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :secret_access_key,
                            env_name: "S3_ACTIONS_SECRET_ACCESS_KEY",
                         description: "AWS Secret Access Key",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :bucket,
                            env_name: "S3_ACTIONS_BUCKET",
                         description: "S3 Bucket",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :output_path,
                            env_name: "S3_ACTIONS_OUTPUT_PATH",
                         description: "Path to save downloaded file",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :file_name,
                            env_name: "S3_ACTIONS_DOWNLOAD_FILE_NAME",
                         description: "File name",
                            optional: true,
                                type: String)
  ]
end

.descriptionObject



36
37
38
# File 'lib/fastlane/plugin/s3_actions/actions/s3_download_action.rb', line 36

def self.description
  "Download a file from AWS S3"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/fastlane/plugin/s3_actions/actions/s3_download_action.rb', line 74

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fastlane/plugin/s3_actions/actions/s3_download_action.rb', line 6

def self.run(params)
  Actions.verify_gem!('s3')

  service = S3::Service.new(access_key_id: params[:access_key_id],
                        secret_access_key: params[:secret_access_key])

  bucket_name = params[:bucket]
  file_name = params[:file_name]
  output_path = params[:output_path]

  output_directory = File.dirname(output_path)
  unless File.exist?(output_directory)
    Actions.sh("mkdir #{output_directory}", log: $verbose)
  end

  bucket = service.buckets.find(bucket_name)
  if bucket.nil?
    UI.user_error! "Bucket '#{bucket_name}' not found, please verify bucket and credentials 🚫"
  end

  begin
    object = bucket.objects.find(file_name)
  rescue
    UI.user_error! "Object '#{file_name}' not found, please verify file and bucket 🚫"
  end

  UI.important("Downloading file '#{bucket_name}/#{file_name}' 📥")
  File.write(output_path, object.content)
end