lib/mixlib/install/backend/bintray.rb in mixlib-install-1.0.2 vs lib/mixlib/install/backend/bintray.rb in mixlib-install-1.0.3
- old
+ new
@@ -36,19 +36,18 @@
module Mixlib
class Install
class Backend
class Bintray < Base
class UnknownArchitecture < StandardError; end
-
- ENDPOINT = "https://bintray.com/api/v1/".freeze
-
+ class VersionNotFound < StandardError; end
# Bintray credentials for api read access. These are here intentionally.
BINTRAY_USERNAME = "mixlib-install@chef".freeze
-
BINTRAY_PASSWORD = "a83d3a2ffad50eb9a2230f281a2e19b70fe0db2d".freeze
+ ENDPOINT = "https://bintray.com/api/v1/".freeze
DOWNLOAD_URL_ENDPOINT = "https://packages.chef.io".freeze
+ COMPAT_DOWNLOAD_URL_ENDPOINT = "http://chef.bintray.com".freeze
def endpoint
@endpoint ||= ENV.fetch("BINTRAY_ENDPOINT", ENDPOINT)
end
@@ -112,19 +111,29 @@
#
# @return [Array<ArtifactInfo>] Array of info about found artifacts
#
def bintray_artifacts
version = options.latest_version? ? latest_version : options.product_version
- results = bintray_get("#{options.channel}/#{options.product_name}/versions/#{version}/files")
+ begin
+ results = bintray_get("#{options.channel}/#{options.product_name}/versions/#{version}/files")
+ rescue Net::HTTPServerException => e
+ if e.message =~ /404 "Not Found"/
+ raise VersionNotFound,
+ "Specified version (#{version}) not found for #{options.product_name} in #{options.channel} channel."
+ else
+ raise
+ end
+ end
#
- # Delete .asc files
- # Also delete .pkg files which are uploaded along with dmg files for
+ # Delete files that we don't want as part of the artifact info array
+ # Windows: .asc files
+ # MAC OS _X: .pkg files which are uploaded along with dmg files for
# some chef versions.
#
- results.reject! do |r|
- r["name"].end_with?(".asc") || r["name"].end_with?(".pkg")
+ %w{ asc pkg }.each do |ext|
+ results.reject! { |r| r["name"].end_with?(".#{ext}") }
end
# Convert results to build records
results.map! { |a| create_artifact(a) }
@@ -180,20 +189,44 @@
# @return [ArtifactInfo] ArtifactInfo instance
#
def create_artifact(artifact_map)
platform_info = parse_platform_info(artifact_map)
- url = "#{DOWNLOAD_URL_ENDPOINT}/#{options.channel}/#{artifact_map["path"]}"
-
ArtifactInfo.new(
sha1: artifact_map["sha1"],
sha256: artifact_map["sha256"],
version: artifact_map["version"],
platform: platform_info[:platform],
platform_version: platform_info[:platform_version],
architecture: platform_info[:architecture],
- url: url
+ url: url(artifact_map)
)
+ end
+
+ #
+ # Creates the URL for the artifact.
+ #
+ # For some older platform & platform_version combinations we need to
+ # use COMPAT_DOWNLOAD_URL_ENDPOINT since these versions have an
+ # OpenSSL version that can not verify the DOWNLOAD_URL_ENDPOINT
+ # based urls
+ #
+ # @param artifact_map
+ # see #create_artifact for details.
+ #
+ # @return [String] url for the artifact
+ #
+ def url(artifact_map)
+ platform_info = parse_platform_info(artifact_map)
+
+ base_url = case "#{platform_info[:platform]}-#{platform_info[:platform_version]}"
+ when "freebsd-9"
+ COMPAT_DOWNLOAD_URL_ENDPOINT
+ else
+ DOWNLOAD_URL_ENDPOINT
+ end
+
+ "#{base_url}/#{options.channel}/#{artifact_map["path"]}"
end
#
# Parses platform info
#