ksconnect 0.2.1 → 0.2.2
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/config.rb +5 -1
- data/lib/ksconnect/api.rb +1 -1
- data/lib/ksconnect/helpers.rb +27 -27
- data/lib/ksconnect/logs.rb +6 -5
- data/lib/ksconnect.rb +9 -5
- 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: 1d91fc4dd993ead89d5e76a124852edf2a6090b8
|
4
|
+
data.tar.gz: e4af39026299c2e5652396a489c7c0c373d7f87c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aef855195621760ce29beb37fb2f8c383877fc5a770c3627b98b2c67e87da71931803948def0791199efcd00b4b6346b78bb6f53f34d4f3850c2da33eee5288
|
7
|
+
data.tar.gz: 863962b0a6c006e814dd5b6d810222be3541db1804f4c1b027a2cf50cdcf546b0e10085292b5b4875f8368fdd0503462a93d649780560e600a50b462e950b271
|
@@ -1,11 +1,15 @@
|
|
1
|
+
require 'ksconnect/logs'
|
2
|
+
|
1
3
|
class KSConnect
|
2
4
|
class API
|
3
5
|
class Plugin
|
4
6
|
class Config
|
7
|
+
include Logs
|
8
|
+
|
5
9
|
attr_accessor :on_initialize, :on_update, :on_teardown, :on_push
|
6
10
|
|
7
11
|
def initialize
|
8
|
-
@on_initialize = @on_update = @on_teardown = @on_push = lambda { |msg| "No callback set for msg: #{msg}" }
|
12
|
+
@on_initialize = @on_update = @on_teardown = @on_push = lambda { |msg| logger.debug "No callback set for msg: #{msg}" }
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
data/lib/ksconnect/api.rb
CHANGED
@@ -16,7 +16,7 @@ class KSConnect
|
|
16
16
|
# set the main plugin
|
17
17
|
unless enabled_plugins.empty?
|
18
18
|
main_plugin_name = enabled_plugins.shift
|
19
|
-
@plugin = @plugins[main_plugin_name] = KSConnect::API::Plugin.new(
|
19
|
+
@plugin = @plugins[main_plugin_name] = KSConnect::API::Plugin.new(main_plugin_name.to_s, true)
|
20
20
|
end
|
21
21
|
|
22
22
|
# init the other plugins
|
data/lib/ksconnect/helpers.rb
CHANGED
@@ -2,54 +2,54 @@ require 'active_support/core_ext/object/try'
|
|
2
2
|
|
3
3
|
class KSConnect
|
4
4
|
module Helpers
|
5
|
-
def ip_address_for(
|
6
|
-
if all_domains[
|
7
|
-
all_domains[
|
5
|
+
def ip_address_for(domain_name)
|
6
|
+
if all_domains[domain_name]
|
7
|
+
all_domains[domain_name].ip_address
|
8
8
|
else
|
9
9
|
"kloudsec.com" # go to something safe if ip is invalid
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def https_enabled?(
|
14
|
-
k, c = ssl_key_and_cert_for(
|
13
|
+
def https_enabled?(domain_name)
|
14
|
+
k, c = ssl_key_and_cert_for(domain_name)
|
15
15
|
k && c
|
16
16
|
end
|
17
17
|
|
18
|
-
def https_redirect_enabled?(
|
19
|
-
https_enabled?(
|
18
|
+
def https_redirect_enabled?(domain_name)
|
19
|
+
https_enabled?(domain_name) && plugins[:ssl].domains[domain_name].data['redirect'] == "true"
|
20
20
|
end
|
21
21
|
|
22
|
-
def https_rewriting_enabled?(
|
23
|
-
https_enabled?(
|
22
|
+
def https_rewriting_enabled?(domain_name)
|
23
|
+
https_enabled?(domain_name) && plugins[:ssl].domains[domain_name].data['rewriteHTTPS'] == "true"
|
24
24
|
end
|
25
25
|
|
26
|
-
def waf_enabled?(
|
27
|
-
plugins[:web_shield].domains.has_key?(
|
26
|
+
def waf_enabled?(domain_name)
|
27
|
+
plugins[:web_shield].domains.has_key?(domain_name)
|
28
28
|
end
|
29
29
|
|
30
|
-
def waf_learning?(
|
31
|
-
waf_enabled?(
|
30
|
+
def waf_learning?(domain_name)
|
31
|
+
waf_enabled?(domain_name) && plugins[:web_shield].domains[domain_name].data['learning']
|
32
32
|
end
|
33
33
|
|
34
|
-
def waf_location_config(
|
35
|
-
waf_enabled?(
|
34
|
+
def waf_location_config(domain_name)
|
35
|
+
waf_enabled?(domain_name) ? plugins[:web_shield].domains[domain_name].private_data['location.conf'] : ""
|
36
36
|
end
|
37
37
|
|
38
|
-
def waf_server_config(
|
39
|
-
waf_enabled?(
|
38
|
+
def waf_server_config(domain_name)
|
39
|
+
waf_enabled?(domain_name) ? plugins[:web_shield].domains[domain_name].private_data['server.conf'] : ""
|
40
40
|
end
|
41
41
|
|
42
|
-
def pagespeed_enabled?(
|
43
|
-
plugins[:mod_cache].domains.has_key?(
|
42
|
+
def pagespeed_enabled?(domain_name)
|
43
|
+
plugins[:mod_cache].domains.has_key?(domain_name)
|
44
44
|
end
|
45
45
|
|
46
|
-
def pending_autossl?(
|
47
|
-
p, k = autossl_verification_path_and_key_for(
|
48
|
-
plugins[:autossl].domains.has_key?(
|
46
|
+
def pending_autossl?(domain_name)
|
47
|
+
p, k = autossl_verification_path_and_key_for(domain_name)
|
48
|
+
plugins[:autossl].domains.has_key?(domain_name) && p && k
|
49
49
|
end
|
50
50
|
|
51
|
-
def autossl_verification_path_and_key_for(
|
52
|
-
d = plugins[:autossl].domains[
|
51
|
+
def autossl_verification_path_and_key_for(domain_name)
|
52
|
+
d = plugins[:autossl].domains[domain_name].try(:private_data)
|
53
53
|
if d
|
54
54
|
return d['verify_endpoint'], d['verify_content']
|
55
55
|
else
|
@@ -57,9 +57,9 @@ class KSConnect
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
def ssl_key_and_cert_for(
|
61
|
-
ssl = plugins[:ssl].domains[
|
62
|
-
autossl = plugins[:autossl].domains[
|
60
|
+
def ssl_key_and_cert_for(domain_name)
|
61
|
+
ssl = plugins[:ssl].domains[domain_name].try(:private_data)
|
62
|
+
autossl = plugins[:autossl].domains[domain_name].try(:private_data)
|
63
63
|
|
64
64
|
if ssl && ssl['key'] && ssl['cert']
|
65
65
|
return ssl['key'], ssl['cert']
|
data/lib/ksconnect/logs.rb
CHANGED
@@ -15,11 +15,12 @@ module Logs
|
|
15
15
|
|
16
16
|
module ClassMethods
|
17
17
|
def logger
|
18
|
-
return
|
18
|
+
return @_logger if @_logger
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
STDOUT.sync = true
|
21
|
+
@_logger = Logger.new(STDOUT)
|
22
|
+
@_logger.level = "Logger::#{ENV['LOG_LEVEL'] || 'INFO'}".constantize
|
23
|
+
@_logger
|
23
24
|
end
|
24
25
|
end
|
25
|
-
end
|
26
|
+
end
|
data/lib/ksconnect.rb
CHANGED
@@ -34,25 +34,29 @@ class KSConnect
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.thread_pool
|
37
|
+
Thread::Pool.abort_on_exception = true
|
37
38
|
@@thread_pool ||= Thread.pool(MIN_THREADS, MAX_THREADS)
|
38
39
|
end
|
39
40
|
|
40
41
|
def self.channel(name)
|
41
42
|
Thread.start do
|
42
43
|
begin
|
43
|
-
Redis.new.subscribe(name) do |on|
|
44
|
+
Redis.new(driver: :hiredis).subscribe(name) do |on|
|
44
45
|
logger.info "Subscribing to redis channel: #{name}"
|
45
46
|
on.message do |_channel, message|
|
46
47
|
thread_pool.process do
|
47
|
-
|
48
|
-
|
48
|
+
begin
|
49
|
+
yield message
|
50
|
+
rescue => error
|
51
|
+
logger.error "#{error.message} on redis channel #{name}:"
|
52
|
+
logger.error error
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
rescue => error
|
53
|
-
logger.error "
|
58
|
+
logger.error "Fatal error on redis channel #{name}, restarting in 0.5s"
|
54
59
|
logger.error error.backtrace.join("\n")
|
55
|
-
$stdout.flush
|
56
60
|
sleep 0.5
|
57
61
|
retry
|
58
62
|
end
|