Class: Batali::Origin::ChefServer

Inherits:
Batali::Origin show all
Includes:
Utility::Chef, Bogo::Memoization
Defined in:
lib/batali/origin/chef_server.rb

Overview

Fetch unit information from chef server

Instance Method Summary collapse

Methods included from Utility::Chef

#api_service, included, #init_chef!

Constructor Details

#initialize(*_) ⇒ ChefServer

Returns a new instance of ChefServer.



18
19
20
21
22
23
24
25
# File 'lib/batali/origin/chef_server.rb', line 18

def initialize(*_)
  super
  init_chef!
  self.identifier = Digest::SHA256.hexdigest(endpoint)
  unless(name?)
    self.name = identifier
  end
end

Instance Method Details

#unitsArray<Unit>

Returns all units.

Returns:

  • (Array<Unit>)

    all units



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/batali/origin/chef_server.rb', line 28

def units
  memoize(:units) do
    debug "Fetching units from chef server: #{endpoint}"
    units = api_service.get_rest('cookbooks?num_versions=all').map do |c_name, meta|
      meta['versions'].map do |info|
        "#{c_name}/#{info['version']}"
      end
    end.flatten.map do |ckbk|
      debug "Unit information from #{endpoint}: #{ckbk.inspect}"
      c_name, c_version = ckbk.split('/', 2)
      c_deps = api_service.get_rest(
        "cookbooks/#{c_name}/#{c_version}"
      )..dependencies.to_a
      Unit.new(
        :name => c_name,
        :version => c_version,
        :dependencies => c_deps,
        :source => Smash.new(
          :type => :chef_server,
          :version => c_version,
          :dependencies => c_deps,
          :endpoint => endpoint,
          :client_key => client_key,
          :client_name => client_name,
          :cache_path => cache_path
        )
      )
    end.flatten
  end
end