ultrahook 0.1.2 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/lib/ultrahook.rb +0 -0
- data/lib/ultrahook/client.rb +32 -11
- data/lib/ultrahook/version.rb +1 -1
- metadata +12 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f11615e8b193ddb0b04af5fdfa47d61bcde9e22f7c0f1c4d377c012f97830d29
|
4
|
+
data.tar.gz: db37642d651ceb26377e5e9eec1e79da38715dee668f5db609be92fe0475f52e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64146e8ac3d3926c112d802e2c2a62c97c057d68a08cfa1d309fe12a4af0e87db91d367ee83a44c7ff0c4de539f9a0473530e4933afd3c2f5a13416ae5c60c04
|
7
|
+
data.tar.gz: 7682d234c73348c4d35f1bc6cfbe423e807e61688c4f56ffd1443553764f1136e2b2480e08a4e77f0ae9ece547d3293819e2f8c786afe77350f0c39af450aff6
|
data/LICENSE
CHANGED
data/lib/ultrahook.rb
CHANGED
File without changes
|
data/lib/ultrahook/client.rb
CHANGED
@@ -3,6 +3,9 @@ require 'net/http'
|
|
3
3
|
require 'json'
|
4
4
|
require 'base64'
|
5
5
|
require 'optparse'
|
6
|
+
require 'openssl'
|
7
|
+
|
8
|
+
$stdout.sync = true
|
6
9
|
|
7
10
|
module UltraHook
|
8
11
|
class Client
|
@@ -69,7 +72,7 @@ module UltraHook
|
|
69
72
|
"http://#{dest}"
|
70
73
|
elsif dest =~ /^[[:alnum:]\.\-]+$/
|
71
74
|
"http://#{dest}"
|
72
|
-
elsif dest =~ /^
|
75
|
+
elsif dest =~ /^https?:\/\//
|
73
76
|
dest
|
74
77
|
else
|
75
78
|
error "Cannot parse destination url"
|
@@ -78,7 +81,7 @@ module UltraHook
|
|
78
81
|
|
79
82
|
def process(msg)
|
80
83
|
begin
|
81
|
-
payload = JSON.parse(Base64.decode64(msg))
|
84
|
+
payload = JSON.parse(Base64.decode64(msg).force_encoding("utf-8"))
|
82
85
|
rescue
|
83
86
|
error "Cannot communicate with server."
|
84
87
|
end
|
@@ -89,7 +92,7 @@ module UltraHook
|
|
89
92
|
|
90
93
|
def process_init(payload)
|
91
94
|
puts "Forwarding activated..."
|
92
|
-
puts "
|
95
|
+
puts "https://#{@ultrahook_host} -> #{@options["destination"]}"
|
93
96
|
end
|
94
97
|
|
95
98
|
def process_error(payload)
|
@@ -100,6 +103,14 @@ module UltraHook
|
|
100
103
|
puts "Warning: "+payload["message"]
|
101
104
|
end
|
102
105
|
|
106
|
+
def process_message(payload)
|
107
|
+
puts payload["message"]
|
108
|
+
end
|
109
|
+
|
110
|
+
def process_ping(payload)
|
111
|
+
# silent ack!
|
112
|
+
end
|
113
|
+
|
103
114
|
def full_path(uri)
|
104
115
|
return "/" if uri.path == "" && uri.query == ""
|
105
116
|
return "/?#{uri.query}" if uri.path == "" && uri.query != ""
|
@@ -112,15 +123,20 @@ module UltraHook
|
|
112
123
|
uri = URI("#{@options["destination"]}#{payload["path"]}?#{payload["query"]}")
|
113
124
|
response = http_post(uri, payload["body"], payload["headers"])
|
114
125
|
|
115
|
-
puts "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] POST
|
126
|
+
puts "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] POST #{uri.scheme}://#{uri.host}:#{uri.port}#{full_path(uri)} - #{response.code}"
|
116
127
|
end
|
117
128
|
|
118
|
-
def http_post(uri, data, headers=
|
119
|
-
Net::HTTP.new(uri.host, uri.port)
|
129
|
+
def http_post(uri, data="", headers={})
|
130
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
131
|
+
if uri.scheme == "https"
|
132
|
+
http.use_ssl = true
|
133
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
134
|
+
end
|
135
|
+
http.post(full_path(uri), data, headers)
|
120
136
|
end
|
121
137
|
|
122
138
|
def retrieve_config
|
123
|
-
response = http_post(URI("
|
139
|
+
response = http_post(URI("https://www.ultrahook.com/init"), "key=#{@options["key"]}&host=#{@options["host"]}&version=#{UltraHook::VERSION}")
|
124
140
|
|
125
141
|
error "Could not retrieve config from server: #{response.code}" if response.code.to_i != 200
|
126
142
|
|
@@ -128,6 +144,7 @@ module UltraHook
|
|
128
144
|
if payload["success"] == true
|
129
145
|
@stream_url = payload["url"]
|
130
146
|
@namespace = payload["namespace"]
|
147
|
+
@ultrahook_host = payload["host"]
|
131
148
|
|
132
149
|
puts "Authenticated as #{@namespace}"
|
133
150
|
else
|
@@ -137,7 +154,7 @@ module UltraHook
|
|
137
154
|
|
138
155
|
def init_stream
|
139
156
|
uri = URI(@stream_url)
|
140
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
157
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
141
158
|
begin
|
142
159
|
request = Net::HTTP::Get.new "#{uri.path}?#{uri.query}"
|
143
160
|
|
@@ -147,9 +164,13 @@ module UltraHook
|
|
147
164
|
response.read_body do |chunk|
|
148
165
|
io += chunk
|
149
166
|
|
150
|
-
|
151
|
-
|
152
|
-
|
167
|
+
loop do
|
168
|
+
if idx = io.index("\n\n")
|
169
|
+
msg = io.slice!(0, idx+2)
|
170
|
+
process(msg)
|
171
|
+
else
|
172
|
+
break
|
173
|
+
end
|
153
174
|
end
|
154
175
|
end
|
155
176
|
end
|
data/lib/ultrahook/version.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ultrahook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Vinay Sahni
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.8.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.8.0
|
30
27
|
description: UltraHook lets you receive webhooks on localhost. It relays HTTP POST
|
@@ -36,34 +33,32 @@ executables:
|
|
36
33
|
extensions: []
|
37
34
|
extra_rdoc_files: []
|
38
35
|
files:
|
39
|
-
- lib/ultrahook/client.rb
|
40
|
-
- lib/ultrahook/version.rb
|
41
|
-
- lib/ultrahook.rb
|
42
36
|
- LICENSE
|
43
37
|
- bin/ultrahook
|
38
|
+
- lib/ultrahook.rb
|
39
|
+
- lib/ultrahook/client.rb
|
40
|
+
- lib/ultrahook/version.rb
|
44
41
|
homepage: http://www.ultrahook.com
|
45
42
|
licenses:
|
46
43
|
- Commercial
|
44
|
+
metadata: {}
|
47
45
|
post_install_message:
|
48
46
|
rdoc_options: []
|
49
47
|
require_paths:
|
50
48
|
- lib
|
51
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
50
|
requirements:
|
54
|
-
- -
|
51
|
+
- - ">="
|
55
52
|
- !ruby/object:Gem::Version
|
56
53
|
version: '0'
|
57
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
55
|
requirements:
|
60
|
-
- -
|
56
|
+
- - ">="
|
61
57
|
- !ruby/object:Gem::Version
|
62
58
|
version: '0'
|
63
59
|
requirements: []
|
64
|
-
|
65
|
-
rubygems_version: 1.8.25
|
60
|
+
rubygems_version: 3.0.6
|
66
61
|
signing_key:
|
67
|
-
specification_version:
|
62
|
+
specification_version: 4
|
68
63
|
summary: Receive webhooks on localhost
|
69
64
|
test_files: []
|