module Berkshelf
Constants
- DEFAULT_FILENAME
- Shell
-
Subclass the current shell (which is different based on the OS)
- VERSION
Attributes
Public Class Methods
Source
# File lib/berkshelf.rb, line 89 def berkshelf_path @berkshelf_path ||= File.expand_path(ENV["BERKSHELF_PATH"] || "~/.berkshelf") end
Returns the filepath to the location Berkshelf
will use for storage; temp files will go here, Cookbooks will be downloaded to or uploaded from here. By default this is ‘~/.berkshelf’ but can be overridden by specifying a value for the ENV variable ‘BERKSHELF_PATH’.
@return [String]
Source
# File lib/berkshelf.rb, line 108 def chef_config @chef_config ||= Berkshelf::ChefConfigCompat.new(ENV["BERKSHELF_CHEF_CONFIG"]) end
The Chef configuration file.
@return [Berkshelf::ChefConfigCompat]
Source
# File lib/berkshelf.rb, line 113 def chef_config=(config) @chef_config = config end
@param [Ridley::Chef::Config]
Source
# File lib/berkshelf.rb, line 96 def config Berkshelf::Config.instance end
The Berkshelf
configuration.
@return [Berkshelf::Config]
Source
# File lib/berkshelf.rb, line 101 def config=(config) Berkshelf::Config.set_config(config) end
@param [Berkshelf::Config]
Source
# File lib/berkshelf.rb, line 127 def cookbook_store CookbookStore.instance end
@return [Berkshelf::CookbookStore]
Source
# File lib/berkshelf.rb, line 31 def self.fix_proxies ENV["http_proxy"] = ENV["HTTP_PROXY"] if ENV["HTTP_PROXY"] && !ENV["http_proxy"] ENV["https_proxy"] = ENV["HTTPS_PROXY"] if ENV["HTTPS_PROXY"] && !ENV["https_proxy"] ENV["ftp_proxy"] = ENV["FTP_PROXY"] if ENV["FTP_PROXY"] && !ENV["ftp_proxy"] ENV["no_proxy"] = ENV["NO_PROXY"] if ENV["NO_PROXY"] && !ENV["no_proxy"] end
Source
# File lib/berkshelf.rb, line 135 def formatter @formatter ||= HumanFormatter.new end
Get the appropriate Formatter object based on the formatter classes that have been registered.
@return [~Formatter]
Source
# File lib/berkshelf.rb, line 118 def initialize_filesystem FileUtils.mkdir_p(berkshelf_path, mode: 0755) unless File.writable?(berkshelf_path) raise InsufficientPrivledges.new(berkshelf_path) end end
Initialize the filepath for the Berkshelf
path..
Source
# File lib/berkshelf.rb, line 144 def ridley_connection(options = {}, &block) ssl_options = {} ssl_options[:verify] = if options[:ssl_verify].nil? Berkshelf.config.ssl.verify else options[:ssl_verify] end ssl_options[:cert_store] = ssl_policy.store if ssl_policy.store ridley_options = {} ridley_options[:ssl] = options[:ssl] if options.key?(:ssl) ridley_options[:server_url] = options[:server_url] || Berkshelf.config.chef.chef_server_url ridley_options[:client_name] = options[:client_name] || Berkshelf.config.chef.node_name ridley_options[:client_key] = options[:client_key] || Berkshelf.config.chef.client_key ridley_options[:ssl] = ssl_options if !ridley_options[:server_url] || ridley_options[:server_url] =~ /^\s*$/ raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.server_url" end if !ridley_options[:client_name] || ridley_options[:client_name] =~ /^\s*$/ raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.node_name" end if !ridley_options[:client_key] || ridley_options[:client_key].to_s =~ /^\s*$/ raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.client_key" end RidleyCompat.new_client(**ridley_options, &block) rescue ChefConnectionError, BerkshelfError raise rescue => ex log.exception(ex) raise ChefConnectionError, ex # todo implement end
@raise [Berkshelf::ChefConnectionError]
Source
# File lib/berkshelf.rb, line 73 def root @root ||= Pathname.new(File.expand_path("../", File.dirname(__FILE__))) end
@return [Pathname]
Source
# File lib/berkshelf.rb, line 188 def set_format(name) id = name.to_s.capitalize @formatter = Berkshelf.const_get("#{id}Formatter").new end
Specify the format for output
@param [#to_sym] format_id
the ID of the registered formatter to use
@example Berkshelf.set_format
:json
@return [~Formatter]
Source
# File lib/berkshelf.rb, line 139 def ssl_policy @ssl_policy ||= SSLPolicy.new end
Source
# File lib/berkshelf.rb, line 78 def ui @ui ||= Berkshelf::Shell.new end
@return [Berkshelf::Shell]
Source
# File lib/berkshelf.rb, line 197 def which(executable) if File.file?(executable) && File.executable?(executable) executable elsif ENV["PATH"] path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |p| File.executable?(File.join(p, executable)) end path && File.expand_path(executable, path) end end
Location
an executable in the current user’s $PATH
@return [String, nil]
the path to the executable, or +nil+ if not present
Private Class Methods
Source
# File lib/berkshelf.rb, line 210 def null_stream @null ||= begin strm = STDOUT.clone strm.reopen(RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ ? "NUL:" : "/dev/null") strm.sync = true strm end end