class Dpl::Providers::S3
Constants
- DEFAULT_CONTENT_TYPE
Public Instance Methods
Source
# File lib/dpl/providers/s3.rb, line 73 def deploy upload index_document_suffix if index_document_suffix? rescue Aws::S3::Errors::ServiceError => e handle_error(e) end
Source
# File lib/dpl/providers/s3.rb, line 63 def setup @cwd = Dir.pwd Dir.chdir(local_dir) # Aws.eager_autoload!(services: ['S3']) end
Private Instance Methods
Source
# File lib/dpl/providers/s3.rb, line 147 def acl super.gsub(/_/, '-') if acl? end
Calls superclass method
Source
# File lib/dpl/providers/s3.rb, line 191 def bucket @bucket ||= Aws::S3::Resource.new(client:).bucket(super) end
Calls superclass method
Source
# File lib/dpl/providers/s3.rb, line 195 def client Aws::S3::Client.new(s3_opts) end
Source
# File lib/dpl/providers/s3.rb, line 162 def compact(hash) hash.reject { |_, value| value.nil? }.to_h end
Source
# File lib/dpl/providers/s3.rb, line 155 def content_type(file) return DEFAULT_CONTENT_TYPE unless type = MIME::Types.type_for(file).first type = "#{type}; charset=#{default_text_charset}" if encoding(file) == 'text' && default_text_charset? type.to_s end
Source
# File lib/dpl/providers/s3.rb, line 208 def credentials Aws::Credentials.new(access_key_id, secret_access_key) end
Source
# File lib/dpl/providers/s3.rb, line 166 def endpoint @endpoint ||= normalize_endpoint(super) if endpoint? end
Calls superclass method
Source
# File lib/dpl/providers/s3.rb, line 139 def files @files ||= Dir.glob(*glob).reject { |path| File.directory?(path) } end
Source
# File lib/dpl/providers/s3.rb, line 143 def glob [super, dot_match? ? File::FNM_DOTMATCH : nil].compact end
Calls superclass method
Source
# File lib/dpl/providers/s3.rb, line 178 def handle_error(err) case err when Aws::S3::Errors::InvalidAccessKeyId error :invalid_access_key_id when Aws::S3::Errors::ChecksumError error :checksum_error when Aws::S3::Errors::AccessDenied error :access_denied else error err.message end end
Source
# File lib/dpl/providers/s3.rb, line 117 def index_document_suffix info :index_document_suffix, super body = { website_configuration: { index_document: { suffix: super } } } bucket.website.put(body) end
Calls superclass method
Source
# File lib/dpl/providers/s3.rb, line 216 def match_opt(strs, file) maps = Array(strs).map { |str| Mapping.new(str, file) } maps.map(&:value).compact.first end
Source
# File lib/dpl/providers/s3.rb, line 170 def normalize_endpoint(url) uri = URI.parse(url) return uri if uri.scheme info :default_uri_scheme URI.parse("https://#{url}") end
Source
# File lib/dpl/providers/s3.rb, line 101 def progress(file, data) if verbose? info :upload_file, file, upload_dir || '/', to_pairs(data) else print '.' end end
Source
# File lib/dpl/providers/s3.rb, line 199 def s3_opts compact( region:, credentials:, endpoint:, force_path_style: force_path_style? ) end
Source
# File lib/dpl/providers/s3.rb, line 151 def server_side_encryption 'AES256' if server_side_encryption? end
Source
# File lib/dpl/providers/s3.rb, line 212 def to_pairs(hash) hash.map { |pair| pair.join('=') }.join(' ') end
Source
# File lib/dpl/providers/s3.rb, line 86 def upload info :upload, files.length, max_threads threads = max_threads.times.map { |_i| Thread.new(&method(:upload_files)) } threads.each(&:join) info "\n" unless verbose? end
Source
# File lib/dpl/providers/s3.rb, line 109 def upload_file(file, opts) object = bucket.object(upload_path(file)) return warn :upload_skipped, file: file if !overwrite && object.exists? info :upload_file, file, upload_dir || '/', to_pairs(opts) object.upload_file(file, opts) || warn(:upload_failed, file) end
Source
# File lib/dpl/providers/s3.rb, line 93 def upload_files while file = files.pop opts = upload_opts(file) progress(file, opts) upload_file(file, opts) end end
Source
# File lib/dpl/providers/s3.rb, line 127 def upload_opts(file) compact( acl:, content_type: content_type(file), content_encoding: detect_encoding? ? encoding(file) : nil, cache_control: match_opt(cache_control, file), expires: match_opt(expires, file), storage_class:, server_side_encryption: ) end
Source
# File lib/dpl/providers/s3.rb, line 123 def upload_path(file) [upload_dir, file].compact.join('/') end