Module: Chef::Mixin::GenerateURL

Included in:
Client, Provider::File
Defined in:
lib/chef/mixin/generate_url.rb

Instance Method Summary collapse

Instance Method Details

#generate_cookbook_url(url, cookbook, type, node, args = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef/mixin/generate_url.rb', line 25

def generate_cookbook_url(url, cookbook, type, node, args=nil)
  Chef::Log.debug("generating cookbook url for url=#{url}, cookbook=#{cookbook.inspect}, type=#{type}, node=#{node}")
  new_url = nil
  if url =~ /^(http|https):\/\//
    new_url = url
  else
    new_url = "cookbooks/#{cookbook}/#{type}?"
    new_url += "id=#{url}"
    new_url = generate_cookbook_url_from_uri(new_url, node, args)
  end
  Chef::Log.debug("generated cookbook url: #{new_url}")
  return new_url
end

#generate_cookbook_url_from_uri(uri, node, args = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/mixin/generate_url.rb', line 39

def generate_cookbook_url_from_uri(uri, node, args=nil)
  platform, version = Chef::Platform.find_platform_and_version(node)
  uri =~ /cookbooks\/(.+?)\/(.+)\?/
  cookbook = $1
  type = $2
  if type == "files" || type == "templates"
    uri += "&platform=#{platform}&version=#{version}&fqdn=#{node[:fqdn]}&node_name=#{node.name}"
  end
  if args
    args.each do |key, value|
      uri += "&#{key}=#{value}"
    end
  end

  uri
end