Class: ChefDK::Policyfile::LocalLockFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile/local_lock_fetcher.rb

Overview

A policyfile lock fetcher that can read a lock from a local disk

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, source_options, storage_config) ⇒ LocalLockFetcher

Initialize a LocalLockFetcher

Parameters:

  • name (String)

    The name of the policyfile

  • source_options (Hash)

    A hash with a :path key pointing at the location of the lock

  • storage_config (StorageConfig)


37
38
39
40
41
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 37

def initialize(name, source_options, storage_config)
  @name = name
  @source_options = source_options
  @storage_config = storage_config
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 27

def name
  @name
end

#source_optionsObject (readonly)

Returns the value of attribute source_options.



28
29
30
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 28

def source_options
  @source_options
end

#storage_configObject (readonly)

Returns the value of attribute storage_config.



29
30
31
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 29

def storage_config
  @storage_config
end

Instance Method Details

#apply_locked_source_options(options_from_lock) ⇒ Object

Applies source options from a lock file. This is used to make sure that the same policyfile lock is loaded that was locked

Parameters:

  • options_from_lock (Hash)

    The source options loaded from a policyfile lock



71
72
73
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 71

def apply_locked_source_options(options_from_lock)
  # There are no options the lock could provide
end

#errorsArray<String>

Check the options provided when craeting this class for errors

Returns:

  • (Array<String>)

    A list of errors found



52
53
54
55
56
57
58
59
60
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 52

def errors
  error_messages = []

  [:path].each do |key|
    error_messages << "include_policy for #{name} is missing key #{key}" unless source_options[key]
  end

  error_messages
end

#lock_dataString

Returns of the policyfile lock data.

Returns:

  • (String)

    of the policyfile lock data



76
77
78
79
80
81
82
83
84
85
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 76

def lock_data
  FFI_Yajl::Parser.new.parse(content).tap do |data|
    data["cookbook_locks"].each do |cookbook_name, cookbook_lock|
      cookbook_path = cookbook_lock["source_options"]["path"]
      if !cookbook_path.nil?
        cookbook_lock["source_options"]["path"] = transform_path(cookbook_path)
      end
    end
  end
end

#source_options_for_lockHash

Returns The source_options that describe how to fetch this exact lock again.

Returns:

  • (Hash)

    The source_options that describe how to fetch this exact lock again



63
64
65
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 63

def source_options_for_lock
  source_options
end

#valid?True, False

Returns:

  • (True)

    if there were no errors with the provided source_options

  • (False)

    if there were errors with the provided source_options



45
46
47
# File 'lib/chef-dk/policyfile/local_lock_fetcher.rb', line 45

def valid?
  errors.empty?
end