rhcp 0.2.18 → 0.2.19
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 -2
- data/lib/rhcp/broker.rb +0 -0
- data/lib/rhcp/client/command_param_stub.rb +0 -0
- data/lib/rhcp/client/command_stub.rb +0 -0
- data/lib/rhcp/client/context_aware_broker.rb +0 -0
- data/lib/rhcp/client/http_broker.rb +0 -0
- data/lib/rhcp/command.rb +24 -2
- data/lib/rhcp/command_param.rb +6 -2
- data/lib/rhcp/context.rb +11 -15
- data/lib/rhcp/dispatching_broker.rb +0 -0
- data/lib/rhcp/http_exporter.rb +0 -0
- data/lib/rhcp/logging_broker.rb +46 -40
- data/lib/rhcp/request.rb +3 -35
- data/lib/rhcp/response.rb +0 -0
- data/lib/rhcp/rhcp_exception.rb +0 -0
- data/test/rhcp/broker_test.rb +0 -0
- data/test/rhcp/client/command_param_stub_test.rb +0 -0
- data/test/rhcp/client/command_stub_test.rb +0 -0
- data/test/rhcp/command_param_test.rb +0 -0
- data/test/rhcp/command_test.rb +0 -0
- data/test/rhcp/context_aware_broker_test.rb +0 -0
- data/test/rhcp/context_test.rb +0 -0
- data/test/rhcp/dispatching_broker_test.rb +0 -0
- data/test/rhcp/http_broker_test.rb +0 -0
- data/test/rhcp/http_exporter_test.rb +0 -0
- data/test/rhcp/http_test_server.rb +0 -0
- data/test/rhcp/logging_broker_test.rb +0 -0
- data/test/rhcp/request_test.rb +0 -0
- data/test/rhcp/response_test.rb +0 -0
- data/test/rhcp/test_base.rb +0 -0
- data/test/rhcp/tests_for_brokers.rb +0 -0
- data/test/rhcp/tests_for_writable_brokers.rb +0 -0
- metadata +30 -32
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 = 19
|
27
27
|
|
28
28
|
def Version.to_s
|
29
29
|
[ MAJOR, MINOR, TINY ].join(".")
|
@@ -40,7 +40,7 @@ module RHCP #:nodoc:
|
|
40
40
|
def initialize()
|
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
|
-
@logger = Logger.new(
|
43
|
+
@logger = Logger.new(STDOUT)
|
44
44
|
end
|
45
45
|
|
46
46
|
|
data/lib/rhcp/broker.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/rhcp/command.rb
CHANGED
@@ -34,6 +34,10 @@ module RHCP
|
|
34
34
|
|
35
35
|
attr_reader :accepts_extra_params
|
36
36
|
|
37
|
+
attr_reader :ignores_extra_params
|
38
|
+
|
39
|
+
attr_accessor :notifications
|
40
|
+
|
37
41
|
# an array of context keys that enable this command
|
38
42
|
#
|
39
43
|
# if at least one of the listed keys is found in the context, the command
|
@@ -41,6 +45,8 @@ module RHCP
|
|
41
45
|
# by default
|
42
46
|
attr_accessor :enabled_through_context_keys
|
43
47
|
|
48
|
+
attr_accessor :available_if
|
49
|
+
|
44
50
|
# hints about how the result of this command might be displayed
|
45
51
|
attr_accessor :result_hints
|
46
52
|
|
@@ -60,6 +66,11 @@ module RHCP
|
|
60
66
|
@enabled_through_context_keys = nil
|
61
67
|
|
62
68
|
@accepts_extra_params = false
|
69
|
+
@ignores_extra_params = false
|
70
|
+
|
71
|
+
@notifications = false
|
72
|
+
|
73
|
+
@available_if = nil
|
63
74
|
|
64
75
|
# TODO formalize this! (we need rules how clients should react, otherwise this will be a mess)
|
65
76
|
# TODO in some cases, the display_type could also be guessed from the response, I guess
|
@@ -70,7 +81,7 @@ module RHCP
|
|
70
81
|
}
|
71
82
|
end
|
72
83
|
|
73
|
-
def is_enabled?(context = RHCP::Context.new())
|
84
|
+
def is_enabled?(context = RHCP::Context.new(), param_values = nil)
|
74
85
|
result = true
|
75
86
|
|
76
87
|
if @enabled_through_context_keys != nil
|
@@ -84,6 +95,12 @@ module RHCP
|
|
84
95
|
end
|
85
96
|
end
|
86
97
|
|
98
|
+
if param_values != nil
|
99
|
+
if @available_if != nil
|
100
|
+
result = @available_if.call(param_values)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
87
104
|
result
|
88
105
|
end
|
89
106
|
|
@@ -116,6 +133,11 @@ module RHCP
|
|
116
133
|
@accepts_extra_params = true
|
117
134
|
self
|
118
135
|
end
|
136
|
+
|
137
|
+
def ignore_extra_params()
|
138
|
+
@ignores_extra_params = true
|
139
|
+
self
|
140
|
+
end
|
119
141
|
|
120
142
|
# returns the specified CommandParam
|
121
143
|
# or throws an RhcpException if the parameter does not exist
|
@@ -156,7 +178,7 @@ module RHCP
|
|
156
178
|
end
|
157
179
|
rescue Exception => ex
|
158
180
|
if (/undefined\sparameter/.match(ex.message))
|
159
|
-
raise RHCP::RhcpException.new(ex.message) unless @accepts_extra_params
|
181
|
+
raise RHCP::RhcpException.new(ex.message) unless @accepts_extra_params or @ignores_extra_params
|
160
182
|
end
|
161
183
|
end
|
162
184
|
|
data/lib/rhcp/command_param.rb
CHANGED
@@ -26,6 +26,8 @@ module RHCP
|
|
26
26
|
# the key to a context value that is used for filling this parameter
|
27
27
|
attr_reader :autofill_context_key
|
28
28
|
|
29
|
+
attr_reader :allows_extra_values
|
30
|
+
|
29
31
|
attr_accessor :default_value
|
30
32
|
|
31
33
|
# creates a new command parameter
|
@@ -35,7 +37,7 @@ module RHCP
|
|
35
37
|
# :lookup_method a block that returns an array of lookup values valid for this param
|
36
38
|
# :is_default_param true if this parameter is the default param for the enclosing command
|
37
39
|
# :default_value a value to use as default (who would have thought?)
|
38
|
-
def initialize(name, description, options =
|
40
|
+
def initialize(name, description, options = {})
|
39
41
|
@name = name
|
40
42
|
@description = description
|
41
43
|
|
@@ -47,6 +49,7 @@ module RHCP
|
|
47
49
|
@is_default_param = options[:is_default_param] || options[:default_param] || false
|
48
50
|
@autofill_context_key = options[:autofill_context_key] || nil
|
49
51
|
@default_value = options[:default_value] || nil
|
52
|
+
@allows_extra_values = options[:allows_extra_values] || false
|
50
53
|
end
|
51
54
|
|
52
55
|
# searches the context for a values that can be auto-filled
|
@@ -96,7 +99,8 @@ module RHCP
|
|
96
99
|
# check against lookup values
|
97
100
|
if @has_lookup_values
|
98
101
|
possible_value.each do |value|
|
99
|
-
if ! get_lookup_values(request).include?(value)
|
102
|
+
if ! get_lookup_values(request).include?(value) and
|
103
|
+
! @allows_extra_values
|
100
104
|
raise RHCP::RhcpException.new("invalid value '#{value}' for parameter '#{@name}'")
|
101
105
|
end
|
102
106
|
end
|
data/lib/rhcp/context.rb
CHANGED
@@ -15,27 +15,23 @@ module RHCP
|
|
15
15
|
@cookies = cookies
|
16
16
|
@request_context_id = request_context_id
|
17
17
|
@request_counter = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_hash(h)
|
21
|
+
new(h["cookies"], h["request_context_id"])
|
18
22
|
end
|
19
23
|
|
20
|
-
# def to_json(*args)
|
21
|
-
# {
|
22
|
-
# 'cookies' => @cookies,
|
23
|
-
# }.to_json(*args)
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# def self.reconstruct_from_json(json_data)
|
27
|
-
# $logger.debug "reconstructing context from json : >>#{json_data}<<"
|
28
|
-
# object = JSON.parse(json_data)
|
29
|
-
# instance = self.new()
|
30
|
-
# instance.cookies = object['cookies']
|
31
|
-
#
|
32
|
-
# instance
|
33
|
-
# end
|
34
|
-
|
35
24
|
def incr_and_get_request_counter()
|
36
25
|
@request_counter += 1
|
37
26
|
end
|
38
27
|
|
28
|
+
def as_json(options={})
|
29
|
+
{
|
30
|
+
"cookies" => @cookies,
|
31
|
+
"request_context_id" => @request_context_id
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
39
35
|
def to_s
|
40
36
|
result = "<Context with #{@cookies.size} cookies>"
|
41
37
|
# @cookies.each do |k,v|
|
File without changes
|
data/lib/rhcp/http_exporter.rb
CHANGED
File without changes
|
data/lib/rhcp/logging_broker.rb
CHANGED
@@ -31,10 +31,18 @@ module RHCP
|
|
31
31
|
[]
|
32
32
|
end
|
33
33
|
|
34
|
+
def get_graylisted_commands
|
35
|
+
[]
|
36
|
+
end
|
37
|
+
|
34
38
|
def graylist
|
35
39
|
[ "on_machine", "list_machines" ]
|
36
40
|
end
|
37
41
|
|
42
|
+
def blacklist
|
43
|
+
blacklist_defaults + get_blacklisted_commands
|
44
|
+
end
|
45
|
+
|
38
46
|
# TODO would be nice if this helper method would be accessible from inside vop plugins
|
39
47
|
def var_name(name)
|
40
48
|
self.class.to_s + "." + name
|
@@ -43,57 +51,55 @@ module RHCP
|
|
43
51
|
def execute(request)
|
44
52
|
command = get_command(request.command.name, request.context)
|
45
53
|
mode = command.is_read_only ? 'r/o' : 'r/w'
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
Time.now().to_i.to_s + '_' + request.command.name
|
54
|
+
|
55
|
+
should_be_logged = (not blacklist.include?(command.name))
|
56
|
+
|
57
|
+
if should_be_logged
|
58
|
+
request_id = Thread.current[var_name("request_id")]
|
52
59
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
is_new_request = request_id == nil
|
61
|
+
|
62
|
+
if is_new_request
|
63
|
+
if mode == 'r/o'
|
64
|
+
should_be_logged = false
|
65
|
+
else
|
66
|
+
new_request_id = if request.param_values.has_key?('request_id')
|
67
|
+
request.param_values['request_id'].first
|
68
|
+
elsif request.context.request_context_id != nil
|
69
|
+
request.context.request_context_id
|
70
|
+
else
|
71
|
+
Time.now().to_i.to_s + '_' + request.command.name
|
72
|
+
end
|
73
|
+
|
74
|
+
Thread.current[var_name("request_id")] = new_request_id
|
75
|
+
|
76
|
+
Thread.current[var_name("stack")] = []
|
77
|
+
Thread.current[var_name("id_stack")] = []
|
78
|
+
end
|
67
79
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
80
|
+
|
81
|
+
if should_be_logged
|
82
|
+
Thread.current[var_name("stack")] << command.name #unless graylist.include? command.name
|
83
|
+
|
84
|
+
level = Thread.current[var_name("stack")].size()
|
85
|
+
|
86
|
+
start_ts = Time.now()
|
87
|
+
log_request_start(Thread.current[var_name("request_id")], level, mode, stack_for_display, request, start_ts)
|
72
88
|
end
|
73
89
|
end
|
74
90
|
|
75
|
-
graylisted = graylist.include? command.name
|
76
|
-
|
77
|
-
unless blacklisted or graylisted
|
78
|
-
#$logger.info ">> #{command.name} (#{mode}) : #{Thread.current[var_name("stack")].join(" -> ")}"
|
79
|
-
start_ts = Time.now()
|
80
|
-
log_request_start(Thread.current[var_name("request_id")], level, mode, stack_for_display, request, start_ts)
|
81
|
-
end
|
82
|
-
|
83
91
|
response = @wrapped_broker.execute(request)
|
84
92
|
|
85
|
-
|
86
|
-
unless blacklisted or graylisted
|
93
|
+
if should_be_logged
|
87
94
|
stop_ts = Time.now()
|
88
95
|
duration = stop_ts.to_i - start_ts.to_i
|
89
96
|
|
90
97
|
log_request_stop(Thread.current[var_name("request_id")], level, mode, stack_for_display, request, response, duration)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Thread.current[var_name("request_id")] = nil
|
98
|
+
|
99
|
+
Thread.current[var_name("stack")].pop
|
100
|
+
if level == 1
|
101
|
+
Thread.current[var_name("request_id")] = nil
|
102
|
+
end
|
97
103
|
end
|
98
104
|
|
99
105
|
response
|
data/lib/rhcp/request.rb
CHANGED
@@ -27,11 +27,10 @@ module RHCP
|
|
27
27
|
@request_count = @context.incr_and_get_request_counter()
|
28
28
|
|
29
29
|
command.params.each do |param|
|
30
|
-
|
31
30
|
value_from_context = param.find_value_in_context(context)
|
32
31
|
if value_from_context != nil
|
33
32
|
# if the parameter has been specified in the param values, do not override
|
34
|
-
|
33
|
+
unless param_values.has_key?(param.name)
|
35
34
|
@logger.debug "pre-filling param #{param.name} with value '#{value_from_context}' (context key '#{param.autofill_context_key}')"
|
36
35
|
param_values[param.name] = value_from_context
|
37
36
|
end
|
@@ -45,9 +44,7 @@ module RHCP
|
|
45
44
|
param_values[param.name] = param.default_value
|
46
45
|
end
|
47
46
|
end
|
48
|
-
|
49
47
|
end
|
50
|
-
|
51
48
|
|
52
49
|
# autobox the parameters if necessary
|
53
50
|
param_values.each do |k,v|
|
@@ -88,40 +85,11 @@ module RHCP
|
|
88
85
|
@command.execute_request(self)
|
89
86
|
end
|
90
87
|
|
91
|
-
# reconstructs the request from it's JSON representation
|
92
|
-
# Since the JSON version of a request does hold the command name instead
|
93
|
-
# of the full command only, a broker is needed to lookup the command by
|
94
|
-
# it's name
|
95
|
-
#
|
96
|
-
# Params:
|
97
|
-
# +broker+ is the broker to use for command lookup
|
98
|
-
# +json_data+ is the JSON data that represents the request
|
99
|
-
# def self.reconstruct_from_json(broker, json_data)
|
100
|
-
# object = JSON.parse(json_data)
|
101
|
-
#
|
102
|
-
# context = object.has_key?('context') ?
|
103
|
-
# RHCP::Context.reconstruct_from_json(object['context']) :
|
104
|
-
# RHCP::Context.new(object['cookies'])
|
105
|
-
#
|
106
|
-
# command = broker.get_command(object['command_name'], context)
|
107
|
-
#
|
108
|
-
# self.new(command, object['param_values'], context)
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# # returns a JSON representation of this request.
|
112
|
-
# def to_json(*args)
|
113
|
-
# {
|
114
|
-
# 'command_name' => @command.name,
|
115
|
-
# 'param_values' => @param_values,
|
116
|
-
# 'context' => @context.to_json
|
117
|
-
# }.to_json(*args)
|
118
|
-
# end
|
119
|
-
|
120
88
|
def as_json(options={})
|
121
89
|
{
|
122
|
-
:command_name => @command.
|
90
|
+
:command_name => @command.full_name,
|
123
91
|
:param_values => @param_values,
|
124
|
-
:context => @context,
|
92
|
+
:context => @context.as_json(),
|
125
93
|
:request_count => @request_count
|
126
94
|
}
|
127
95
|
end
|
data/lib/rhcp/response.rb
CHANGED
File without changes
|
data/lib/rhcp/rhcp_exception.rb
CHANGED
File without changes
|
data/test/rhcp/broker_test.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/rhcp/command_test.rb
CHANGED
File without changes
|
File without changes
|
data/test/rhcp/context_test.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/rhcp/request_test.rb
CHANGED
File without changes
|
data/test/rhcp/response_test.rb
CHANGED
File without changes
|
data/test/rhcp/test_base.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,22 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhcp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 49
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 19
|
10
|
+
version: 0.2.19
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
- Philipp
|
13
|
+
- Philipp T.
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2013-01-06 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: json
|
@@ -34,8 +33,8 @@ dependencies:
|
|
34
33
|
version: 0.0.0
|
35
34
|
type: :runtime
|
36
35
|
version_requirements: *id001
|
37
|
-
description:
|
38
|
-
email: philipp
|
36
|
+
description: RHCP is a protocol designed for building up a command-metadata-based communication infrastructure making it easier for application developers to export commands in applications to generic clients.
|
37
|
+
email: philipp@virtualop.org
|
39
38
|
executables:
|
40
39
|
- rhcp_test_server
|
41
40
|
extensions: []
|
@@ -44,39 +43,38 @@ extra_rdoc_files: []
|
|
44
43
|
|
45
44
|
files:
|
46
45
|
- bin/rhcp_test_server
|
47
|
-
- lib/rhcp.rb
|
48
|
-
- lib/rhcp/command_param.rb
|
49
46
|
- lib/rhcp/response.rb
|
50
|
-
- lib/rhcp/rhcp_exception.rb
|
51
47
|
- lib/rhcp/logging_broker.rb
|
52
|
-
- lib/rhcp/
|
48
|
+
- lib/rhcp/command_param.rb
|
49
|
+
- lib/rhcp/rhcp_exception.rb
|
53
50
|
- lib/rhcp/client/context_aware_broker.rb
|
54
|
-
- lib/rhcp/client/command_stub.rb
|
55
51
|
- lib/rhcp/client/command_param_stub.rb
|
52
|
+
- lib/rhcp/client/command_stub.rb
|
53
|
+
- lib/rhcp/client/http_broker.rb
|
54
|
+
- lib/rhcp/command.rb
|
55
|
+
- lib/rhcp/context.rb
|
56
|
+
- lib/rhcp/request.rb
|
56
57
|
- lib/rhcp/http_exporter.rb
|
57
58
|
- lib/rhcp/dispatching_broker.rb
|
58
|
-
- lib/rhcp/request.rb
|
59
59
|
- lib/rhcp/broker.rb
|
60
|
-
- lib/rhcp
|
61
|
-
-
|
62
|
-
- test/rhcp/test_base.rb
|
63
|
-
- test/rhcp/command_param_test.rb
|
64
|
-
- test/rhcp/context_aware_broker_test.rb
|
65
|
-
- test/rhcp/request_test.rb
|
66
|
-
- test/rhcp/tests_for_brokers.rb
|
60
|
+
- lib/rhcp.rb
|
61
|
+
- test/rhcp/context_test.rb
|
67
62
|
- test/rhcp/http_exporter_test.rb
|
63
|
+
- test/rhcp/tests_for_brokers.rb
|
68
64
|
- test/rhcp/logging_broker_test.rb
|
69
|
-
- test/rhcp/
|
70
|
-
- test/rhcp/
|
65
|
+
- test/rhcp/command_test.rb
|
66
|
+
- test/rhcp/response_test.rb
|
67
|
+
- test/rhcp/context_aware_broker_test.rb
|
68
|
+
- test/rhcp/test_base.rb
|
71
69
|
- test/rhcp/broker_test.rb
|
70
|
+
- test/rhcp/tests_for_writable_brokers.rb
|
72
71
|
- test/rhcp/client/command_param_stub_test.rb
|
73
72
|
- test/rhcp/client/command_stub_test.rb
|
73
|
+
- test/rhcp/dispatching_broker_test.rb
|
74
|
+
- test/rhcp/http_test_server.rb
|
75
|
+
- test/rhcp/command_param_test.rb
|
76
|
+
- test/rhcp/request_test.rb
|
74
77
|
- test/rhcp/http_broker_test.rb
|
75
|
-
- test/rhcp/response_test.rb
|
76
|
-
- test/rhcp/tests_for_writable_brokers.rb
|
77
|
-
- test/rhcp/context_test.rb
|
78
|
-
- test/rhcp/command_test.rb
|
79
|
-
has_rdoc: true
|
80
78
|
homepage: http://rubyforge.org/projects/rhcp
|
81
79
|
licenses: []
|
82
80
|
|
@@ -105,10 +103,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
103
|
version: "0"
|
106
104
|
requirements: []
|
107
105
|
|
108
|
-
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.24
|
110
108
|
signing_key:
|
111
109
|
specification_version: 3
|
112
|
-
summary:
|
110
|
+
summary: command-based rpc library thing
|
113
111
|
test_files: []
|
114
112
|
|