Module: Bellboy

Defined in:
lib/bellboy/errors.rb,
lib/bellboy.rb,
lib/bellboy/cli.rb,
lib/bellboy/logger.rb,
lib/bellboy/uploader.rb,
lib/bellboy/installer.rb,
lib/bellboy/versioner.rb,
lib/bellboy/mixin/berkshelf.rb

Overview

Copyright 2014 Dyn Inc.

Authors: Kristian Van Der Vliet <[email protected]>

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: BerksfileBellboy Classes: BellboyAPIError, BellboyError, BellboyIOError, ChefConnectionError, Cli, ConfigNotFound, DatabagAPIError, DatabagReadError, DatabagWriteError, Installer, Logger, Uploader, Versioner

Constant Summary collapse

DEFAULT_FILENAME =
'Bellboy'
LOG_LEVEL_NONE =
0
LOG_LEVEL_INFO =
1
LOG_LEVEL_DEBUG =
2

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



42
43
44
# File 'lib/bellboy.rb', line 42

def logger
  @logger
end

Class Method Details

.berks_from_file(filepath) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/bellboy.rb', line 33

def berks_from_file(filepath)
  begin
    Berkshelf::Berksfile.from_file(filepath)
  rescue Berkshelf::BerksfileNotFound
    Bellboy.logger.log "Berkfile #{filepath} could not be found."
    exit
  end
end

.berks_sources(berksfile) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bellboy.rb', line 44

def berks_sources(berksfile)
  sources = Array.new

  dependencies = berksfile.list
  dependencies.each do |dependency|
    Bellboy.logger.debug "Adding source for #{dependency.name}"
    sources << berksfile.retrieve_locked(dependency)
  end

  sources
end

.list(berksfile) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/bellboy.rb', line 78

def list(berksfile)
  databags = {}

  local_sources = Bellboy.berks_sources(berksfile)

  local_sources.each do |source|
    Bellboy.logger.debug "Source: #{source.path}"

    path = File.join(source.path, 'data_bags')
    Dir.foreach(path) do |dir|
      subdir = File.join(path, dir)

      next unless File.directory?(subdir)
      next if dir == '.' || dir == '..'

      databags[dir] = []

      Dir.foreach(subdir) do |item|
        next if item == '.' || item == '..'
        next unless item.match('^.*\.json$')

        databags[dir] << item.chomp('.json')
      end
    end if Dir.exists?(path)

  end

  databags
end

.ridley_connection(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bellboy.rb', line 56

def ridley_connection(options = {})
  ridley_options               = options.slice(:ssl)
  ridley_options[:server_url]  = options[:server_url] || Berkshelf::Config.instance.chef.chef_server_url
  ridley_options[:client_name] = options[:client_name] || Berkshelf::Config.instance.chef.node_name
  ridley_options[:client_key]  = options[:client_key] || Berkshelf::Config.instance.chef.client_key
  ridley_options[:ssl]         = { verify: (options[:ssl_verify] || Berkshelf::Config.instance.ssl.verify) }

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

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

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

  Ridley.new(ridley_options)
end