ksconnect 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ksconnect/api/plugin.rb +19 -30
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea648d37bdf08e22c193648dc2ef8e06c396069a
4
- data.tar.gz: 663bc01a5c9a1e26c6255f2e90556721153a56ff
3
+ metadata.gz: 6730d75198a54bf80d6a387229b7d60d3e905d6b
4
+ data.tar.gz: 3647c8d45e3e9834e7932b95584fcfb336ec977c
5
5
  SHA512:
6
- metadata.gz: e8d1aef99fafb2166cda2b51271237abe3fae887074b8dec65ba9d6fb63951fe8169025b02fcf7ebd51ddb474182ac01d610eeb75334e7deffa2a3da8b669d30
7
- data.tar.gz: 9fd0ed41cab42654b170f31d8b4b100d7be9bbb45be598ccd2b38c797fa20e1287329ab71ff090052a1d616e47b7ddb02b1c86971904d452fc25c52bf15d05ef
6
+ metadata.gz: be27f9d88e195b9165e3cdd81f03e18b3c4acf49596432684857f10b768f2cfde5d11a09087ca3e4b97fd9c36b6c95dc94ba6eeeb67b2191ddb0467eff4e2a44
7
+ data.tar.gz: 5f6a210cc57bb84cdd29aeb88edd37a3884d9072ec734ee6743f2d2eeec9868eb6c6f1c6280db868b5e0161969ff59a810986b0f11dca7535a82639c9eed2b96
@@ -47,39 +47,13 @@ class KSConnect
47
47
  def subscribe_to_events
48
48
  KSConnect.channel("#{@name}:push") do |message|
49
49
  begin
50
- msg = JSON.parse(message)
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
- raise "Invalid request type"
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ksconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Poon