Sha256: baf462daf7e2cec1190c8ee1a5c08b986c414799861fbe5bfa21f2eae04158f2

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

module Berkshelf::API
  class CacheBuilder
    module Worker
      class ChefServer < Worker::Base
        worker_type "chef_server"

        finalizer :finalize_callback

        # @option options [String] :url
        #   the URL of the target Chef Server
        # @option options [String] :client_name
        #   the name of the client for authenticating to the Chef Server
        # @option options [String] :client_key
        #   a client key for authenticating to the Chef Server
        # @option options [Boolean] :ssl_verify
        #   turn ssl verification off if you have an unsigned SSL certificate
        def initialize(options = {})
          @connection = Ridley::Client.new_link(server_url: options[:url], client_key: options[:client_key],
            client_name: options[:client_name], ssl: { verify: options[:ssl_verify] })
          super
        end

        # @return [Array<RemoteCookbook>]
        #  The list of cookbooks this builder can find
        def cookbooks
          [].tap do |cookbook_versions|
            connection.cookbook.all.each do |cookbook, versions|
              versions.each do |version|
                cookbook_versions << RemoteCookbook.new(cookbook, version, self.class.worker_type,
                  @connection.server_url, priority)
              end
            end
          end
        end

        # @param [RemoteCookbook] remote
        #
        # @return [Ridley::Chef::Cookbook::Metadata]
        def metadata(remote)
          metadata_hash = connection.cookbook.find(remote.name, remote.version).metadata
          Ridley::Chef::Cookbook::Metadata.from_hash(metadata_hash)
        end

        private

          attr_reader :connection

          def finalize_callback
            connection.terminate if connection && connection.alive?
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
berkshelf-api-1.1.1 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.1.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb