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 +4 -4
- data/README.md +12 -7
- data/lib/ksconnect/api/plugin/data.rb +1 -1
- data/lib/ksconnect/api/plugin/domain.rb +11 -0
- data/lib/ksconnect/api/plugin.rb +2 -2
- data/lib/ksconnect.rb +2 -0
- 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: 950863b2585d00b7199bbcbee6de49fce6841b05
|
4
|
+
data.tar.gz: de7149bc22067e0dc2ea8bebb64da81c9b8c97cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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`
|
@@ -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
|
data/lib/ksconnect/api/plugin.rb
CHANGED
@@ -43,7 +43,7 @@ class KSConnect
|
|
43
43
|
begin
|
44
44
|
msg = JSON.parse(message)
|
45
45
|
rescue Exception => e
|
46
|
-
|
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
|
-
|
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
|