class Omnibus::PackageRelease
Attributes
access_policy[R]
package_path[R]
Public Class Methods
new(package_path, opts={:access=>:private}, &block)
click to toggle source
@param package_path
[String] file system path to the package artifact @option opts [:private, :public_read] :access specifies access control on
uploaded files
@yield callback triggered by successful upload. Allows users of this
class to add UI feedback.
@yieldparam s3_object_key [String] the S3 key of the uploaded object.
# File lib/omnibus/package_release.rb, line 39 def initialize(package_path, opts={:access=>:private}, &block) @package_path = package_path @metadata = nil @s3_client = nil @after_upload = if block_given? block else lambda { |item_key| nil } end # sets @access_policy handle_opts(opts) end
Public Instance Methods
config()
click to toggle source
# File lib/omnibus/package_release.rb, line 147 def config Omnibus.config end
handle_opts(opts)
click to toggle source
# File lib/omnibus/package_release.rb, line 151 def handle_opts(opts) access_policy = opts[:access] if access_policy.nil? raise ArgumentError, "options to #{self.class} must specify `:access' (given: #{opts.inspect})" elsif not [:private, :public_read].include?(access_policy) raise ArgumentError, "option `:access' must be one of `[:private, :public_read]' (given: #{access_policy.inspect})" else @access_policy = access_policy end end
md5()
click to toggle source
# File lib/omnibus/package_release.rb, line 87 def md5 metadata["md5"] end
metadata()
click to toggle source
# File lib/omnibus/package_release.rb, line 91 def metadata @metadata ||= JSON.parse(metadata_json) end
metadata_json()
click to toggle source
# File lib/omnibus/package_release.rb, line 95 def metadata_json IO.read(package_metadata_path) end
metadata_key()
click to toggle source
# File lib/omnibus/package_release.rb, line 79 def metadata_key File.join(platform_path, File.basename(package_metadata_path)) end
package_content()
click to toggle source
# File lib/omnibus/package_release.rb, line 99 def package_content IO.read(package_path) end
package_key()
click to toggle source
# File lib/omnibus/package_release.rb, line 75 def package_key File.join(platform_path, File.basename(package_path)) end
package_metadata_path()
click to toggle source
# File lib/omnibus/package_release.rb, line 103 def package_metadata_path "#{package_path}.metadata.json" end
platform_path()
click to toggle source
# File lib/omnibus/package_release.rb, line 83 def platform_path File.join(metadata["platform"], metadata["platform_version"], metadata["arch"]) end
release()
click to toggle source
Primary API for this class. Validates S3 configuration and package files, then runs the upload. @return [void] @raise [NoPackageFile, NoPackageMetadataFile] when the package or
associated metadata file do not exist.
@raise [InvalidS3ReleaseConfiguration] when the Omnibus
configuration is
missing required settings.
@raise Also may raise errors from uber-s3 or net/http.
# File lib/omnibus/package_release.rb, line 62 def release validate_config! validate_package! s3_client.store(metadata_key, metadata_json, :access => access_policy) uploaded(metadata_key) s3_client.store(package_key, package_content, :access => access_policy, :content_md5 => md5) uploaded(package_key) end
s3_access_key()
click to toggle source
# File lib/omnibus/package_release.rb, line 135 def s3_access_key config[:release_s3_access_key] end
s3_bucket()
click to toggle source
# File lib/omnibus/package_release.rb, line 143 def s3_bucket config[:release_s3_bucket] end
s3_client()
click to toggle source
# File lib/omnibus/package_release.rb, line 126 def s3_client @s3_client ||= UberS3.new( :access_key => s3_access_key, :secret_access_key => s3_secret_key, :bucket => s3_bucket, :adaper => :net_http ) end
s3_secret_key()
click to toggle source
# File lib/omnibus/package_release.rb, line 139 def s3_secret_key config[:release_s3_secret_key] end
uploaded(key)
click to toggle source
# File lib/omnibus/package_release.rb, line 71 def uploaded(key) @after_upload.call(key) end
validate_config!()
click to toggle source
# File lib/omnibus/package_release.rb, line 117 def validate_config! if s3_access_key && s3_secret_key && s3_bucket true else err = InvalidS3ReleaseConfiguration.new(s3_bucket, s3_access_key, s3_secret_key) raise err end end
validate_package!()
click to toggle source
# File lib/omnibus/package_release.rb, line 107 def validate_package! if !File.exist?(package_path) raise NoPackageFile.new(package_path) elsif !File.exist?(package_metadata_path) raise NoPackageMetadataFile.new(package_metadata_path) else true end end