Class: ChefCLI::Policyfile::RemoteLockFetcher

Inherits:
Object
  • Object
show all
Includes:
LockFetcherMixin
Defined in:
lib/chef-cli/policyfile/remote_lock_fetcher.rb

Overview

A policyfile lock fetcher that can read a lock from a remote location.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LockFetcherMixin

#validate_revision_id

Constructor Details

#initialize(name, source_options) ⇒ RemoteLockFetcher

Initialize a RemoteLockFetcher

Parameters:

  • name (String)

    The name of the policyfile

  • source_options (Hash)

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



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#source_optionsObject (readonly)

Returns the value of attribute source_options.



32
33
34
# File 'lib/chef-cli/policyfile/remote_lock_fetcher.rb', line 32

def source_options
  @source_options
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



72
73
74
# File 'lib/chef-cli/policyfile/remote_lock_fetcher.rb', line 72

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



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

def errors
  error_messages = []

  [:remote].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



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

def lock_data
  fetch_lock_data.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?
        raise ChefCLI::InvalidLockfile, "Invalid cookbook path: #{cookbook_path}. Remote Policyfiles should only use remote cookbooks."
      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



64
65
66
# File 'lib/chef-cli/policyfile/remote_lock_fetcher.rb', line 64

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



46
47
48
# File 'lib/chef-cli/policyfile/remote_lock_fetcher.rb', line 46

def valid?
  errors.empty?
end