Class: Puppet::Indirector::REST
Overview
Direct Known Subclasses
FileBucketFile::Rest, CertificateStatus::Rest, FileContent::Rest, FileMetadata::Rest, Puppet::Indirector::ResourceType::Rest, Status::Rest, Node::Rest, Resource::Catalog::Rest, SSL::Certificate::Rest, SSL::CertificateRequest::Rest, SSL::CertificateRevocationList::Rest, Transaction::Report::Rest
Constant Summary
collapse
- IndirectedRoutes =
Puppet::Network::HTTP::API::IndirectedRoutes
Constants included
from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included
from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Constants included
from Util::Docs
Util::Docs::HEADER_LEVELS
Class Attribute Summary collapse
Attributes included from Util::Docs
#doc, #nodoc
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_profiling_header(headers) ⇒ Object
-
#destroy(request) ⇒ Object
-
#do_request(request) ⇒ Object
Encapsulate call to request.do_request with the arguments from this class Then yield to the code block that was called in We certainly could have retained the full request.do_request(…) { |r| … } but this makes the code much cleaner and we only then actually make the call to request.do_request from here, thus if we change what we pass or how we get it, we only need to change it here.
-
#find(request) ⇒ Object
-
#head(request) ⇒ Object
-
#headers ⇒ Object
Provide appropriate headers.
-
#http_delete(request, path, headers = nil, *args) ⇒ Object
-
#http_get(request, path, headers = nil, *args) ⇒ Object
-
#http_head(request, path, headers = nil, *args) ⇒ Object
-
#http_post(request, path, data, headers = nil, *args) ⇒ Object
-
#http_put(request, path, data, headers = nil, *args) ⇒ Object
-
#http_request(method, request, *args) ⇒ Object
-
#network(request) ⇒ Object
-
#save(request) ⇒ Object
-
#search(request) ⇒ Object
-
#validate_key(request) ⇒ Object
Methods inherited from Terminus
abstract_terminus?, #allow_remote_requests?, const2name, #indirection, indirection_name, inherited, #initialize, mark_as_abstract_terminus, model, #model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type, #validate, #validate_model
#instance_docs, #instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances
Methods included from Util
absolute_path?, benchmark, chuser, deterministic_rand, deterministic_rand_int, exit_on_fail, logmethods, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, symbolizehash, thinmark, uri_to_path, which, withenv, withumask
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Class Attribute Details
.port_setting ⇒ Object
14
15
16
|
# File 'lib/puppet/indirector/rest.rb', line 14
def port_setting
@port_setting
end
|
.server_setting ⇒ Object
14
15
16
|
# File 'lib/puppet/indirector/rest.rb', line 14
def server_setting
@server_setting
end
|
Class Method Details
40
41
42
|
# File 'lib/puppet/indirector/rest.rb', line 40
def self.port
Puppet.settings[port_setting || :masterport].to_i
end
|
36
37
38
|
# File 'lib/puppet/indirector/rest.rb', line 36
def self.server
Puppet.settings[server_setting || :server]
end
|
.srv_service ⇒ Object
32
33
34
|
# File 'lib/puppet/indirector/rest.rb', line 32
def self.srv_service
@srv_service || :puppet
end
|
.use_port_setting(setting) ⇒ Object
Specify the setting that we should use to get the port.
23
24
25
|
# File 'lib/puppet/indirector/rest.rb', line 23
def self.use_port_setting(setting)
@port_setting = setting
end
|
.use_server_setting(setting) ⇒ Object
Specify the setting that we should use to get the server name.
18
19
20
|
# File 'lib/puppet/indirector/rest.rb', line 18
def self.use_server_setting(setting)
@server_setting = setting
end
|
.use_srv_service(service) ⇒ Object
Specify the service to use when doing SRV record lookup
28
29
30
|
# File 'lib/puppet/indirector/rest.rb', line 28
def self.use_srv_service(service)
@srv_service = service
end
|
Instance Method Details
#destroy(request) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/puppet/indirector/rest.rb', line 153
def destroy(request)
raise ArgumentError, "DELETE does not accept options" unless request.options.empty?
response = do_request(request) do |req|
http_delete(req, IndirectedRoutes.request_to_uri(req), )
end
if is_http_200?(response)
content_type, body = parse_response(response)
deserialize_destroy(content_type, body)
else
nil
end
end
|
#do_request(request) ⇒ Object
Encapsulate call to request.do_request with the arguments from this class Then yield to the code block that was called in We certainly could have retained the full request.do_request(…) { |r| … } but this makes the code much cleaner and we only then actually make the call to request.do_request from here, thus if we change what we pass or how we get it, we only need to change it here.
189
190
191
|
# File 'lib/puppet/indirector/rest.rb', line 189
def do_request(request)
request.do_request(self.class.srv_service, self.class.server, self.class.port) { |req| yield(req) }
end
|
#find(request) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/puppet/indirector/rest.rb', line 91
def find(request)
uri, body = IndirectedRoutes.request_to_uri_and_body(request)
uri_with_query_string = "#{uri}?#{body}"
response = do_request(request) do |req|
if "GET #{uri_with_query_string} HTTP/1.1\r\n".length > 1024
http_post(req, uri, body, )
else
http_get(req, uri_with_query_string, )
end
end
if is_http_200?(response)
content_type, body = parse_response(response)
result = deserialize_find(content_type, body)
result.name = request.key if result.respond_to?(:name=)
result
elsif is_http_404?(response)
return nil unless request.options[:fail_on_404]
content_type, body = parse_response(response)
msg = "Find #{elide(uri_with_query_string, 100)} resulted in 404 with the message: #{body}"
raise Puppet::Error, msg
else
nil
end
end
|
#head(request) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/puppet/indirector/rest.rb', line 128
def head(request)
response = do_request(request) do |req|
http_head(req, IndirectedRoutes.request_to_uri(req), )
end
if is_http_200?(response)
true
else
false
end
end
|
Provide appropriate headers.
#http_delete(request, path, headers = nil, *args) ⇒ Object
78
79
80
|
# File 'lib/puppet/indirector/rest.rb', line 78
def http_delete(request, path, = nil, *args)
http_request(:delete, request, path, (), *args)
end
|
#http_get(request, path, headers = nil, *args) ⇒ Object
66
67
68
|
# File 'lib/puppet/indirector/rest.rb', line 66
def http_get(request, path, = nil, *args)
http_request(:get, request, path, (), *args)
end
|
#http_head(request, path, headers = nil, *args) ⇒ Object
74
75
76
|
# File 'lib/puppet/indirector/rest.rb', line 74
def http_head(request, path, = nil, *args)
http_request(:head, request, path, (), *args)
end
|
#http_post(request, path, data, headers = nil, *args) ⇒ Object
70
71
72
|
# File 'lib/puppet/indirector/rest.rb', line 70
def http_post(request, path, data, = nil, *args)
http_request(:post, request, path, data, (), *args)
end
|
#http_put(request, path, data, headers = nil, *args) ⇒ Object
82
83
84
|
# File 'lib/puppet/indirector/rest.rb', line 82
def http_put(request, path, data, = nil, *args)
http_request(:put, request, path, data, (), *args)
end
|
#http_request(method, request, *args) ⇒ Object
86
87
88
89
|
# File 'lib/puppet/indirector/rest.rb', line 86
def http_request(method, request, *args)
conn = network(request)
conn.send(method, *args)
end
|
#network(request) ⇒ Object
61
62
63
64
|
# File 'lib/puppet/indirector/rest.rb', line 61
def network(request)
Puppet::Network::HttpPool.http_instance(request.server || self.class.server,
request.port || self.class.port)
end
|
#save(request) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/puppet/indirector/rest.rb', line 168
def save(request)
raise ArgumentError, "PUT does not accept options" unless request.options.empty?
response = do_request(request) do |req|
http_put(req, IndirectedRoutes.request_to_uri(req), req.instance.render, .merge({ "Content-Type" => req.instance.mime }))
end
if is_http_200?(response)
content_type, body = parse_response(response)
deserialize_save(content_type, body)
else
nil
end
end
|
#search(request) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/puppet/indirector/rest.rb', line 140
def search(request)
response = do_request(request) do |req|
http_get(req, IndirectedRoutes.request_to_uri(req), )
end
if is_http_200?(response)
content_type, body = parse_response(response)
deserialize_search(content_type, body) || []
else
[]
end
end
|
#validate_key(request) ⇒ Object
193
194
195
|
# File 'lib/puppet/indirector/rest.rb', line 193
def validate_key(request)
end
|