rhcp 0.2.15 → 0.2.16
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 +1 -1
- data/lib/rhcp/context.rb +19 -19
- data/lib/rhcp/logging_broker.rb +41 -11
- data/lib/rhcp/request.rb +36 -19
- data/lib/rhcp/response.rb +9 -22
- metadata +4 -5
- data/test/rhcp/rhcp.log +0 -20
data/lib/rhcp.rb
CHANGED
data/lib/rhcp/context.rb
CHANGED
@@ -14,27 +14,27 @@ module RHCP
|
|
14
14
|
@cookies = cookies
|
15
15
|
end
|
16
16
|
|
17
|
-
def to_json(*args)
|
18
|
-
{
|
19
|
-
'cookies' => @cookies,
|
20
|
-
}.to_json(*args)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.reconstruct_from_json(json_data)
|
24
|
-
$logger.debug "reconstructing context from json : >>#{json_data}<<"
|
25
|
-
object = JSON.parse(json_data)
|
26
|
-
instance = self.new()
|
27
|
-
instance.cookies = object['cookies']
|
28
|
-
|
29
|
-
instance
|
30
|
-
end
|
17
|
+
# def to_json(*args)
|
18
|
+
# {
|
19
|
+
# 'cookies' => @cookies,
|
20
|
+
# }.to_json(*args)
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def self.reconstruct_from_json(json_data)
|
24
|
+
# $logger.debug "reconstructing context from json : >>#{json_data}<<"
|
25
|
+
# object = JSON.parse(json_data)
|
26
|
+
# instance = self.new()
|
27
|
+
# instance.cookies = object['cookies']
|
28
|
+
#
|
29
|
+
# instance
|
30
|
+
# end
|
31
31
|
|
32
32
|
def to_s
|
33
|
-
result = "<Context cookies
|
34
|
-
@cookies.each do |k,v|
|
35
|
-
result += " '#{k}'='#{v}'"
|
36
|
-
end
|
37
|
-
result += ">"
|
33
|
+
result = "<Context with #{@cookies.size} cookies>"
|
34
|
+
# @cookies.each do |k,v|
|
35
|
+
# result += " '#{k}'='#{v}'"
|
36
|
+
# end
|
37
|
+
# result += ">"
|
38
38
|
result
|
39
39
|
end
|
40
40
|
|
data/lib/rhcp/logging_broker.rb
CHANGED
@@ -8,6 +8,7 @@ module RHCP
|
|
8
8
|
super()
|
9
9
|
@wrapped_broker = wrapped_broker
|
10
10
|
@logger = RHCP::ModuleHelper::instance.logger
|
11
|
+
@blacklisted_commands = [ "log_to_jabber", "log_to_jabber_detail", "on_host", "hostname", "ssh_options_for_machine" ]
|
11
12
|
end
|
12
13
|
|
13
14
|
def get_command_list(context = RHCP::Context.new())
|
@@ -22,22 +23,24 @@ module RHCP
|
|
22
23
|
@wrapped_broker.clear()
|
23
24
|
end
|
24
25
|
|
26
|
+
def blacklist_defaults
|
27
|
+
[ "log_to_jabber", "log_to_jabber_detail", "on_host", "hostname", "ssh_options_for_machine" ]
|
28
|
+
end
|
29
|
+
|
25
30
|
def get_blacklisted_commands
|
26
|
-
[
|
31
|
+
[]
|
27
32
|
end
|
28
33
|
|
34
|
+
def graylist
|
35
|
+
[ "on_machine", "list_machines" ]
|
36
|
+
end
|
29
37
|
|
30
38
|
# TODO would be nice if this helper method would be accessible from inside vop plugins
|
31
39
|
def var_name(name)
|
32
40
|
self.class.to_s + "." + name
|
33
41
|
end
|
34
42
|
|
35
|
-
def execute(request)
|
36
|
-
blacklisted = get_blacklisted_commands.include?(request.command.name)
|
37
|
-
if not blacklisted and request.context.cookies.has_key?('__loggingbroker.blacklisted_commands') then
|
38
|
-
blacklisted = request.context.cookies['__loggingbroker.blacklisted_commands'].split(',').include?(request.command.name)
|
39
|
-
end
|
40
|
-
|
43
|
+
def execute(request)
|
41
44
|
command = get_command(request.command.name, request.context)
|
42
45
|
mode = command.is_read_only ? 'r/o' : 'r/w'
|
43
46
|
|
@@ -52,25 +55,52 @@ module RHCP
|
|
52
55
|
|
53
56
|
level = Thread.current[var_name("stack")].size()
|
54
57
|
|
55
|
-
|
58
|
+
blacklist = blacklist_defaults + get_blacklisted_commands
|
59
|
+
blacklisted = false
|
60
|
+
blacklist.each do |sheep|
|
61
|
+
if Thread.current[var_name("stack")].include?(sheep)
|
62
|
+
blacklisted = true
|
63
|
+
break
|
64
|
+
end
|
65
|
+
end
|
66
|
+
if not blacklisted
|
67
|
+
if request.context.cookies.has_key?('__loggingbroker.blacklisted_commands') then
|
68
|
+
blacklisted = request.context.cookies['__loggingbroker.blacklisted_commands'].split(',').include?(request.command.name)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
graylisted = graylist.include? command.name
|
73
|
+
|
74
|
+
unless blacklisted or graylisted
|
56
75
|
#$logger.info ">> #{command.name} (#{mode}) : #{Thread.current[var_name("stack")].join(" -> ")}"
|
57
76
|
start_ts = Time.now()
|
58
|
-
log_request_start(Thread.current[var_name("request_id")], level, mode,
|
77
|
+
log_request_start(Thread.current[var_name("request_id")], level, mode, stack_for_display, request, start_ts)
|
59
78
|
end
|
60
79
|
|
61
80
|
response = @wrapped_broker.execute(request)
|
62
81
|
|
63
|
-
|
82
|
+
|
83
|
+
unless blacklisted or graylisted
|
64
84
|
stop_ts = Time.now()
|
65
85
|
duration = stop_ts.to_i - start_ts.to_i
|
66
86
|
|
67
|
-
log_request_stop(Thread.current[var_name("request_id")], level, mode,
|
87
|
+
log_request_stop(Thread.current[var_name("request_id")], level, mode, stack_for_display, request, response, duration)
|
68
88
|
end
|
69
89
|
|
70
90
|
Thread.current[var_name("stack")].pop
|
71
91
|
|
92
|
+
if level == 1
|
93
|
+
Thread.current[var_name("request_id")] = nil
|
94
|
+
end
|
95
|
+
|
72
96
|
response
|
73
97
|
end
|
98
|
+
|
99
|
+
def stack_for_display
|
100
|
+
Thread.current[var_name("stack")].select do |command_name|
|
101
|
+
not graylist.include? command_name
|
102
|
+
end.join(".")
|
103
|
+
end
|
74
104
|
|
75
105
|
def log_request_start(request_id, level, mode, current_stack, request, start_ts)
|
76
106
|
$logger.debug("> #{request_id} #{level} [#{mode}] #{current_stack.join('.')} #{request}")
|
data/lib/rhcp/request.rb
CHANGED
@@ -94,29 +94,46 @@ module RHCP
|
|
94
94
|
# Params:
|
95
95
|
# +broker+ is the broker to use for command lookup
|
96
96
|
# +json_data+ is the JSON data that represents the request
|
97
|
-
def self.reconstruct_from_json(broker, json_data)
|
98
|
-
object = JSON.parse(json_data)
|
99
|
-
|
100
|
-
context = object.has_key?('context') ?
|
101
|
-
RHCP::Context.reconstruct_from_json(object['context']) :
|
102
|
-
RHCP::Context.new(object['cookies'])
|
103
|
-
|
104
|
-
command = broker.get_command(object['command_name'], context)
|
105
|
-
|
106
|
-
self.new(command, object['param_values'], context)
|
107
|
-
end
|
108
|
-
|
109
|
-
# returns a JSON representation of this request.
|
110
|
-
def to_json(*args)
|
97
|
+
# def self.reconstruct_from_json(broker, json_data)
|
98
|
+
# object = JSON.parse(json_data)
|
99
|
+
#
|
100
|
+
# context = object.has_key?('context') ?
|
101
|
+
# RHCP::Context.reconstruct_from_json(object['context']) :
|
102
|
+
# RHCP::Context.new(object['cookies'])
|
103
|
+
#
|
104
|
+
# command = broker.get_command(object['command_name'], context)
|
105
|
+
#
|
106
|
+
# self.new(command, object['param_values'], context)
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# # returns a JSON representation of this request.
|
110
|
+
# def to_json(*args)
|
111
|
+
# {
|
112
|
+
# 'command_name' => @command.name,
|
113
|
+
# 'param_values' => @param_values,
|
114
|
+
# 'context' => @context.to_json
|
115
|
+
# }.to_json(*args)
|
116
|
+
# end
|
117
|
+
|
118
|
+
def as_json(options={})
|
111
119
|
{
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
120
|
+
:command_name => @command.name,
|
121
|
+
:param_values => @param_values,
|
122
|
+
:context => @context
|
123
|
+
}
|
116
124
|
end
|
117
125
|
|
118
126
|
def to_s
|
119
|
-
|
127
|
+
s = @command.name + ' ('
|
128
|
+
count = 0
|
129
|
+
@param_values.each do |k,v|
|
130
|
+
next if v.class == Proc.class
|
131
|
+
count += 1
|
132
|
+
s += ' ' unless count == 1
|
133
|
+
s += "#{k} => #{v}"
|
134
|
+
end
|
135
|
+
s += ')'
|
136
|
+
s
|
120
137
|
end
|
121
138
|
|
122
139
|
end
|
data/lib/rhcp/response.rb
CHANGED
@@ -45,29 +45,16 @@ module RHCP
|
|
45
45
|
@context = new_context
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
object = JSON.parse(json_data)
|
50
|
-
instance = self.new()
|
51
|
-
instance.status = object["status"]
|
52
|
-
instance.error_text = object["error_text"]
|
53
|
-
instance.error_detail = object["error_detail"]
|
54
|
-
instance.set_payload(object["data"])
|
55
|
-
instance.result_text = object['result_text']
|
56
|
-
instance.context = object['cookies']
|
57
|
-
instance.created_at = object['created_at']
|
58
|
-
instance
|
59
|
-
end
|
60
|
-
|
61
|
-
def to_json(*args)
|
48
|
+
def as_json(options = {})
|
62
49
|
{
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
}
|
50
|
+
:status => @status,
|
51
|
+
:error_text => @error_text,
|
52
|
+
:error_detail => @error_detail,
|
53
|
+
:data => @data, # TODO what about JSONinification of data? (probably data should be JSON-ish data only, i.e. no special objects)
|
54
|
+
:result_text => @result_text,
|
55
|
+
:context => @context,
|
56
|
+
:created_at => @created_at
|
57
|
+
}
|
71
58
|
end
|
72
59
|
|
73
60
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhcp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 16
|
10
|
+
version: 0.2.16
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philipp Traeder
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-26 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -63,7 +63,6 @@ files:
|
|
63
63
|
- test/rhcp/test_base.rb
|
64
64
|
- test/rhcp/command_param_test.rb
|
65
65
|
- test/rhcp/context_aware_broker_test.rb
|
66
|
-
- test/rhcp/rhcp.log
|
67
66
|
- test/rhcp/request_test.rb
|
68
67
|
- test/rhcp/tests_for_brokers.rb
|
69
68
|
- test/rhcp/http_exporter_test.rb
|
data/test/rhcp/rhcp.log
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# Logfile created on Sat Nov 12 22:54:42 +0100 2011 by logger.rb/22285
|
2
|
-
D, [2011-11-12T22:54:42.004418 #8757] DEBUG -- : enabling command context_test because of context key host
|
3
|
-
D, [2011-11-12T22:54:42.004543 #8757] DEBUG -- : initializing request test with params first_paramthing
|
4
|
-
D, [2011-11-12T22:54:42.004588 #8757] DEBUG -- : request initialized : command 'test', params : first_param=thing
|
5
|
-
D, [2011-11-12T22:54:42.004623 #8757] DEBUG -- : gonna execute request >>test (first_paramthing)<<
|
6
|
-
D, [2011-11-12T22:54:42.004736 #8757] DEBUG -- : initializing request not working with params
|
7
|
-
D, [2011-11-12T22:54:42.004771 #8757] DEBUG -- : request initialized : command 'not working', params :
|
8
|
-
D, [2011-11-12T22:54:42.004802 #8757] DEBUG -- : gonna execute request >>not working ()<<
|
9
|
-
D, [2011-11-12T22:54:42.004922 #8757] DEBUG -- : initializing request test with params first_paramthe_value
|
10
|
-
D, [2011-11-12T22:54:42.004961 #8757] DEBUG -- : request initialized : command 'test', params : first_param=the_value
|
11
|
-
D, [2011-11-12T22:54:42.004997 #8757] DEBUG -- : gonna execute request >>test (first_paramthe_value)<<
|
12
|
-
D, [2011-11-12T22:54:42.005214 #8757] DEBUG -- : initializing request test with params does_not_existsingle value for non-existing param
|
13
|
-
D, [2011-11-12T22:54:42.005256 #8757] DEBUG -- : request initialized : command 'test', params : does_not_exist=single value for non-existing param
|
14
|
-
D, [2011-11-12T22:54:42.005291 #8757] DEBUG -- : gonna execute request >>test (does_not_existsingle value for non-existing param)<<
|
15
|
-
D, [2011-11-12T22:54:42.005413 #8757] DEBUG -- : initializing request test with params real_paramvalue for the real paramanother value for the real param
|
16
|
-
D, [2011-11-12T22:54:42.005452 #8757] DEBUG -- : request initialized : command 'test', params : real_param=value for the real param,another value for the real param
|
17
|
-
D, [2011-11-12T22:54:42.005513 #8757] DEBUG -- : gonna execute request >>test (real_paramvalue for the real paramanother value for the real param)<<
|
18
|
-
D, [2011-11-12T22:54:42.005661 #8757] DEBUG -- : initializing request test with params
|
19
|
-
D, [2011-11-12T22:54:42.005701 #8757] DEBUG -- : request initialized : command 'test', params :
|
20
|
-
D, [2011-11-12T22:54:42.005733 #8757] DEBUG -- : gonna execute request >>test ()<<
|