ksconnect 0.2.8 → 0.3.0
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/api/plugin.rb +19 -30
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6730d75198a54bf80d6a387229b7d60d3e905d6b
|
4
|
+
data.tar.gz: 3647c8d45e3e9834e7932b95584fcfb336ec977c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be27f9d88e195b9165e3cdd81f03e18b3c4acf49596432684857f10b768f2cfde5d11a09087ca3e4b97fd9c36b6c95dc94ba6eeeb67b2191ddb0467eff4e2a44
|
7
|
+
data.tar.gz: 5f6a210cc57bb84cdd29aeb88edd37a3884d9072ec734ee6743f2d2eeec9868eb6c6f1c6280db868b5e0161969ff59a810986b0f11dca7535a82639c9eed2b96
|
data/lib/ksconnect/api/plugin.rb
CHANGED
@@ -47,39 +47,13 @@ class KSConnect
|
|
47
47
|
def subscribe_to_events
|
48
48
|
KSConnect.channel("#{@name}:push") do |message|
|
49
49
|
begin
|
50
|
-
|
50
|
+
json = JSON.parse(message)
|
51
|
+
perform_request(json)
|
51
52
|
rescue Exception => e
|
52
53
|
logger.error e
|
53
54
|
logger.error "Error parsing message as JSON: #{message}"
|
54
55
|
next
|
55
56
|
end
|
56
|
-
|
57
|
-
if %w(initialize update teardown).include? msg['request_type']
|
58
|
-
perform_request(msg)
|
59
|
-
else
|
60
|
-
begin
|
61
|
-
result = config.on_push.call(msg)
|
62
|
-
update_action(msg["action_uuid"], :done, result) if msg["action_uuid"] && ENV['KSCONNECT_READ_ONLY'].nil?
|
63
|
-
rescue => e
|
64
|
-
update_action(msg["action_uuid"], :failed, "") if msg["action_uuid"] && ENV['KSCONNECT_READ_ONLY'].nil?
|
65
|
-
raise e
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def update_action(action_id, state, body="")
|
72
|
-
raise "Updating action with empty action_id" if action_id.nil? or action_id.empty?
|
73
|
-
$redis.with do |redis|
|
74
|
-
redis.multi do |redis_transaction|
|
75
|
-
redis_transaction.mapped_hmset "kloudsec_data:#{action_id}", {
|
76
|
-
plugin_name: @name,
|
77
|
-
uuid: action_id,
|
78
|
-
state: state,
|
79
|
-
response: body,
|
80
|
-
}
|
81
|
-
redis_transaction.expire "kloudsec_data:#{action_id}", 300
|
82
|
-
end
|
83
57
|
end
|
84
58
|
end
|
85
59
|
|
@@ -104,8 +78,23 @@ class KSConnect
|
|
104
78
|
when 'teardown'
|
105
79
|
config.on_teardown.call(request)
|
106
80
|
@domains.delete(domain_name)
|
107
|
-
else
|
108
|
-
|
81
|
+
else # default to generic `on_push` type
|
82
|
+
begin
|
83
|
+
keys_to_echo = { domain_name: request['domain_name'], website_plugin_id: request['website_plugin_id'], request_id: request['request_id'] }
|
84
|
+
result = config.on_push.call(request)
|
85
|
+
update_action(keys_to_echo.merge!({ state: :done, data: result }))
|
86
|
+
rescue => e
|
87
|
+
update_action(keys_to_echo.merge({ state: :failed }))
|
88
|
+
raise e
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def update_action(result)
|
94
|
+
if ENV['KSCONNECT_READ_ONLY'].nil?
|
95
|
+
$redis.with do |redis|
|
96
|
+
redis.lpush("ks:actions_push", result.to_json)
|
97
|
+
end
|
109
98
|
end
|
110
99
|
end
|
111
100
|
|