module Berkshelf

Constants

DEFAULT_FILENAME
Shell

Subclass the current shell (which is different based on the OS)

VERSION

Attributes

berkshelf_path[W]
ui[W]

Public Class Methods

berkshelf_path() click to toggle source

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]

# File lib/berkshelf.rb, line 89
def berkshelf_path
  @berkshelf_path ||= File.expand_path(ENV["BERKSHELF_PATH"] || "~/.berkshelf")
end
chef_config() click to toggle source

The Chef configuration file.

@return [Berkshelf::ChefConfigCompat]

# File lib/berkshelf.rb, line 108
def chef_config
  @chef_config ||= Berkshelf::ChefConfigCompat.new(ENV["BERKSHELF_CHEF_CONFIG"])
end
chef_config=(config) click to toggle source

@param [Ridley::Chef::Config]

# File lib/berkshelf.rb, line 113
def chef_config=(config)
  @chef_config = config
end
config() click to toggle source

The Berkshelf configuration.

@return [Berkshelf::Config]

# File lib/berkshelf.rb, line 96
def config
  Berkshelf::Config.instance
end
config=(config) click to toggle source

@param [Berkshelf::Config]

# File lib/berkshelf.rb, line 101
def config=(config)
  Berkshelf::Config.set_config(config)
end
cookbook_store() click to toggle source

@return [Berkshelf::CookbookStore]

# File lib/berkshelf.rb, line 127
def cookbook_store
  CookbookStore.instance
end
fix_proxies() click to toggle 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
formatter() click to toggle source

Get the appropriate Formatter object based on the formatter classes that have been registered.

@return [~Formatter]

# File lib/berkshelf.rb, line 135
def formatter
  @formatter ||= HumanFormatter.new
end
initialize_filesystem() click to toggle source

Initialize the filepath for the Berkshelf path..

# 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
ridley_connection(options = {}, &block) click to toggle source

@raise [Berkshelf::ChefConnectionError]

# 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
root() click to toggle source

@return [Pathname]

# File lib/berkshelf.rb, line 73
def root
  @root ||= Pathname.new(File.expand_path("../", File.dirname(__FILE__)))
end
set_format(name) click to toggle source

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]

# File lib/berkshelf.rb, line 188
def set_format(name)
  id = name.to_s.capitalize
  @formatter = Berkshelf.const_get("#{id}Formatter").new
end
ssl_policy() click to toggle source
# File lib/berkshelf.rb, line 139
def ssl_policy
  @ssl_policy ||= SSLPolicy.new
end
ui() click to toggle source

@return [Berkshelf::Shell]

# File lib/berkshelf.rb, line 78
def ui
  @ui ||= Berkshelf::Shell.new
end
which(executable) click to toggle source

Location an executable in the current user’s $PATH

@return [String, nil]

the path to the executable, or +nil+ if not present
# 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

Private Class Methods

null_stream() click to toggle 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