Class: ChefCLI::Policyfile::LocalLockFetcher

Inherits:
Object
  • Object
show all
Includes:
LockFetcherMixin
Defined in:
lib/chef-cli/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

Methods included from LockFetcherMixin

#validate_revision_id

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)


39
40
41
42
43
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 39

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.



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

def name
  @name
end

#source_optionsObject (readonly)

Returns the value of attribute source_options.



30
31
32
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 30

def source_options
  @source_options
end

#storage_configObject (readonly)

Returns the value of attribute storage_config.



31
32
33
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 31

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



73
74
75
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 73

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

#errorsArray<String>

Check the options provided when creating this class for errors

Returns:

  • (Array<String>)

    A list of errors found



54
55
56
57
58
59
60
61
62
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 54

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



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 78

def lock_data
  FFI_Yajl::Parser.new.parse(content).tap do |data|
    validate_revision_id(data["revision_id"], source_options)
    data["cookbook_locks"].each do |cookbook_name, cookbook_lock|
      cookbook_path = cookbook_lock["source_options"]["path"]
      unless 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



65
66
67
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 65

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



47
48
49
# File 'lib/chef-cli/policyfile/local_lock_fetcher.rb', line 47

def valid?
  errors.empty?
end