Class: Chef::Provider::HttpRequest

Inherits:
Chef::Provider show all
Defined in:
lib/chef/provider/http_request.rb

Instance Attribute Summary collapse

Attributes inherited from Chef::Provider

#action, #current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Chef::Provider

#action_nothing, #cleanup_after_converge, #cookbook_name, #define_resource_requirements, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?

Methods included from DSL::Recipe

#method_missing

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::DSL::Recipe

Instance Attribute Details

#restObject

Returns the value of attribute rest.



25
26
27
# File 'lib/chef/provider/http_request.rb', line 25

def rest
  @rest
end

Instance Method Details

#action_deleteObject

Send a DELETE request to @new_resource.url



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/chef/provider/http_request.rb', line 95

def action_delete
  converge_by("#{@new_resource} DELETE to #{@new_resource.url}") do
    body = @rest.delete(
      "#{@new_resource.url}",
      @new_resource.headers
    )
    @new_resource.updated_by_last_action(true)
    Chef::Log.info("#{@new_resource} DELETE to #{@new_resource.url} successful")
    Chef::Log.debug("#{@new_resource} DELETE request response: #{body}")
  end
end

#action_getObject

Send a GET request to @new_resource.url, with ?message=@new_resource.message



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/provider/http_request.rb', line 52

def action_get
  converge_by("#{@new_resource} GET to #{@new_resource.url}") do

    message = check_message(@new_resource.message)
    body = @rest.get(
      "#{@new_resource.url}?message=#{message}",
      false,
      @new_resource.headers
    )
    Chef::Log.info("#{@new_resource} GET to #{@new_resource.url} successful")
    Chef::Log.debug("#{@new_resource} GET request response: #{body}")
  end
end

#action_headObject

Send a HEAD request to @new_resource.url, with ?message=@new_resource.message



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chef/provider/http_request.rb', line 36

def action_head
  message = check_message(@new_resource.message)
  # returns true from Chef::REST if returns 2XX (Net::HTTPSuccess)
  modified = @rest.head(
    "#{@new_resource.url}?message=#{message}",
    @new_resource.headers
  )
  Chef::Log.info("#{@new_resource} HEAD to #{@new_resource.url} successful")
  Chef::Log.debug("#{@new_resource} HEAD request response: #{modified}")
  # :head is usually used to trigger notifications, which converge_by now does
  if modified
    converge_by("#{@new_resource} HEAD to #{@new_resource.url} returned modified, trigger notifications") {}
  end
end

#action_postObject

Send a POST request to @new_resource.url, with the message as the payload



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/chef/provider/http_request.rb', line 81

def action_post
  converge_by("#{@new_resource} POST to #{@new_resource.url}") do
    message = check_message(@new_resource.message)
    body = @rest.post(
      "#{@new_resource.url}",
      message,
      @new_resource.headers
    )
    Chef::Log.info("#{@new_resource} POST to #{@new_resource.url} message: #{message.inspect} successful")
    Chef::Log.debug("#{@new_resource} POST request response: #{body}")
  end
end

#action_putObject

Send a PUT request to @new_resource.url, with the message as the payload



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/chef/provider/http_request.rb', line 67

def action_put
  converge_by("#{@new_resource} PUT to #{@new_resource.url}") do
    message = check_message(@new_resource.message)
    body = @rest.put(
      "#{@new_resource.url}",
      message,
      @new_resource.headers
    )
    Chef::Log.info("#{@new_resource} PUT to #{@new_resource.url} successful")
    Chef::Log.debug("#{@new_resource} PUT request response: #{body}")
  end
end

#load_current_resourceObject



31
32
33
# File 'lib/chef/provider/http_request.rb', line 31

def load_current_resource
  @rest = Chef::REST.new(@new_resource.url, nil, nil)
end

#whyrun_supported?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/chef/provider/http_request.rb', line 27

def whyrun_supported?
  true
end