lib/license_acceptance/acceptor.rb in license-acceptance-1.0.3 vs lib/license_acceptance/acceptor.rb in license-acceptance-1.0.5
- old
+ new
@@ -37,25 +37,25 @@
def_delegator :@config, :output
# For applications that just need simple logic to handle a failed license acceptance flow we include this small
# wrapper. Apps with more complex logic (like logging to a logging engine) should call the non-bang version and
# handle the exception.
- def check_and_persist!(product_name, version)
- check_and_persist(product_name, version)
- rescue LicenseNotAcceptedError
- output.puts "#{product_name} cannot execute without accepting the license"
+ def check_and_persist!(product_id, version)
+ check_and_persist(product_id, version)
+ rescue LicenseNotAcceptedError => e
+ output.puts "#{e.product.pretty_name} cannot execute without accepting the license"
exit 172
end
- def check_and_persist(product_name, version)
+ def check_and_persist(product_id, version)
if accepted_no_persist?
logger.debug("Chef License accepted with no persistence")
@acceptance_value = ACCEPT_NO_PERSIST
return true
end
- product_relationship = product_reader.lookup(product_name, version)
+ product_relationship = product_reader.lookup(product_id, version)
missing_licenses = file_strategy.accepted?(product_relationship)
# They have already accepted all licenses and stored their acceptance in the persistent files
if missing_licenses.empty?
@@ -85,20 +85,20 @@
[]
end
end
return true
else
- raise LicenseNotAcceptedError.new(missing_licenses)
+ raise LicenseNotAcceptedError.new(product_relationship.parent, missing_licenses)
end
end
- def self.check_and_persist!(product_name, version, opts={})
- new(opts).check_and_persist!(product_name, version)
+ def self.check_and_persist!(product_id, version, opts={})
+ new(opts).check_and_persist!(product_id, version)
end
- def self.check_and_persist(product_name, version, opts={})
- new(opts).check_and_persist(product_name, version)
+ def self.check_and_persist(product_id, version, opts={})
+ new(opts).check_and_persist(product_id, version)
end
# Check whether the specified product requires license acceptance for the given version.
def license_required?(mixlib_name, version)
product = product_reader.lookup_by_mixlib(mixlib_name)
@@ -107,15 +107,15 @@
return true if version == :latest || version.nil?
Gem::Version.new(version) >= Gem::Version.new(product.license_required_version)
end
# Some callers only know about mixlib names so we need a way for them to get the product
- # name as this library knows it.
- def name_from_mixlib(mixlib_name)
+ # id as this library knows it.
+ def id_from_mixlib(mixlib_name)
product = product_reader.lookup_by_mixlib(mixlib_name)
return nil if product.nil?
- product.name
+ product.id
end
# Return the value that was matched ("accept", "accept-no-persist", etc.). Used by callers so they do not
# have to know the precedence order between provided/environment/argument. Can just get back the value
# that was used. Value is only guaranteed to be set after calling check_and_persist.
@@ -158,11 +158,13 @@
end
end
class LicenseNotAcceptedError < RuntimeError
- def initialize(missing_licenses)
- msg = "Missing licenses for the following:\n* " + missing_licenses.map(&:name).join("\n* ")
+ attr_reader :product
+ def initialize(product, missing_licenses)
+ @product = product
+ msg = "Missing licenses for the following:\n* " + missing_licenses.map(&:id).join("\n* ")
super(msg)
end
end
end