ksconnect 0.1.4 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/ksconnect.rb +12 -5
- data/lib/ksconnect/api/plugin.rb +20 -1
- data/lib/ksconnect/api/plugin/domain.rb +3 -3
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e06a4a726ae9d277d8c455a9091a5720999d955e
|
4
|
+
data.tar.gz: 86b4fde365fbc5b5d4b9a57325920dee13749b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e83a4b54c544587f3b7390f22ac1fc690d0e9ae19884454792ec56ee48ccf82357751bf2371c920e20e755f91db57a7140a216435476e4f1c686501e06d8c34d
|
7
|
+
data.tar.gz: 58bd856484abb32f1a18e4112b5519e1373d6de0a6c012e92a6bde957d7afdc60b9521412a6be620780e1e0f41cdfad4cd5eb196d5c0437e9e9bc4952dead89f
|
data/lib/ksconnect.rb
CHANGED
@@ -6,6 +6,7 @@ require 'ksconnect/api/plugin/data'
|
|
6
6
|
require 'ksconnect/api/plugin/domain'
|
7
7
|
require 'ksconnect/helpers'
|
8
8
|
require 'ksconnect/logs'
|
9
|
+
require 'thread/pool'
|
9
10
|
|
10
11
|
class KSConnect
|
11
12
|
include Logs
|
@@ -26,17 +27,23 @@ class KSConnect
|
|
26
27
|
@api = KSConnect::API.new(enabled_plugins: plugins, use_helpers: additional_options[:use_helpers])
|
27
28
|
end
|
28
29
|
|
30
|
+
def self.thread_pool
|
31
|
+
@@thread_pool ||= Thread.pool(3, 50)
|
32
|
+
end
|
33
|
+
|
29
34
|
def self.channel(name)
|
30
35
|
Thread.start do
|
31
36
|
begin
|
32
37
|
Redis.new.subscribe(name) do |on|
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
thread_pool.process do
|
39
|
+
logger.info "Subscribing to redis channel: #{name}"
|
40
|
+
on.message do |_channel, message|
|
41
|
+
yield message
|
42
|
+
end
|
43
|
+
$stdout.flush
|
36
44
|
end
|
37
|
-
$stdout.flush
|
38
45
|
end
|
39
|
-
rescue
|
46
|
+
rescue => error
|
40
47
|
logger.error "#{error} on redis channel #{name}, restarting in 0.5s"
|
41
48
|
logger.error error.backtrace.join("\n")
|
42
49
|
$stdout.flush
|
data/lib/ksconnect/api/plugin.rb
CHANGED
@@ -54,11 +54,30 @@ class KSConnect
|
|
54
54
|
if %w(initialize update teardown).include? msg['request_type']
|
55
55
|
perform_request(msg)
|
56
56
|
else
|
57
|
-
|
57
|
+
begin
|
58
|
+
result = config.on_push.call(msg)
|
59
|
+
update_action(msg["action_uuid"], :done, result) if msg["action_uuid"]
|
60
|
+
rescue => e
|
61
|
+
update_action(msg["action_uuid"], :failed, "") if msg["action_uuid"]
|
62
|
+
raise e
|
63
|
+
end
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|
61
67
|
|
68
|
+
def update_action(action_id, state, body="")
|
69
|
+
raise "Updating action with empty action_id" if action_id.nil? or action_id.empty?
|
70
|
+
redis.multi do |redis_transaction|
|
71
|
+
redis_transaction.mapped_hmset "kloudsec_data:#{action_id}", {
|
72
|
+
plugin_name: @name,
|
73
|
+
uuid: action_id,
|
74
|
+
state: state,
|
75
|
+
response: body,
|
76
|
+
}
|
77
|
+
redis_transaction.expire "kloudsec_data:#{action_id}", 300
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
62
81
|
def perform_request(request)
|
63
82
|
request.stringify_keys!
|
64
83
|
|
@@ -30,15 +30,15 @@ class KSConnect
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def notify(data)
|
33
|
-
redis.lpush("
|
33
|
+
redis.lpush("ks:notifications_push", data.merge({ domain_name: @name, plugin_name: @plugin_name }))
|
34
34
|
end
|
35
35
|
|
36
36
|
def add_issue(issue_type, data)
|
37
|
-
redis.lpush("
|
37
|
+
redis.lpush("ks:issues_push", data.merge({ domain_name: @name, plugin_name: @plugin_name, issue_type: issue_type, request_type: 'add' }))
|
38
38
|
end
|
39
39
|
|
40
40
|
def clear_issue(issue_type)
|
41
|
-
redis.lpush("
|
41
|
+
redis.lpush("ks:issues_push", { domain_name: @name, plugin_name: @plugin_name, issue_type: issue_type, request_type: 'remove' })
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ksconnect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Poon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -95,4 +95,3 @@ signing_key:
|
|
95
95
|
specification_version: 4
|
96
96
|
summary: Connection API for Kloudsec
|
97
97
|
test_files: []
|
98
|
-
has_rdoc:
|