class ChefCLI::Policyfile::GitLockFetcher

def lock_data

Returns:
  • (Hash) - of the policyfile lock data
def lock_data
  @lock_data ||= fetch_lock_data.tap do |data|
    data["cookbook_locks"].each do |cookbook_name, cookbook_lock|
      if cookbook_lock["source_options"].key?("path")
        cookbook_lock["source_options"].tap do |opt|
          opt["git"]      = uri unless opt.key?("git")
          opt["revision"] = revision unless opt.key?("revision")
          opt["branch"]   = branch unless opt.key?("branch") || branch.nil?
          opt["tag"]      = tag unless opt.key?("tag") || branch.nil?
          opt["ref"]      = ref unless opt.key?("ref") || ref.nil?
          path_keys = %w{path rel}.map { |path_key| path_key if opt.key?(path_key) }.compact
          path_keys.each do |name|
            # We can safely grab the entire cookbook when the Policyfile defines a cookbook path of itself (".")
            if opt[name] == "."
              opt.delete(name)
              next
            end
            # Mutate the path key to a rel key so that we identify the source_type
            # as a git repo and not a local directory. Git also doesn't like paths
            # prefixed with `./` and cannot use relative paths outside the repo.
            # http://rubular.com/r/JYpdYHT19p
            pattern = %r{(^../)|(^./)}
            opt["rel"] = opt[name].gsub(pattern, "")
          end
          # Delete the path key if present to ensure we use the git source_type
          opt.delete("path")
        end
      end # cookbook_lock["source_options"]
    end # data["cookbook_locks"].each
  end # fetch_lock_data.tap
  @lock_data
end