class Akabei::Omakase::S3
Constants
- GZIP_MIME_TYPE
- SIG_MIME_TYPE
- XZ_MIME_TYPE
Public Class Methods
new(aws_config, shell)
click to toggle source
# File lib/akabei/omakase/s3.rb, line 4 def initialize(aws_config, shell) if aws_config require 'aws-sdk-core' @s3 = Aws::S3::Client.new( access_key_id: aws_config['access_key_id'], secret_access_key: aws_config['secret_access_key'], region: aws_config['region'], ) @bucket_name = aws_config['bucket'] @write_options = aws_config['write_options'] @shell = shell end end
Public Instance Methods
after!(config, arch, packages)
click to toggle source
# File lib/akabei/omakase/s3.rb, line 22 def after!(config, arch, packages) upload_repository(config, arch, packages) if @s3 end
before!(config, arch)
click to toggle source
# File lib/akabei/omakase/s3.rb, line 18 def before!(config, arch) download_repository(config, arch) if @s3 end
download_repository(config, arch)
click to toggle source
# File lib/akabei/omakase/s3.rb, line 26 def download_repository(config, arch) get(config.db_path(arch)) if config.repo_signer get(Pathname.new("#{config.db_path(arch)}.sig")) end get(config.files_path(arch)) get(config.abs_path(arch)) end
get(path)
click to toggle source
# File lib/akabei/omakase/s3.rb, line 35 def get(path) @shell.say("Download #{path}", :blue) @s3.get_object( bucket: @bucket_name, key: path.to_s, response_target: path, ) rescue Aws::S3::Errors::NoSuchKey @shell.say("S3: #{path} not found", :red) FileUtils.rm_f(path) end
put(path, mime_type)
click to toggle source
# File lib/akabei/omakase/s3.rb, line 66 def put(path, mime_type) @shell.say("Upload #{path}", :green) path.open do |f| @s3.put_object( @write_options.merge( bucket: @bucket_name, key: path.to_s, body: f, content_type: mime_type, ) ) end end
upload_repository(config, arch, packages)
click to toggle source
# File lib/akabei/omakase/s3.rb, line 51 def upload_repository(config, arch, packages) packages.each do |package| put(package.path, XZ_MIME_TYPE) if config.package_signer put(Pathname.new("#{package.path}.sig"), SIG_MIME_TYPE) end end put(config.abs_path(arch), GZIP_MIME_TYPE) put(config.files_path(arch), GZIP_MIME_TYPE) put(config.db_path(arch), GZIP_MIME_TYPE) if config.repo_signer put(Pathname.new("#{config.db_path(arch)}.sig"), SIG_MIME_TYPE) end end