class ChefCLI::Policyfile::LockApplier

A class that can apply constraints from a lock to a compiler

def apply!

Other tags:
    Note: - No changes are applied until apply! is invoked
def apply!
  prepare_constraints_for_policies
end

def initialize(policyfile_lock, policyfile_compiler)

Parameters:
  • policyfile_compiler (PolicyfileCompiler) -- the compiler to apply the locked data
  • policyfile_lock (PolicyfileLock) -- contains the locked data to use
def initialize(policyfile_lock, policyfile_compiler)
  @policyfile_lock = policyfile_lock
  @policyfile_compiler = policyfile_compiler
  @unlocked_policies = []
end

def prepare_constraints_for_policies

def prepare_constraints_for_policies
  if unlocked_policies == :all
    return
  end
  policyfile_compiler.included_policies.each do |policy|
    unless unlocked_policies.include?(policy.name)
      lock = policyfile_lock.included_policy_locks.find do |policy_lock|
        policy_lock["name"] == policy.name
      end
      policy.apply_locked_source_options(lock["source_options"])
    end
  end
end

def with_unlocked_policies(policies)

Parameters:
  • policies (Array) -- Unconstrain a specific policy by name
  • policies (:all) -- Unconstrain all policies
def with_unlocked_policies(policies)
  if policies == :all || unlocked_policies == :all
    @unlocked_policies = :all
  else
    policies.each do |policy|
      @unlocked_policies << policy
    end
  end
  self
end