Skip to content

Commit 76397bf

Browse files
committed
Merge remote-tracking branch 'upstream/pr/3230'
* upstream/pr/3230: (PUP-3370) Remove serialization support from indirector request
2 parents e481f76 + ac182a8 commit 76397bf

File tree

2 files changed

+0
-138
lines changed

2 files changed

+0
-138
lines changed

lib/puppet/indirector/request.rb

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
# Indirection call, and as a result also handles REST calls. It's somewhat
88
# analogous to an HTTP Request object, except tuned for our Indirector.
99
class Puppet::Indirector::Request
10-
# FormatSupport for serialization methods
11-
include Puppet::Network::FormatSupport
1210

1311
attr_accessor :key, :method, :options, :instance, :node, :ip, :authenticated, :ignore_cache, :ignore_terminus
1412

@@ -20,51 +18,6 @@ class Puppet::Indirector::Request
2018
# and keep it "trusted"
2119
OPTION_ATTRIBUTES = [:ip, :node, :authenticated, :ignore_terminus, :ignore_cache, :instance, :environment]
2220

23-
def self.from_data_hash(data)
24-
raise ArgumentError, "No indirection name provided in data" unless indirection_name = data['type']
25-
raise ArgumentError, "No method name provided in data" unless method = data['method']
26-
raise ArgumentError, "No key provided in data" unless key = data['key']
27-
28-
request = new(indirection_name, method, key, nil, data['attributes'])
29-
30-
if instance = data['instance']
31-
klass = Puppet::Indirector::Indirection.instance(request.indirection_name).model
32-
if instance.is_a?(klass)
33-
request.instance = instance
34-
else
35-
request.instance = klass.from_data_hash(instance)
36-
end
37-
end
38-
39-
request
40-
end
41-
42-
def self.from_pson(json)
43-
Puppet.deprecation_warning("from_pson is being removed in favour of from_data_hash.")
44-
self.from_data_hash(json)
45-
end
46-
47-
def to_data_hash
48-
result = {
49-
'type' => indirection_name,
50-
'method' => method,
51-
'key' => key
52-
}
53-
attributes = {}
54-
OPTION_ATTRIBUTES.each do |key|
55-
next unless value = send(key)
56-
attributes[key] = value
57-
end
58-
59-
options.each do |opt, value|
60-
attributes[opt] = value
61-
end
62-
63-
result['attributes'] = attributes unless attributes.empty?
64-
result['instance'] = instance if instance
65-
result
66-
end
67-
6821
# Is this an authenticated request?
6922
def authenticated?
7023
# Double negative, so we just get true or false

spec/unit/indirector/request_spec.rb

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -377,97 +377,6 @@ def the_parsed_query_string_from(request)
377377
end
378378
end
379379

380-
describe "when converting to json" do
381-
before do
382-
@request = Puppet::Indirector::Request.new(:facts, :find, "foo", nil)
383-
end
384-
385-
it "should set the 'key'" do
386-
@request.should set_json_attribute("key").to("foo")
387-
end
388-
389-
it "should include an attribute for its indirection name" do
390-
@request.should set_json_attribute("type").to("facts")
391-
end
392-
393-
it "should include a 'method' attribute set to its method" do
394-
@request.should set_json_attribute("method").to("find")
395-
end
396-
397-
it "should add all attributes under the 'attributes' attribute" do
398-
@request.ip = "127.0.0.1"
399-
@request.should set_json_attribute("attributes", "ip").to("127.0.0.1")
400-
end
401-
402-
it "should add all options under the 'attributes' attribute" do
403-
@request.options["opt"] = "value"
404-
PSON.parse(@request.to_pson)['attributes']['opt'].should == "value"
405-
end
406-
407-
it "should include the instance if provided" do
408-
facts = Puppet::Node::Facts.new("foo")
409-
@request.instance = facts
410-
PSON.parse(@request.to_pson)['instance'].should be_instance_of(Hash)
411-
end
412-
end
413-
414-
describe "when converting from json" do
415-
before do
416-
@request = Puppet::Indirector::Request.new(:facts, :find, "foo", nil)
417-
@klass = Puppet::Indirector::Request
418-
@format = Puppet::Network::FormatHandler.format('pson')
419-
end
420-
421-
def from_json(json)
422-
@format.intern(Puppet::Indirector::Request, json)
423-
end
424-
425-
it "should set the 'key'" do
426-
from_json(@request.to_pson).key.should == "foo"
427-
end
428-
429-
it "should fail if no key is provided" do
430-
json = PSON.parse(@request.to_pson)
431-
json.delete("key")
432-
expect { from_json(json.to_pson) }.to raise_error(ArgumentError)
433-
end
434-
435-
it "should set its indirector name" do
436-
from_json(@request.to_pson).indirection_name.should == :facts
437-
end
438-
439-
it "should fail if no type is provided" do
440-
json = PSON.parse(@request.to_pson)
441-
json.delete("type")
442-
expect { from_json(json.to_pson) }.to raise_error(ArgumentError)
443-
end
444-
445-
it "should set its method" do
446-
from_json(@request.to_pson).method.should == "find"
447-
end
448-
449-
it "should fail if no method is provided" do
450-
json = PSON.parse(@request.to_pson)
451-
json.delete("method")
452-
expect { from_json(json.to_pson) }.to raise_error(ArgumentError)
453-
end
454-
455-
it "should initialize with all attributes and options" do
456-
@request.ip = "127.0.0.1"
457-
@request.options["opt"] = "value"
458-
result = from_json(@request.to_pson)
459-
result.options[:opt].should == "value"
460-
result.ip.should == "127.0.0.1"
461-
end
462-
463-
it "should set its instance as an instance if one is provided" do
464-
facts = Puppet::Node::Facts.new("foo")
465-
@request.instance = facts
466-
result = from_json(@request.to_pson)
467-
result.instance.should be_instance_of(Puppet::Node::Facts)
468-
end
469-
end
470-
471380
context '#do_request' do
472381
before :each do
473382
@request = Puppet::Indirector::Request.new(:myind, :find, "my key", nil)

0 commit comments

Comments
 (0)