summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Broadhead <james.broadhead@mongodb.com>2017-05-08 13:56:34 -0400
committerJames Broadhead <james.broadhead@mongodb.com>2017-05-08 13:59:31 -0400
commit788bbff36108a6952da19538150e685ae45694d1 (patch)
tree8086d52c8a7942431d7a35c0356eb8219f9e6299
parent0ad389f48d43ebfc4347c41a3573ee855993c5f1 (diff)
downloadchef-788bbff36108a6952da19538150e685ae45694d1.tar.gz
Add support for HTTP PATCH requests
Signed-off-by: James Broadhead <james.broadhead@mongodb.com>
-rw-r--r--lib/chef/http/http_request.rb3
-rw-r--r--lib/chef/provider/http_request.rb14
-rw-r--r--lib/chef/resource/http_request.rb2
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb
index 20c46aaa8d..7fc1acb889 100644
--- a/lib/chef/http/http_request.rb
+++ b/lib/chef/http/http_request.rb
@@ -49,6 +49,7 @@ class Chef
ENCODING_GZIP_DEFLATE = "gzip;q=1.0,deflate;q=0.6,identity;q=0.3".freeze
GET = "get".freeze
+ PATCH = "patch".freeze
PUT = "put".freeze
POST = "post".freeze
DELETE = "delete".freeze
@@ -161,6 +162,8 @@ class Chef
Net::HTTP::Post.new(req_path, headers)
when PUT
Net::HTTP::Put.new(req_path, headers)
+ when PATCH
+ Net::HTTP::Patch.new(req_path, headers)
when DELETE
Net::HTTP::Delete.new(req_path, headers)
when HEAD
diff --git a/lib/chef/provider/http_request.rb b/lib/chef/provider/http_request.rb
index 8370c2375c..cafdc1e007 100644
--- a/lib/chef/provider/http_request.rb
+++ b/lib/chef/provider/http_request.rb
@@ -62,6 +62,20 @@ class Chef
end
end
+ # Send a PATCH request to new_resource.url, with the message as the payload
+ def action_patch
+ converge_by("#{new_resource} PATCH to #{new_resource.url}") do
+ message = check_message(new_resource.message)
+ body = @http.patch(
+ "#{new_resource.url}",
+ message,
+ new_resource.headers
+ )
+ Chef::Log.info("#{new_resource} PATCH to #{new_resource.url} successful")
+ Chef::Log.debug("#{new_resource} PATCH request response: #{body}")
+ end
+ end
+
# Send a PUT request to new_resource.url, with the message as the payload
def action_put
converge_by("#{new_resource} PUT to #{new_resource.url}") do
diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb
index fcc48470bc..9fac3562f3 100644
--- a/lib/chef/resource/http_request.rb
+++ b/lib/chef/resource/http_request.rb
@@ -27,7 +27,7 @@ class Chef
identity_attr :url
default_action :get
- allowed_actions :get, :put, :post, :delete, :head, :options
+ allowed_actions :get, :patch, :put, :post, :delete, :head, :options
def initialize(name, run_context = nil)
super