notifyor 0.4.3 → 0.5.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/notifyor/cli.rb +15 -10
- data/lib/notifyor/configuration.rb +6 -6
- data/lib/notifyor/plugin.rb +4 -9
- data/lib/notifyor/remote/connection.rb +20 -16
- data/lib/notifyor/version.rb +1 -1
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/log/development.log +6 -0
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a06c37ee1d957d65e8d85fc3f2a7fe548a17fc8
|
4
|
+
data.tar.gz: a23b2405dc4b7a2ff8f498aa567aa8f749c5d34a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 281d8842cc4fbefca6577f019b095f9e6bf2f72990bf9d1e62de88e4069e645417b4852f09c88394543fb2227f138f288cee27a44598c69903453c907d0844ac
|
7
|
+
data.tar.gz: 0d11f8684dc3b83c4237eb79fb31c1fef8c5bece12b7ea3515088ed259f006f2755a59abbf57884b538a5afcf3fe274869ab1b076b68a4e4f70efb916d8d6d88
|
data/lib/notifyor/cli.rb
CHANGED
@@ -23,10 +23,6 @@ module Notifyor
|
|
23
23
|
::Notifyor.configuration.ssh_host = host
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on('--ssh-password password', 'Provide the ssh password for the deployment/remote server') do |password|
|
27
|
-
::Notifyor.configuration.ssh_password = password
|
28
|
-
end
|
29
|
-
|
30
26
|
opts.on('--ssh-port port', 'Provide the ssh port for the deployment/remote server') do |port|
|
31
27
|
::Notifyor.configuration.ssh_port = port
|
32
28
|
end
|
@@ -34,16 +30,25 @@ module Notifyor
|
|
34
30
|
opts.on('--ssh-user user', 'Provide the ssh user for the deployment/remote server') do |user|
|
35
31
|
::Notifyor.configuration.ssh_user = user
|
36
32
|
end
|
33
|
+
|
34
|
+
opts.on('--tunnel-port tunnel_port', 'Provide the ssh user for the deployment/remote server') do |tunnel_port|
|
35
|
+
::Notifyor.configuration.tunnel_port = tunnel_port
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('--redis-port redis_port', 'Provide the ssh user for the deployment/remote server') do |redis_port|
|
39
|
+
::Notifyor.configuration.redis_port = redis_port
|
40
|
+
end
|
37
41
|
end.parse!
|
38
42
|
end
|
39
43
|
|
40
44
|
def check_notifications
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
connection = Notifyor::Remote::Connection.new
|
46
|
+
begin
|
47
|
+
connection.build_tunnel
|
48
|
+
connection.build_redis_tunnel_connection
|
49
|
+
connection.subscribe_to_redis
|
50
|
+
rescue => e
|
51
|
+
STDOUT.write "Could not establish SSH tunnel. Reason: #{e.message}"
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require 'redis
|
1
|
+
require 'redis'
|
2
2
|
require 'connection_pool'
|
3
3
|
module Notifyor
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :redis_connection
|
6
|
-
attr_accessor :notifyor_models
|
7
6
|
attr_accessor :ssh_host
|
8
7
|
attr_accessor :ssh_user
|
9
|
-
attr_accessor :ssh_password
|
10
8
|
attr_accessor :ssh_port
|
9
|
+
attr_accessor :tunnel_port
|
10
|
+
attr_accessor :redis_port
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@redis_connection = ::Redis.new
|
14
|
-
|
15
|
-
@notifyor_models = Set.new
|
16
|
-
@ssh_port = 22
|
14
|
+
@ssh_port = '22'
|
17
15
|
@ssh_host = 'localhost'
|
16
|
+
@tunnel_port ='2000'
|
17
|
+
@redis_port = '6379'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/notifyor/plugin.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'redis'
|
2
3
|
|
3
4
|
module Notifyor
|
4
5
|
module Plugin
|
@@ -8,14 +9,8 @@ module Notifyor
|
|
8
9
|
end
|
9
10
|
|
10
11
|
module ClassMethods
|
11
|
-
attr_accessor :notifyor_events
|
12
|
-
attr_accessor :notifyor_models
|
13
|
-
|
14
12
|
def notifyor(options = {})
|
15
13
|
configure_plugin(options)
|
16
|
-
self.extend ::Redis::Objects
|
17
|
-
::Notifyor.configuration.notifyor_models.add(self.name)
|
18
|
-
self.notifyor_events = ::Redis::List.new("notifyor:#{self.name.tableize}")
|
19
14
|
end
|
20
15
|
|
21
16
|
def configure_plugin(options = {})
|
@@ -27,11 +22,11 @@ module Notifyor
|
|
27
22
|
configuration[:only].each do |action|
|
28
23
|
case action
|
29
24
|
when :create
|
30
|
-
self.after_commit -> {
|
25
|
+
self.after_commit -> { ::Notifyor.configuration.redis_connection.publish "notifyor", {message: configuration[:messages][:create].call(self)}.to_json }, on: :create, if: -> { configuration[:only].include? :create }
|
31
26
|
when :update
|
32
|
-
self.after_commit -> {
|
27
|
+
self.after_commit -> { ::Notifyor.configuration.redis_connection.publish "notifyor", {message: configuration[:messages][:update].call(self)}.to_json }, on: :update, if: -> { configuration[:only].include? :update }
|
33
28
|
when :destroy
|
34
|
-
self.before_destroy -> {
|
29
|
+
self.before_destroy -> { ::Notifyor.configuration.redis_connection.publish "notifyor", {message: configuration[:messages][:destroy].call(self)}.to_json }, if: -> { configuration[:only].include? :destroy }
|
35
30
|
else
|
36
31
|
#nop
|
37
32
|
end
|
@@ -3,40 +3,44 @@ require 'notifyor'
|
|
3
3
|
require 'notifyor/growl'
|
4
4
|
require 'notifyor/util/formatter'
|
5
5
|
require 'notifyor/errors/ssh_error'
|
6
|
+
require 'net/ssh/gateway'
|
6
7
|
module Notifyor
|
7
8
|
module Remote
|
8
9
|
class Connection
|
9
10
|
|
10
11
|
def initialize
|
11
12
|
@ssh_host = ::Notifyor.configuration.ssh_host
|
12
|
-
@ssh_password = ::Notifyor.configuration.ssh_password
|
13
13
|
@ssh_port = ::Notifyor.configuration.ssh_port
|
14
14
|
@ssh_user = ::Notifyor.configuration.ssh_user
|
15
|
+
@tunnel_port = ::Notifyor.configuration.tunnel_port
|
16
|
+
@redis_port = ::Notifyor.configuration.redis_port
|
17
|
+
@ssh_gateway = nil
|
18
|
+
@redis_tunnel_connection = nil
|
15
19
|
end
|
16
20
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
21
|
+
def build_tunnel
|
22
|
+
unless ['127.0.0.1', 'localhost'].include? @ssh_host
|
23
|
+
@ssh_gateway = Net::SSH::Gateway.new(@ssh_host, @ssh_user, port: @ssh_port)
|
24
|
+
@ssh_gateway.open('127.0.0.1', @redis_port, @tunnel_port)
|
20
25
|
end
|
21
|
-
ssh_cmd = @ssh_user.present? ? "ssh #{@ssh_user}:#{@ssh_password}@#{@ssh_host}" : "ssh #{@ssh_host}"
|
22
|
-
ssh_cmd + " -p#{@ssh_port ? @ssh_port : 22}"
|
23
26
|
end
|
24
27
|
|
25
|
-
def
|
26
|
-
|
28
|
+
def build_redis_tunnel_connection
|
29
|
+
redis_port = (['127.0.0.1', 'localhost'].include? @ssh_host) ? @redis_port : @tunnel_port
|
30
|
+
@redis_tunnel_connection = Redis.new(port: redis_port)
|
27
31
|
end
|
28
32
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
def subscribe_to_redis
|
34
|
+
@redis_tunnel_connection.subscribe('notifyor') do |on|
|
35
|
+
on.message do |channel, msg|
|
36
|
+
data = JSON.parse(msg)
|
37
|
+
growl_message(data['message'])
|
38
|
+
end
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
|
-
def growl_message(
|
38
|
-
|
39
|
-
::Notifyor::Growl.create_growl("Notifyor", value) unless Notifyor::Util::Formatter.squish!(value).empty?
|
42
|
+
def growl_message(message)
|
43
|
+
::Notifyor::Growl.create_growl("Notifyor", message) unless Notifyor::Util::Formatter.squish!(message).empty?
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
data/lib/notifyor/version.rb
CHANGED
Binary file
|
@@ -193,3 +193,9 @@ Migrating to CreateUsers (20160404044940)
|
|
193
193
|
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
194
194
|
[1m[35mSQL (1.6ms)[0m UPDATE "users" SET "first_name" = ?, "updated_at" = ? WHERE "users"."id" = ? [["first_name", "erwin"], ["updated_at", "2016-04-05 19:15:08.874646"], ["id", 5]]
|
195
195
|
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
196
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
197
|
+
[1m[35mSQL (1.9ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-06 08:51:10.426367"], ["updated_at", "2016-04-06 08:51:10.426367"]]
|
198
|
+
[1m[36m (6.1ms)[0m [1mcommit transaction[0m
|
199
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
200
|
+
[1m[35mSQL (1.1ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-06 08:54:59.353124"], ["updated_at", "2016-04-06 08:54:59.353124"]]
|
201
|
+
[1m[36m (39.3ms)[0m [1mcommit transaction[0m
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifyor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erwin Schens
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: net-ssh
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: net-ssh-gateway
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: sqlite3
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|