Module: Berkshelf

Extended by:
Mixin::Logging
Defined in:
lib/berkshelf.rb,
lib/berkshelf/cli.rb,
lib/berkshelf/shell.rb,
lib/berkshelf/config.rb,
lib/berkshelf/errors.rb,
lib/berkshelf/logger.rb,
lib/berkshelf/source.rb,
lib/berkshelf/version.rb,
lib/berkshelf/location.rb,
lib/berkshelf/lockfile.rb,
lib/berkshelf/packager.rb,
lib/berkshelf/resolver.rb,
lib/berkshelf/uploader.rb,
lib/berkshelf/berksfile.rb,
lib/berkshelf/installer.rb,
lib/berkshelf/mixin/git.rb,
lib/berkshelf/validator.rb,
lib/berkshelf/dependency.rb,
lib/berkshelf/downloader.rb,
lib/berkshelf/source_uri.rb,
lib/berkshelf/visualizer.rb,
lib/berkshelf/file_syncer.rb,
lib/berkshelf/ssl_policies.rb,
lib/berkshelf/locations/git.rb,
lib/berkshelf/mixin/logging.rb,
lib/berkshelf/base_generator.rb,
lib/berkshelf/commands/shelf.rb,
lib/berkshelf/community_rest.rb,
lib/berkshelf/cookbook_store.rb,
lib/berkshelf/init_generator.rb,
lib/berkshelf/locations/base.rb,
lib/berkshelf/locations/path.rb,
lib/berkshelf/resolver/graph.rb,
lib/berkshelf/cached_cookbook.rb,
lib/berkshelf/formatters/base.rb,
lib/berkshelf/formatters/json.rb,
lib/berkshelf/formatters/null.rb,
lib/berkshelf/formatters/human.rb,
lib/berkshelf/locations/github.rb,
lib/berkshelf/cookbook_generator.rb,
lib/berkshelf/commands/test_command.rb

Defined Under Namespace

Modules: FileSyncer, Mixin, Validator Classes: AbstractFunction, ArgumentError, BaseFormatter, BaseGenerator, BaseLocation, Berksfile, BerksfileNotFound, BerksfileReadError, BerkshelfError, CachedCookbook, ChefConnectionError, Cli, CommunityREST, CommunitySiteError, Config, ConfigNotFound, ConfigurationError, ConstraintNotSatisfied, CookbookGenerator, CookbookNotFound, CookbookStore, CookbookSyntaxError, CookbookValidationFailure, Dependency, DependencyNotFound, DependencyNotInstalled, DeprecatedError, Downloader, DuplicateDemand, DuplicateDependencyDefined, EnvironmentFileNotFound, EnvironmentNotFound, FrozenCookbook, GitCommandError, GitError, GitLocation, GitNotInstalled, GithubLocation, GraphvizCommandFailed, GraphvizNotInstalled, HumanFormatter, InitGenerator, Installer, InsufficientPrivledges, InternalError, InvalidConfiguration, InvalidCookbookFiles, InvalidSourceURI, JsonFormatter, LicenseNotFound, Location, Lockfile, LockfileNotFound, LockfileOutOfSync, LockfileParserError, Logger, MismatchedCookbookName, MissingLockfileCookbookVersion, NoAPISourcesDefined, NoSolutionError, NotACookbook, NullFormatter, OutdatedDependency, PackageError, Packager, PathLocation, Resolver, SSLPolicy, Shelf, Source, SourceURI, TestCommand, UnknownCompressionType, UploadFailure, Uploader, Visualizer

Constant Summary collapse

DEFAULT_FILENAME =
"Berksfile".freeze
Shell =

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

Class.new(Thor::Base.shell) do
  # Mute the output of this instance of UI until {#unmute!} is called
  def mute!
    @mute = true
  end

  # Unmute the output of this instance of UI until {#mute!} is called
  def unmute!
    @mute = false
  end

  def say(*args)
    return if quiet?
    super(*args)
  end
  alias_method :info, :say

  def warn(message, color = :yellow)
    say(message, color)
  end

  def error(message, color = :red)
    message = set_color(message, *color) if color
    super(message)
  end
end
VERSION =
"5.6.4"

Class Attribute Summary collapse

Attributes included from Mixin::Logging

#logger

Class Method Summary collapse

Class Attribute Details

.berkshelf_pathString

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’.

Returns:



81
82
83
# File 'lib/berkshelf.rb', line 81

def berkshelf_path
  @berkshelf_path ||= File.expand_path(ENV["BERKSHELF_PATH"] || "~/.berkshelf")
end

.uiBerkshelf::Shell

Returns:



70
71
72
# File 'lib/berkshelf.rb', line 70

def ui
  @ui
end

Class Method Details

.chef_configRidley::Chef::Config

The Chef configuration file.

Returns:

  • (Ridley::Chef::Config)


100
101
102
# File 'lib/berkshelf.rb', line 100

def chef_config
  @chef_config ||= Ridley::Chef::Config.new(ENV["BERKSHELF_CHEF_CONFIG"])
end

.chef_config=(config) ⇒ Object

Parameters:

  • (Ridley::Chef::Config)


105
106
107
# File 'lib/berkshelf.rb', line 105

def chef_config=(config)
  @chef_config = config
end

.configBerkshelf::Config

The Berkshelf configuration.

Returns:



88
89
90
# File 'lib/berkshelf.rb', line 88

def config
  Berkshelf::Config.instance
end

.config=(config) ⇒ Object

Parameters:



93
94
95
# File 'lib/berkshelf.rb', line 93

def config=(config)
  Berkshelf::Config.set_config(config)
end

.cookbook_storeBerkshelf::CookbookStore



119
120
121
# File 'lib/berkshelf.rb', line 119

def cookbook_store
  CookbookStore.instance
end

.formatter~Formatter

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

Returns:

  • (~Formatter)


127
128
129
# File 'lib/berkshelf.rb', line 127

def formatter
  @formatter ||= HumanFormatter.new
end

.initialize_filesystemObject

Initialize the filepath for the Berkshelf path..



110
111
112
113
114
115
116
# File 'lib/berkshelf.rb', line 110

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) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/berkshelf.rb', line 136

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               = options.slice(: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

  unless ridley_options[:server_url].present?
    raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.server_url"
  end

  unless ridley_options[:client_name].present?
    raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.node_name"
  end

  unless ridley_options[:client_key].present?
    raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.client_key"
  end

  # @todo  Something scary going on here - getting an instance of Kitchen::Logger from test-kitchen
  # https://github.com/opscode/test-kitchen/blob/master/lib/kitchen.rb#L99
  Celluloid.logger = nil unless ENV["DEBUG_CELLULOID"]
  Ridley.open(ridley_options, &block)
rescue Ridley::Errors::RidleyError => ex
  log.exception(ex)
  raise ChefConnectionError, ex # todo implement
end

.rootPathname

Returns:



65
66
67
# File 'lib/berkshelf.rb', line 65

def root
  @root ||= Pathname.new(File.expand_path("../", File.dirname(__FILE__)))
end

.set_format(name) ⇒ ~Formatter

Specify the format for output

Examples:

Berkshelf.set_format :json

Parameters:

  • format_id (#to_sym)

    the ID of the registered formatter to use

Returns:

  • (~Formatter)


180
181
182
183
# File 'lib/berkshelf.rb', line 180

def set_format(name)
  id = name.to_s.capitalize
  @formatter = Berkshelf.const_get("#{id}Formatter").new
end

.ssl_policyObject



131
132
133
# File 'lib/berkshelf.rb', line 131

def ssl_policy
  @ssl_policy ||= SSLPolicy.new
end

.which(executable) ⇒ String?

Location an executable in the current user’s $PATH

Returns:

  • (String, nil)

    the path to the executable, or nil if not present



189
190
191
192
193
194
195
196
197
198
# File 'lib/berkshelf.rb', line 189

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