sparoid 1.0.11 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/Gemfile +2 -5
- data/lib/sparoid.rb +42 -14
- data/lib/sparoid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a696807043c46908b4bbeeb6e8636e33cea95673930442bfc24a3151fc190d28
|
4
|
+
data.tar.gz: 5e2b64879d91183c6248e28f7fb6faf95ad8f249983f1d675ea17a4c74970758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9a278830be195e3534b076860bd775406bfd338dae9f5e1083f0bf7f66c17d779c169b5dde140e54690b544363a64538f91f108b3178f053714a362d960d1a2
|
7
|
+
data.tar.gz: 32a8a77fb600b7f294b57a30f290e4fa9541ce27a94672173788db61211e2d9101ff7867476cbba08be3e38619cd5709534b2ad8caa896a6396e7280c6c03f51
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,27 @@
|
|
1
|
+
## [1.0.15] - 2021-08-11
|
2
|
+
|
3
|
+
- Raise an exception, don't abort, when resolving hostname fails
|
4
|
+
|
5
|
+
## [1.0.14] - 2021-07-26
|
6
|
+
|
7
|
+
- Send UDP packets to all resolved IPs for a hostname
|
8
|
+
|
9
|
+
## [1.0.13] - 2021-06-30
|
10
|
+
|
11
|
+
- Do not warn on empty public ip cache file
|
12
|
+
- The public ip cache file path can be controlled using the `SPAROID_CACHE_PATH` environment variable
|
13
|
+
|
14
|
+
## [1.0.12] - 2021-06-14
|
15
|
+
|
16
|
+
- Use file locking to prevent multiple processes/threads to write to the public ip cache file
|
17
|
+
|
1
18
|
## [1.0.11] - 2021-06-14
|
2
19
|
|
3
20
|
- Log hostname when reporting unhandled exceptions
|
4
21
|
|
5
22
|
## [1.0.10] - 2021-06-09
|
6
23
|
|
7
|
-
- Cache public IP in
|
24
|
+
- Cache public IP in `/tmp/.sparoid_public_ip` for 1 min
|
8
25
|
|
9
26
|
## [1.0.9] - 2021-05-23
|
10
27
|
|
data/Gemfile
CHANGED
@@ -5,12 +5,9 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in sparoid.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
8
|
gem "minitest", "~> 5.0"
|
11
|
-
|
9
|
+
gem "minitest-stub-const"
|
10
|
+
gem "rake", "~> 13.0"
|
12
11
|
gem "rubocop", "~> 1.7"
|
13
|
-
|
14
12
|
gem "rubocop-minitest", require: false
|
15
|
-
|
16
13
|
gem "rubocop-rake", require: false
|
data/lib/sparoid.rb
CHANGED
@@ -9,6 +9,8 @@ require "resolv"
|
|
9
9
|
module Sparoid
|
10
10
|
extend self
|
11
11
|
|
12
|
+
SPAROID_CACHE_PATH = ENV.fetch("SPAROID_CACHE_PATH", "/tmp/.sparoid_public_ip")
|
13
|
+
|
12
14
|
# Send an authorization packet
|
13
15
|
def auth(key, hmac_key, host, port)
|
14
16
|
msg = message(cached_public_ip)
|
@@ -39,11 +41,18 @@ module Sparoid
|
|
39
41
|
|
40
42
|
private
|
41
43
|
|
42
|
-
def sendmsg(host, port, data)
|
44
|
+
def sendmsg(host, port, data) # rubocop:disable Metrics/MethodLength
|
45
|
+
ok = false
|
43
46
|
UDPSocket.open do |socket|
|
44
|
-
|
45
|
-
|
47
|
+
Resolv.each_address(host) do |ip|
|
48
|
+
ok = true
|
49
|
+
socket.connect ip, port
|
50
|
+
socket.sendmsg data, 0
|
51
|
+
rescue StandardError => e
|
52
|
+
warn "Sparoid error: #{e.message}"
|
53
|
+
end
|
46
54
|
end
|
55
|
+
raise Error, "Sparoid failed to resolv #{host}" unless ok
|
47
56
|
end
|
48
57
|
|
49
58
|
def encrypt(key, data)
|
@@ -76,23 +85,42 @@ module Sparoid
|
|
76
85
|
end
|
77
86
|
|
78
87
|
def cached_public_ip
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
Resolv::IPv4.create f.read
|
84
|
-
end
|
88
|
+
if up_to_date_cache?
|
89
|
+
read_cache
|
90
|
+
else
|
91
|
+
write_cache
|
85
92
|
end
|
86
93
|
rescue StandardError => e
|
87
94
|
warn "Sparoid: #{e.inspect}"
|
88
95
|
public_ip
|
89
96
|
end
|
90
97
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
98
|
+
def up_to_date_cache?
|
99
|
+
mtime = File.mtime(SPAROID_CACHE_PATH)
|
100
|
+
(Time.now - mtime) <= 60 # cache is valid for 1 min
|
101
|
+
rescue Errno::ENOENT
|
102
|
+
false
|
103
|
+
end
|
104
|
+
|
105
|
+
def read_cache
|
106
|
+
File.open(SPAROID_CACHE_PATH, "r") do |f|
|
107
|
+
f.flock(File::LOCK_SH)
|
108
|
+
Resolv::IPv4.create f.read
|
109
|
+
end
|
110
|
+
rescue ArgumentError => e
|
111
|
+
return write_cache if e.message =~ /cannot interpret as IPv4 address/
|
112
|
+
|
113
|
+
raise e
|
114
|
+
end
|
115
|
+
|
116
|
+
def write_cache
|
117
|
+
File.open(SPAROID_CACHE_PATH, File::WRONLY | File::CREAT, 0o0644) do |f|
|
118
|
+
f.flock(File::LOCK_EX)
|
119
|
+
ip = public_ip
|
120
|
+
f.truncate(0)
|
121
|
+
f.write ip.to_s
|
122
|
+
ip
|
123
|
+
end
|
96
124
|
end
|
97
125
|
|
98
126
|
def public_ip
|
data/lib/sparoid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Hörberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|