Class: Berkshelf::Uploader

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/berkshelf/uploader.rb

Overview

Author:

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Uploader

Returns a new instance of Uploader.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :server_url (String)

    URL to the Chef API

  • :client_name (String)

    name of the client used to authenticate with the Chef API

  • :client_key (String)

    filepath to the client’s private key used to authenticate with the Chef API

  • :organization (String)

    the Organization to connect to. This is only used if you are connecting to private Chef or hosted Chef

  • :params (Hash)

    URI query unencoded key/value pairs

  • :headers (Hash)

    unencoded HTTP header key/value pairs

  • :request (Hash)

    request options

  • :ssl (Hash)

    SSL options

  • :proxy (URI, String, Hash)

    URI, String, or Hash of HTTP proxy options



30
31
32
# File 'lib/berkshelf/uploader.rb', line 30

def initialize(options = {})
  @conn = Ridley.connection(options)
end

Instance Method Details

#upload(cookbook, options = {}) ⇒ Boolean

Uploads a CachedCookbook from a CookbookStore to this instances Chef Server URL

Parameters:

  • cookbook (CachedCookbook)

    a cached cookbook to upload

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :force (Boolean)

    Upload the Cookbook even if the version already exists and is frozen on the target Chef Server

  • :freeze (Boolean)

    Freeze the uploaded Cookbook on the Chef Server so that it cannot be overwritten

  • :skip_syntax_check (Boolean)

    Skip syntax checking of the Cookbook to reduce the overall upload time

Returns:

  • (Boolean)

Raises:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/berkshelf/uploader.rb', line 52

def upload(cookbook, options = {})
  cookbook.validate! unless options[:skip_syntax_check]
  mutex     = Mutex.new
  checksums = cookbook.checksums.dup
  sandbox   = conn.sandbox.create(checksums.keys)

  sandbox.multi_upload(checksums)
  sandbox.commit
  sandbox.terminate

  conn.cookbook.save(
    cookbook.cookbook_name,
    cookbook.version,
    cookbook.to_json,
    options
  )
end