sparoid 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12dad3dbab45bb38650465dab2b26f356c051569b06d20ba1bcfd6af11eb9701
4
- data.tar.gz: 0b17fe457b36978f1b682153cb14578192cb657a846fadcbb3abb2cf82e07bb6
3
+ metadata.gz: 1f5904f6b6c520213811268420efad5fd5a387942352d8def32b722cd14420da
4
+ data.tar.gz: 6f7e19f1515979078635ff1e862bc9bcbb6fb2172ac631d94b986dd1b95984fb
5
5
  SHA512:
6
- metadata.gz: 1c31f7b1fa30e2d064b0e92e79b2b567bdfa4021995d7f52c25b6b4373d08062ed091aab8187aeb42051c11e0c7c1b994d158878e64311eed28e68d1e3fe4008
7
- data.tar.gz: cacd2adf45ed9fa8e31b063809e01cf0371c6d13670e24b5bdb17f7c2623c2f9592c7e38b6df18a5f529db9628d4197baf323a9d58124b8eb6ea75762c3a6d78
6
+ metadata.gz: 6043c439103ae404d9dfc6855b0273777b3e1e505d768e36b7d5bf514abc6c2a0498ecda76ddf89994d4d3fb426394fc3994566e659842e377bab643b8edfcfd
7
+ data.tar.gz: d95a3908952eb8134f1c68bd22a6f13f05ca99a8f1bda888c0adf6cbc77e882f65e4097a12b3db8a28ec74c624d8cee0821827ee12e54953da567606605f1e96
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [1.0.13] - 2021-06-30
2
+
3
+ - Do not warn on empty public ip cache file
4
+ - The public ip cache file path can be controlled using the `SPAROID_CACHE_PATH` environment variable
5
+
1
6
  ## [1.0.12] - 2021-06-14
2
7
 
3
8
  - Use file locking to prevent multiple processes/threads to write to the public ip cache file
@@ -8,7 +13,7 @@
8
13
 
9
14
  ## [1.0.10] - 2021-06-09
10
15
 
11
- - Cache public IP in /tmp/.sparoid_public_ip for 1 min
16
+ - Cache public IP in `/tmp/.sparoid_public_ip` for 1 min
12
17
 
13
18
  ## [1.0.9] - 2021-05-23
14
19
 
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)
@@ -87,21 +89,25 @@ module Sparoid
87
89
  end
88
90
 
89
91
  def up_to_date_cache?
90
- mtime = File.mtime("/tmp/.sparoid_public_ip")
92
+ mtime = File.mtime(SPAROID_CACHE_PATH)
91
93
  (Time.now - mtime) <= 60 # cache is valid for 1 min
92
94
  rescue Errno::ENOENT
93
95
  false
94
96
  end
95
97
 
96
98
  def read_cache
97
- File.open("/tmp/.sparoid_public_ip", "r") do |f|
99
+ File.open(SPAROID_CACHE_PATH, "r") do |f|
98
100
  f.flock(File::LOCK_SH)
99
101
  Resolv::IPv4.create f.read
100
102
  end
103
+ rescue ArgumentError => e
104
+ return write_cache if e.message =~ /cannot interpret as IPv4 address/
105
+
106
+ raise e
101
107
  end
102
108
 
103
109
  def write_cache
104
- File.open("/tmp/.sparoid_public_ip", File::WRONLY | File::CREAT, 0o0644) do |f|
110
+ File.open(SPAROID_CACHE_PATH, File::WRONLY | File::CREAT, 0o0644) do |f|
105
111
  f.flock(File::LOCK_EX)
106
112
  ip = public_ip
107
113
  f.truncate(0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sparoid
4
- VERSION = "1.0.12"
4
+ VERSION = "1.0.13"
5
5
  end
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.12
4
+ version: 1.0.13
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-06-24 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.2.15
72
+ rubygems_version: 3.1.6
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Single Packet Authorisation client