ksconnect 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7d84e395ec798ed06bbd384d903b8d792e40be4
4
- data.tar.gz: 33129b381efe034aabbd70828f4327c7d81cd4ee
3
+ metadata.gz: 950863b2585d00b7199bbcbee6de49fce6841b05
4
+ data.tar.gz: de7149bc22067e0dc2ea8bebb64da81c9b8c97cc
5
5
  SHA512:
6
- metadata.gz: 035bfbbf2af3736d47754bbc370cb7ab2dbac83110c435b39909cdb81b37022b9d824b61f6623d3c028e5a94eccb9188381353e2af4c09222bf6d4d06c72f989
7
- data.tar.gz: 669b9a916103bb0e6a2ee8e8756a8cb860c8acedfa733b3cf15a459592a8ab86a70ae7433ee2323e0e1b9f9fa044bcca0b474199fd82d014f7e2df77e05d55b8
6
+ metadata.gz: 571b953853c9f0d0d05f71ef5b2ecb60f86f4f8bbf5fca911a82819c907ac3c7f3243c1f4167826827942f46972a5e8c4a49150035145a87eb9e234cb493a4ac
7
+ data.tar.gz: a4825b49f1b55c9da2081ae91afd7f3f52b3bfbae573f8da15383e2320e3c10cb24dd4e18e2a4b7a7d0d1871b599fbda9402637c1c56a14077a4311e62d43950
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  KSConnect provides a Ruby connection interface for Kloudsec plugins by exposing a simple to use
4
4
  API for managing and synchronizing plugin data.
5
5
 
6
- # Usage
6
+ ## Usage
7
7
 
8
8
  Initialize the api:
9
9
 
@@ -13,7 +13,7 @@ Use it:
13
13
 
14
14
  `api.domains['domain-1.com'].data['some_flag'] = true`
15
15
 
16
- ## Options
16
+ ### Options
17
17
 
18
18
  Initialize with additional (untested) helpers:
19
19
 
@@ -22,7 +22,7 @@ api = KSConnect.new(:ssl, use_helpers: true).api
22
22
  api.ip_address_for('example.com') => # 127.0.0.1
23
23
  ```
24
24
 
25
- ## Getting the full domain list
25
+ ### Getting the full domain list
26
26
 
27
27
  All domain objects:
28
28
 
@@ -32,19 +32,19 @@ Domain names only:
32
32
 
33
33
  `api.all_domains.keys # => ['domain-1.com',..]`
34
34
 
35
- ## Getting data
35
+ ### Getting data
36
36
 
37
37
  `api.domains['domain-1.com'].data['key'] # => 'value'`
38
38
 
39
39
  `api.domains['domain-1.com'].data.getall # => { 'key' => 'value', ... }`
40
40
 
41
- ## Setting data
41
+ ### Setting data
42
42
 
43
43
  `api.domains['domain-1.com'].data['key'] = new_value`
44
44
 
45
45
  `api.domains['domain-1.com'].data.setall = { 'key': new_value, ... }`
46
46
 
47
- ## Event callbacks
47
+ ### Event callbacks
48
48
 
49
49
  Available callbacks for `<plugin>:push`:
50
50
 
@@ -62,9 +62,14 @@ end
62
62
 
63
63
  NOTE: there is no need to re-message proxy / core plugins to re-read configuration. This is done automatically.
64
64
 
65
- ## Channels
65
+ ### Channels
66
66
 
67
67
  Safely acquire a redis channel in a separate thread by doing:
68
68
 
69
69
  `new_channel = KSConnect.channel('channel_name') { |msg| puts msg }`
70
70
 
71
+ ## Development
72
+
73
+ Ensure tests are ran using:
74
+
75
+ `$ rspec`
@@ -73,7 +73,7 @@ class KSConnect
73
73
  raise "Race on setting data key failed." unless redis.hsetnx("#{@plugin_name}:#{@type}", @domain_name, @data_uuid)
74
74
  end
75
75
  rescue Exception => e
76
- puts e.message
76
+ logger.error e.message
77
77
  retry unless (tries -= 1).zero?
78
78
  end
79
79
  end
@@ -18,6 +18,12 @@ class KSConnect
18
18
  @private_data = Data.new(plugin_name, name, :private_data)
19
19
  end
20
20
 
21
+ def ip_address=(new_ip)
22
+ @ip_address = new_ip
23
+ redis.hset(domains_key, name, new_ip)
24
+ redis.publish("core:push", { domain_name: name, plugin_name: "core", request_type: "update"}) if plugin_name == 'core'
25
+ end
26
+
21
27
  def notify(data)
22
28
  redis.lpush("kloudsec_notifications", data.merge({ domain_name: @name, plugin_name: @plugin_name }))
23
29
  end
@@ -35,6 +41,11 @@ class KSConnect
35
41
  def redis
36
42
  Redis.current
37
43
  end
44
+
45
+ def domains_key
46
+ @domain_list_uuid ||= redis.hget("#{plugin_name}:data", "domain_names")
47
+ "kloudsec_data:#{@domain_list_uuid}"
48
+ end
38
49
  end
39
50
  end
40
51
  end
@@ -43,7 +43,7 @@ class KSConnect
43
43
  begin
44
44
  msg = JSON.parse(message)
45
45
  rescue Exception => e
46
- puts "Error parsing message as JSON: #{msg}"
46
+ logger.error "Error parsing message as JSON: #{msg}"
47
47
  next
48
48
  end
49
49
 
@@ -59,7 +59,7 @@ class KSConnect
59
59
  request.stringify_keys!
60
60
 
61
61
  domain_name = request['domain_name']
62
- puts "Invalid push request with no domain: #{request}" and return unless domain_name
62
+ logger.warn "Invalid push request with no domain: #{request}" and return unless domain_name
63
63
 
64
64
  request_type = request['request_type']
65
65
  case request_type
data/lib/ksconnect.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'redis'
1
2
  require 'logs'
2
3
 
3
4
  class KSConnect
@@ -6,6 +7,7 @@ class KSConnect
6
7
  attr_reader :plugin
7
8
 
8
9
  def initialize(*args)
10
+ Redis.current ||= Redis.new(driver: :hiredis)
9
11
  plugins = args
10
12
 
11
13
  additional_options = args.last.is_a?(Hash) ? args.last : nil
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.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Poon