Sha256: 85f8a03340a0c573f4b39a0437c167d51cf3c943a47cc358d7ca391e7bd9a065

Contents?: true

Size: 1.96 KB

Versions: 15

Compression:

Stored size: 1.96 KB

Contents

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

        finalizer :finalize_callback

        # @return [String]
        attr_reader :url

        # @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 = {})
          @url = options[:url]
          @connection = Ridley::Client.new_link(server_url: url, client_key: options[:client_key],
            client_name: options[:client_name], ssl: { verify: options[:ssl_verify] })
          super
        end

        # @return [String]
        def to_s
          friendly_name(url)
        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

15 entries across 15 versions & 1 rubygems

Version Path
berkshelf-api-3.0.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-2.2.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-2.1.3 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-2.1.2 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-2.1.1 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-2.1.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-2.0.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.4.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.3.1 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.3.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.2.2 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.2.1 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.2.0 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.2.0.rc2 lib/berkshelf/api/cache_builder/worker/chef_server.rb
berkshelf-api-1.2.0.rc1 lib/berkshelf/api/cache_builder/worker/chef_server.rb