class Omnibus::S3Cache
Public Class Methods
fetch_missing()
click to toggle source
Fetch all source tarballs onto the local machine.
@return [true]
# File lib/omnibus/s3_cache.rb, line 98 def fetch_missing missing.each do |software| without_caching do software.fetch end end end
key_for(software)
click to toggle source
@private
The key with which to cache the package on S3. This is the name of the package, the version of the package, and its md5 checksum.
@example
"zlib-1.2.6-618e944d7c7cd6521551e30b32322f4a"
@param [Software] software
@return [String]
# File lib/omnibus/s3_cache.rb, line 119 def key_for(software) unless software.name raise InsufficientSpecification.new(:name, software) end unless software.version raise InsufficientSpecification.new(:version, software) end unless software.fetcher.checksum raise InsufficientSpecification.new("source md5 checksum", software) end "#{software.name}-#{software.version}-#{software.fetcher.checksum}" end
keys()
click to toggle source
The list of objects in the cache, by their key.
@return [Array<String>]
# File lib/omnibus/s3_cache.rb, line 45 def keys bucket.objects.map(&:key) end
list()
click to toggle source
List all software in the cache.
@return [Array<Software>]
# File lib/omnibus/s3_cache.rb, line 32 def list cached = keys softwares.select do |software| key = key_for(software) cached.include?(key) end end
missing()
click to toggle source
List all software missing from the cache.
@return [Array<Software>]
# File lib/omnibus/s3_cache.rb, line 54 def missing cached = keys softwares.select do |software| key = key_for(software) !cached.include?(key) end end
populate()
click to toggle source
Populate the cache with the all the missing software definitions.
@return [true]
# File lib/omnibus/s3_cache.rb, line 67 def populate missing.each do |software| without_caching do software.fetch end key = key_for(software) fetcher = software.fetcher log.info(log_key) do "Caching '#{fetcher.downloaded_file}' to '#{Config.s3_bucket}/#{key}'" end # Fetcher has already verified the downloaded file in software.fetch. # Compute the md5 from scratch because the fetcher may have been # specified with a different hashing algorithm. md5 = digest(fetcher.downloaded_file, :md5) File.open(fetcher.downloaded_file, "rb") do |file| store_object(key, file, md5, "public-read") end end true end
url_for(software)
click to toggle source
# File lib/omnibus/s3_cache.rb, line 135 def url_for(software) client.bucket(Config.s3_bucket).object(S3Cache.key_for(software)).public_url end
Private Class Methods
s3_configuration()
click to toggle source
# File lib/omnibus/s3_cache.rb, line 141 def s3_configuration config = { region: Config.s3_region, bucket_name: Config.s3_bucket, endpoint: Config.s3_endpoint, use_accelerate_endpoint: Config.s3_accelerate, force_path_style: Config.s3_force_path_style, } if Config.s3_iam_role_arn config[:iam_role_arn] = Config.s3_iam_role_arn elsif Config.s3_profile config[:profile] = Config.s3_profile else config[:access_key_id] = Config.s3_access_key config[:secret_access_key] = Config.s3_secret_key end config end
softwares()
click to toggle source
The list of softwares for all Omnibus
projects.
@return [Array<Software>]
# File lib/omnibus/s3_cache.rb, line 167 def softwares Omnibus.projects.inject({}) do |hash, project| project.library.each do |software| if software.fetcher.is_a?(NetFetcher) hash[software.name] = software end end hash end.values.sort end
without_caching() { || ... }
click to toggle source
# File lib/omnibus/s3_cache.rb, line 179 def without_caching(&block) original = Config.use_s3_caching Config.use_s3_caching(false) yield ensure Config.use_s3_caching(original) end