lib/berkshelf/locations/chef_api_location.rb in berkshelf-0.6.0.beta4 vs lib/berkshelf/locations/chef_api_location.rb in berkshelf-1.0.0.rc1
- old
+ new
@@ -84,13 +84,13 @@
# @param [#to_s] name
# @param [Solve::Constraint] version_constraint
# @param [Hash] options
#
# @option options [String, Symbol] :chef_api
- # a URL to a Chef API. Alternatively the symbol :knife can be provided
+ # a URL to a Chef API. Alternatively the symbol :config can be provided
# which will instantiate this location with the values found in your
- # knife configuration.
+ # Berkshelf configuration.
# @option options [String] :node_name
# the name of the client to use to communicate with the Chef API.
# Default: Chef::Config[:node_name]
# @option options [String] :client_key
# the filepath to the authentication key for the client
@@ -98,21 +98,26 @@
def initialize(name, version_constraint, options = {})
@name = name
@version_constraint = version_constraint
@downloaded_status = false
+ if options[:chef_api] == :knife
+ Berkshelf.formatter.deprecation "specifying 'chef_api :knife' is deprecated. Please use 'chef_api :config'."
+ options[:chef_api] = :config
+ end
+
validate_options!(options)
- if options[:chef_api] == :knife
- begin
- Berkshelf.load_config
- rescue KnifeConfigNotFound => e
- raise KnifeConfigNotFound, "A Knife config is required when ':knife' is given for the value of a 'chef_api' location. #{e}"
+ if options[:chef_api] == :config
+ unless Berkshelf::Config.instance.chef.node_name.present? &&
+ Berkshelf::Config.instance.chef.client_key.present? &&
+ Berkshelf::Config.instance.chef.chef_server_url.present?
+ raise ConfigurationError, "A Berkshelf configuration is required with a 'chef.client_key', 'chef.chef_server_Url', and 'chef.node_name' setting to install or upload cookbooks using 'chef_api :config'."
end
- @node_name = Chef::Config[:node_name]
- @client_key = Chef::Config[:client_key]
- @uri = Chef::Config[:chef_server_url]
+ @node_name = Berkshelf::Config.instance.chef.node_name
+ @client_key = Berkshelf::Config.instance.chef.client_key
+ @uri = Berkshelf::Config.instance.chef.chef_server_url
else
@node_name = options[:node_name]
@client_key = options[:client_key]
@uri = options[:chef_api]
end
@@ -248,10 +253,10 @@
# @param [Hash] options
#
# @raise [InvalidChefAPILocation] if any of the options are missing or their values do not
# pass validation
def validate_options!(options)
- if options[:chef_api] == :knife
+ if options[:chef_api] == :config
return true
end
missing_options = [:node_name, :client_key] - options.keys