rhcp 0.2.21 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rhcp.rb +2 -1
- data/lib/rhcp/client/context_aware_broker.rb +9 -2
- data/lib/rhcp/command.rb +15 -6
- data/lib/rhcp/encoding_helper.rb +46 -0
- data/lib/rhcp/request.rb +15 -5
- data/lib/rhcp/response.rb +16 -1
- metadata +56 -73
data/lib/rhcp.rb
CHANGED
@@ -23,7 +23,7 @@ module RHCP #:nodoc:
|
|
23
23
|
|
24
24
|
MAJOR = 0
|
25
25
|
MINOR = 2
|
26
|
-
TINY =
|
26
|
+
TINY = 22
|
27
27
|
|
28
28
|
def Version.to_s
|
29
29
|
[ MAJOR, MINOR, TINY ].join(".")
|
@@ -41,6 +41,7 @@ module RHCP #:nodoc:
|
|
41
41
|
# TODO do we really want to log to STDOUT per default?
|
42
42
|
# TODO check the whole package for correct usage of loggers
|
43
43
|
@logger = Logger.new(STDOUT)
|
44
|
+
@logger.level = Logger::INFO
|
44
45
|
end
|
45
46
|
|
46
47
|
|
@@ -45,13 +45,19 @@ module RHCP
|
|
45
45
|
response = @wrapped_broker.execute(new_request)
|
46
46
|
|
47
47
|
# store context received with response
|
48
|
-
if response.context
|
49
|
-
# TODO it would be nice if we could delete cookies as well
|
48
|
+
if response.context
|
50
49
|
response.context.each do |key,value|
|
51
50
|
@context.cookies[key] = value
|
52
51
|
$logger.debug "storing value '#{value}' for key '#{key}' in context"
|
53
52
|
end
|
54
53
|
end
|
54
|
+
|
55
|
+
if response.anti_context
|
56
|
+
response.anti_context.each do |key|
|
57
|
+
@context.cookies.delete(key)
|
58
|
+
$logger.info "deleted cookie '#{key}'"
|
59
|
+
end
|
60
|
+
end
|
55
61
|
|
56
62
|
response
|
57
63
|
end
|
@@ -67,6 +73,7 @@ module RHCP
|
|
67
73
|
|
68
74
|
def get_lookup_values(request, param_name)
|
69
75
|
request_with_context = give_the_request_some_context_rico(request)
|
76
|
+
request_with_context.context.cookies["phase"] = "lookup"
|
70
77
|
@wrapped_broker.get_lookup_values(request_with_context, param_name)
|
71
78
|
end
|
72
79
|
|
data/lib/rhcp/command.rb
CHANGED
@@ -188,7 +188,7 @@ module RHCP
|
|
188
188
|
end
|
189
189
|
|
190
190
|
begin
|
191
|
-
# TODO redirect the block's output (both Logger and STDOUT/STDERR) and send it back with the response
|
191
|
+
# TODO redirect the block's output (both Logger and STDOUT/STDERR) and send it back with the response?
|
192
192
|
result = block.call(request, response)
|
193
193
|
response.set_payload(result)
|
194
194
|
rescue Exception => ex
|
@@ -219,12 +219,21 @@ module RHCP
|
|
219
219
|
param_values["block"] = block
|
220
220
|
end
|
221
221
|
|
222
|
+
param_values.merge! additional_params
|
223
|
+
|
222
224
|
# we need to carry along the context
|
223
|
-
|
225
|
+
c = RHCP::Context.new()
|
224
226
|
|
225
|
-
|
227
|
+
the_broker = Thread.current['broker']
|
228
|
+
the_broker.context.cookies.each do |k,v|
|
229
|
+
c.cookies[k] = v
|
230
|
+
end
|
231
|
+
#c.cookies.merge! additional_params
|
226
232
|
|
227
|
-
request = RHCP::Request.new(self, param_values,
|
233
|
+
request = RHCP::Request.new(self, param_values, c)
|
234
|
+
#puts ""
|
235
|
+
#puts "gonna execute #{request}"
|
236
|
+
#pp c.cookies
|
228
237
|
response = the_broker.execute(request)
|
229
238
|
|
230
239
|
if (response.status != RHCP::Response::Status::OK) then
|
@@ -250,8 +259,8 @@ module RHCP
|
|
250
259
|
end
|
251
260
|
|
252
261
|
|
253
|
-
# we do not serialize the block
|
254
|
-
# when the command is unmarshalled
|
262
|
+
# we do not serialize the block nor the default param
|
263
|
+
# when the command is unmarshalled, the default param will be set again
|
255
264
|
# automatically by add_param(), and the block will be replaced by the block
|
256
265
|
# that does the remote invocation
|
257
266
|
def to_json(*args)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module RHCP
|
4
|
+
|
5
|
+
module EncodingHelper
|
6
|
+
|
7
|
+
def self.change_string_values(thing, &block)
|
8
|
+
result = nil
|
9
|
+
case thing.class.to_s
|
10
|
+
when "Array"
|
11
|
+
result = []
|
12
|
+
thing.each do |t|
|
13
|
+
result << change_string_values(t, &block)
|
14
|
+
end
|
15
|
+
when "Hash"
|
16
|
+
result = {}
|
17
|
+
thing.each do |k,v|
|
18
|
+
result[k] = change_string_values(v, &block)
|
19
|
+
end
|
20
|
+
#when "String","Fixnum","Boolean","TrueClass","FalseClass"
|
21
|
+
when "String"
|
22
|
+
result = block.call(thing.to_s)
|
23
|
+
when "Fixnum","TrueClass","FalseClass"
|
24
|
+
result = thing
|
25
|
+
when "Proc","NilClass","Binding"
|
26
|
+
# ignore
|
27
|
+
else
|
28
|
+
$logger.debug("don't know how to encode #{thing.class} - skipping")
|
29
|
+
end
|
30
|
+
result
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.to_base64(thing)
|
34
|
+
change_string_values(thing) do |x|
|
35
|
+
Base64.encode64(x)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.from_base64(thing)
|
40
|
+
change_string_values(thing) do |x|
|
41
|
+
Base64.decode64(x)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/rhcp/request.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rhcp/rhcp_exception'
|
2
2
|
require 'rhcp/broker'
|
3
3
|
|
4
|
+
require 'rhcp/encoding_helper'
|
5
|
+
|
4
6
|
require 'rubygems'
|
5
7
|
require 'json'
|
6
8
|
|
@@ -37,7 +39,7 @@ module RHCP
|
|
37
39
|
end
|
38
40
|
|
39
41
|
# fill params with default values
|
40
|
-
if ! param_values.has_key?(param.name)
|
42
|
+
if ! param_values.has_key?(param.name) && param.default_value != nil
|
41
43
|
if param.default_value.class == Proc
|
42
44
|
param_values[param.name] = param.default_value.call(param_values)
|
43
45
|
else
|
@@ -66,7 +68,7 @@ module RHCP
|
|
66
68
|
@param_values = param_values
|
67
69
|
|
68
70
|
printable_param_values = param_values.map do |a,b|
|
69
|
-
a + '=' + b.join(',')
|
71
|
+
a.to_s + '=' + b.join(',')
|
70
72
|
end.join('; ')
|
71
73
|
@logger.debug("request initialized : command '#{command.name}', params : #{printable_param_values}")
|
72
74
|
end
|
@@ -101,16 +103,24 @@ module RHCP
|
|
101
103
|
def execute
|
102
104
|
@command.execute_request(self)
|
103
105
|
end
|
106
|
+
|
107
|
+
def base64_param_values
|
108
|
+
result = {}
|
109
|
+
@param_values.each do |k,v|
|
110
|
+
result[k] = EncodingHelper.to_base64(v)
|
111
|
+
end
|
112
|
+
result
|
113
|
+
end
|
104
114
|
|
105
115
|
def as_json(options={})
|
106
116
|
{
|
107
117
|
:command_name => @command.full_name,
|
108
|
-
:param_values =>
|
118
|
+
:param_values => base64_param_values(),
|
109
119
|
:context => @context.as_json(),
|
110
120
|
:request_count => @request_count
|
111
121
|
}
|
112
122
|
end
|
113
|
-
|
123
|
+
|
114
124
|
def to_s
|
115
125
|
s = @command.name + ' ('
|
116
126
|
count = 0
|
@@ -126,4 +136,4 @@ module RHCP
|
|
126
136
|
|
127
137
|
end
|
128
138
|
|
129
|
-
end
|
139
|
+
end
|
data/lib/rhcp/response.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
+
require 'rhcp/encoding_helper'
|
5
|
+
|
4
6
|
module RHCP
|
5
7
|
|
6
8
|
class Response
|
@@ -15,8 +17,9 @@ module RHCP
|
|
15
17
|
attr_accessor :error_text
|
16
18
|
attr_accessor :error_detail
|
17
19
|
attr_accessor :data
|
18
|
-
# TODO this should be called 'cookies'
|
20
|
+
# TODO this should be called 'cookies' maybe
|
19
21
|
attr_accessor :context
|
22
|
+
attr_accessor :anti_context
|
20
23
|
|
21
24
|
# textual description of the result (optional)
|
22
25
|
attr_accessor :result_text
|
@@ -28,6 +31,7 @@ module RHCP
|
|
28
31
|
@error_detail = ""
|
29
32
|
@result_text = ""
|
30
33
|
@context = nil
|
34
|
+
@anti_context = []
|
31
35
|
@created_at = Time.now().to_i
|
32
36
|
end
|
33
37
|
|
@@ -45,7 +49,12 @@ module RHCP
|
|
45
49
|
@context = new_context
|
46
50
|
end
|
47
51
|
|
52
|
+
def delete_cookie(key)
|
53
|
+
@anti_context << key
|
54
|
+
end
|
55
|
+
|
48
56
|
def as_json(options = {})
|
57
|
+
begin
|
49
58
|
{
|
50
59
|
:status => @status,
|
51
60
|
:error_text => @error_text,
|
@@ -53,9 +62,15 @@ module RHCP
|
|
53
62
|
:data => @data, # TODO what about JSONinification of data? (probably data should be JSON-ish data only, i.e. no special objects)
|
54
63
|
:result_text => @result_text,
|
55
64
|
:context => @context,
|
65
|
+
:anti_context => @anti_context,
|
56
66
|
:created_at => @created_at,
|
57
67
|
:created_at_iso8601 => Time.at(@created_at).iso8601(),
|
58
68
|
}
|
69
|
+
rescue => detail
|
70
|
+
$logger.warn("could not convert response to JSON : #{detail.message}\ncreated at: #{@created_at}")
|
71
|
+
puts @created_at.pretty_inspect
|
72
|
+
raise
|
73
|
+
end
|
59
74
|
end
|
60
75
|
|
61
76
|
end
|
metadata
CHANGED
@@ -1,112 +1,95 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhcp
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.22
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 21
|
10
|
-
version: 0.2.21
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Philipp T.
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-10-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: json
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 31
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 0
|
32
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 0.0.0
|
34
22
|
type: :runtime
|
35
|
-
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.0
|
30
|
+
description: really helpful command protocol
|
37
31
|
email: philipp at virtualop dot org
|
38
|
-
executables:
|
32
|
+
executables:
|
39
33
|
- rhcp_test_server
|
40
34
|
extensions: []
|
41
|
-
|
42
35
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
36
|
+
files:
|
45
37
|
- bin/rhcp_test_server
|
46
|
-
- lib/rhcp.rb
|
47
|
-
- lib/rhcp/http_exporter.rb
|
48
|
-
- lib/rhcp/request.rb
|
49
|
-
- lib/rhcp/rhcp_exception.rb
|
50
|
-
- lib/rhcp/logging_broker.rb
|
51
38
|
- lib/rhcp/dispatching_broker.rb
|
52
|
-
- lib/rhcp/
|
53
|
-
- lib/rhcp/
|
54
|
-
- lib/rhcp/client/http_broker.rb
|
39
|
+
- lib/rhcp/context.rb
|
40
|
+
- lib/rhcp/encoding_helper.rb
|
55
41
|
- lib/rhcp/client/context_aware_broker.rb
|
56
42
|
- lib/rhcp/client/command_stub.rb
|
57
43
|
- lib/rhcp/client/command_param_stub.rb
|
58
|
-
- lib/rhcp/
|
44
|
+
- lib/rhcp/client/http_broker.rb
|
45
|
+
- lib/rhcp/response.rb
|
46
|
+
- lib/rhcp/rhcp_exception.rb
|
47
|
+
- lib/rhcp/command.rb
|
48
|
+
- lib/rhcp/request.rb
|
59
49
|
- lib/rhcp/command_param.rb
|
60
|
-
- lib/rhcp/
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
50
|
+
- lib/rhcp/broker.rb
|
51
|
+
- lib/rhcp/logging_broker.rb
|
52
|
+
- lib/rhcp/http_exporter.rb
|
53
|
+
- lib/rhcp.rb
|
64
54
|
- test/rhcp/tests_for_writable_brokers.rb
|
65
|
-
- test/rhcp/
|
55
|
+
- test/rhcp/logging_broker_test.rb
|
66
56
|
- test/rhcp/http_test_server.rb
|
57
|
+
- test/rhcp/context_test.rb
|
58
|
+
- test/rhcp/request_test.rb
|
59
|
+
- test/rhcp/broker_test.rb
|
60
|
+
- test/rhcp/client/command_param_stub_test.rb
|
61
|
+
- test/rhcp/client/command_stub_test.rb
|
62
|
+
- test/rhcp/test_base.rb
|
63
|
+
- test/rhcp/tests_for_brokers.rb
|
67
64
|
- test/rhcp/dispatching_broker_test.rb
|
68
|
-
- test/rhcp/command_param_test.rb
|
69
65
|
- test/rhcp/command_test.rb
|
70
|
-
- test/rhcp/
|
71
|
-
- test/rhcp/logging_broker_test.rb
|
66
|
+
- test/rhcp/command_param_test.rb
|
72
67
|
- test/rhcp/response_test.rb
|
73
|
-
- test/rhcp/context_aware_broker_test.rb
|
74
|
-
- test/rhcp/test_base.rb
|
75
|
-
- test/rhcp/client/command_stub_test.rb
|
76
|
-
- test/rhcp/client/command_param_stub_test.rb
|
77
68
|
- test/rhcp/http_exporter_test.rb
|
69
|
+
- test/rhcp/http_broker_test.rb
|
70
|
+
- test/rhcp/context_aware_broker_test.rb
|
78
71
|
homepage: http://rubyforge.org/projects/rhcp
|
79
72
|
licenses: []
|
80
|
-
|
81
73
|
post_install_message:
|
82
74
|
rdoc_options: []
|
83
|
-
|
84
|
-
require_paths:
|
75
|
+
require_paths:
|
85
76
|
- lib
|
86
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
78
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
|
93
|
-
- 0
|
94
|
-
version: "0"
|
95
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
84
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
version: "0"
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
104
89
|
requirements: []
|
105
|
-
|
106
90
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.8.
|
91
|
+
rubygems_version: 1.8.25
|
108
92
|
signing_key:
|
109
93
|
specification_version: 3
|
110
|
-
summary:
|
94
|
+
summary: needlessly complicated metadata-centric RPC implementation
|
111
95
|
test_files: []
|
112
|
-
|