lib/mixlib/install/backend/artifactory.rb in mixlib-install-0.8.0.alpha.7 vs lib/mixlib/install/backend/artifactory.rb in mixlib-install-0.8.0.alpha.8
- old
+ new
@@ -18,27 +18,22 @@
require "net/http"
require "json"
require "mixlib/install/artifact_info"
require "artifactory"
+require "mixlib/install/backend/base"
module Mixlib
class Install
class Backend
- class Artifactory
+ class Artifactory < Base
class ConnectionError < StandardError; end
class AuthenticationError < StandardError; end
class NoArtifactsError < StandardError; end
ENDPOINT = "http://artifactory.chef.co".freeze
- attr_accessor :options
-
- def initialize(options)
- @options = options
- end
-
# Create filtered list of artifacts
#
# @return [Array<ArtifactInfo>] list of artifacts for the configured
# channel, product name, and product version.
# @return [ArtifactInfo] arifact info for the configured
@@ -107,17 +102,18 @@
#
# Get artifacts for a given version, channel and product_name
#
# @return [Array<ArtifactInfo>] Array of info about found artifacts
def artifactory_artifacts(version)
- results = artifactory_query(<<-QUERY)
+ results = artifactory_query(<<-QUERY
items.find(
{"repo": "omnibus-#{options.channel}-local"},
{"@omnibus.project": "#{options.product_name}"},
{"@omnibus.version": "#{version}"}
).include("repo", "path", "name", "property")
QUERY
+ )
# Merge artifactory properties and downloadUri to a flat Hash
results.collect! do |result|
{ "downloadUri" => generate_download_uri(result) }.merge(
map_properties(result["properties"])
@@ -189,19 +185,19 @@
def artifactory_request
begin
results = yield
rescue Errno::ETIMEDOUT, ::Artifactory::Error::ConnectionError
- raise ConnectionError, <<-EOS
-Artifactory endpoint '#{::Artifactory.endpoint}' is unreachable. Check that
+ raise ConnectionError, <<-MSG
+Artifactory endpoint '#{endpoint}' is unreachable. Check that
the endpoint is correct and there is an open connection to Chef's private network.
- EOS
+ MSG
rescue ::Artifactory::Error::HTTPError => e
if e.code == 401 && e.message =~ /Bad credentials/
- raise AuthenticationError, <<-EOS
+ raise AuthenticationError, <<-MSG
Artifactory server denied credentials. Verify ARTIFACTORY_USERNAME and
ARTIFACTORY_PASSWORD environment variables are configured properly.
- EOS
+ MSG
else
raise e
end
end