class Chef::Resource::ChocolateySource

Public Instance Methods

choco_cmd(action) click to toggle source

@param [String] action the name of the action to perform @return [String] the choco source command string

# File lib/chef/resource/chocolatey_source.rb, line 146
def choco_cmd(action)
  cmd = "#{ENV["ALLUSERSPROFILE"]}\\chocolatey\\bin\\choco source #{action} -n \"#{new_resource.source_name}\""
  if action == "add"
    cmd << " --source=\"#{new_resource.source}\" --priority=#{new_resource.priority}"
    cmd << " --bypassproxy" if new_resource.bypass_proxy
    cmd << " --allowselfservice" if new_resource.allow_self_service
    cmd << " --adminonly" if new_resource.admin_only
    cmd << " --user=\"#{new_resource.username}\"" if new_resource.username
    cmd << " --password=\"#{new_resource.password}\"" if new_resource.password
    cmd << " --cert=\"#{new_resource.cert}\"" if new_resource.cert
    cmd << " --certpassword=\"#{new_resource.cert_password}\"" if new_resource.cert_password
  end
  cmd
end
fetch_source_element(id) click to toggle source

@param [String] id the source name @return [REXML::Attributes] finds the source element with the

# File lib/chef/resource/chocolatey_source.rb, line 98
def fetch_source_element(id)
  require "rexml/document" unless defined?(REXML::Document)

  config_file = "#{ENV["ALLUSERSPROFILE"]}\\chocolatey\\config\\chocolatey.config"
  raise "Could not find the Chocolatey config at #{config_file}!" unless ::File.exist?(config_file)

  config_contents = REXML::Document.new(::File.read(config_file))
  data = REXML::XPath.first(config_contents, "//sources/source[@id=\"#{id}\"]")
  data ? data.attributes : nil # REXML just returns nil if it can't find anything so avoid an undefined method error
end