sparoid 1.0.22 → 1.2.0

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: 71a3d6d8370df36acaad83f5f03c0b29c6e5037856c33fcfa3e17a16c6f678ac
4
- data.tar.gz: d1d2cd45e4c503af8e0390c5466ec113abfbbeab62a045d3edee274ac888557d
3
+ metadata.gz: c24825e92fdb072067eb45465af26badb031dae413445c2acb4ec979bfe4afaf
4
+ data.tar.gz: e77fe5c9f7ad1c014534a51420bd9d1144f8f5fadbbcc1f28fcc8d4c0d52cf2c
5
5
  SHA512:
6
- metadata.gz: e45e3482c4c500914b12764ea4f1a16e0bde44a4de1119b3b6884a2ba29264de0ad8be169d1c24e3be5c43c8da891d55177491e13229184000fb68b284857487
7
- data.tar.gz: c52b06c69dc47867a73a3178172bf2279840ac3228fb74ace9a3fde7159b2e0af26af39d0c86dcba423c4f6ceb2f50fd5fe511072f9a2be3a00665883899e8f3
6
+ metadata.gz: 8ded4f653d9e8526b3dc4cfe6391deb2df878dd004f7e5c7c694514f251efc865e992f6a0779fa50be7cfeeb88d92b82a982f3de98a89e020e8062b7fcd8b77a
7
+ data.tar.gz: eb545dc80266d74df92a228b09266f33edf0a9612715196d82282a6bb506ece3bf62cb361a0523516a5e7d1af9e989c1ee606e3212d7471c0b8f9daea318571e
@@ -1,18 +1,22 @@
1
1
  name: Ruby
2
2
 
3
- on: [push,pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
4
8
 
5
9
  jobs:
6
10
  build:
7
11
  strategy:
8
12
  fail-fast: false
9
13
  matrix:
10
- ruby: [ 2.7, '3.0', 3.1, ruby-head ]
14
+ ruby: [ 2.7, 3.1, 3.2, 3.3, ruby-head ]
11
15
  runs-on: ubuntu-latest
12
16
  steps:
13
- - uses: actions/checkout@v3
17
+ - uses: actions/checkout@v4
14
18
  - uses: ruby/setup-ruby@v1
15
19
  with:
16
20
  ruby-version: ${{ matrix.ruby }}
17
- - run: bundle install
21
+ bundler-cache: true
18
22
  - run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.2.0] - 2024-07-24
2
+
3
+ - Lookup public IP using http://checkip.amazonaws.com, as it's more reliable for IPv6 connections than the DNS method
4
+
5
+ ## [1.1.0] - 2023-03-03
6
+
7
+ - Allow override of public ip, open for someone else by passing `:open_for_ip` to `Sparoid.auth(..., open_for_ip:)` (#11)
8
+
1
9
  ## [1.0.22] - 2023-02-01
2
10
 
3
11
  - Fix `Addrinfo SocketError` should raise `Sparoid::ResolvError` (#10)
data/CODEOWNERS ADDED
@@ -0,0 +1 @@
1
+ * @84codes/server
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sparoid
4
- VERSION = "1.0.22"
4
+ VERSION = "1.2.0"
5
5
  end
data/lib/sparoid.rb CHANGED
@@ -12,10 +12,10 @@ module Sparoid # rubocop:disable Metrics/ModuleLength
12
12
  SPAROID_CACHE_PATH = ENV.fetch("SPAROID_CACHE_PATH", "/tmp/.sparoid_public_ip")
13
13
 
14
14
  # Send an authorization packet
15
- def auth(key, hmac_key, host, port)
15
+ def auth(key, hmac_key, host, port, open_for_ip: cached_public_ip)
16
16
  addrs = resolve_ip_addresses(host, port)
17
-
18
- msg = message(cached_public_ip)
17
+ ip = Resolv::IPv4.create(open_for_ip)
18
+ msg = message(ip)
19
19
  data = prefix_hmac(hmac_key, encrypt(key, msg))
20
20
  sendmsg(addrs, data)
21
21
 
@@ -149,9 +149,21 @@ module Sparoid # rubocop:disable Metrics/ModuleLength
149
149
  end
150
150
  end
151
151
 
152
- def public_ip
153
- Resolv::DNS.open(nameserver: ["208.67.222.222", "208.67.220.220"]) do |dns|
154
- dns.getresource("myip.opendns.com", Resolv::DNS::Resource::IN::A).address
152
+ def public_ip(host = "checkip.amazonaws.com", port = 80) # rubocop:disable Metrics/MethodLength
153
+ Socket.tcp(host, port, connect_timeout: 3) do |sock|
154
+ sock.sync = true
155
+ sock.print "GET / HTTP/1.1\r\nHost: #{host}\r\nConnection: close\r\n\r\n"
156
+ status = sock.readline(chomp: true)
157
+ raise(ResolvError, "#{host}:#{port} response: #{status}") unless status.start_with? "HTTP/1.1 200 "
158
+
159
+ content_length = 0
160
+ until (header = sock.readline(chomp: true)).empty?
161
+ if (m = header.match(/^Content-Length: (\d+)/))
162
+ content_length = m[1].to_i
163
+ end
164
+ end
165
+ ip = sock.read(content_length).chomp
166
+ Resolv::IPv4.create ip
155
167
  end
156
168
  end
157
169
 
@@ -172,9 +184,7 @@ module Sparoid # rubocop:disable Metrics/ModuleLength
172
184
  class Instance
173
185
  include Sparoid
174
186
 
175
- private
176
-
177
- def public_ip
187
+ def public_ip(*args)
178
188
  @public_ip ||= super
179
189
  end
180
190
 
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.22
4
+ version: 1.2.0
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: 2023-02-01 00:00:00.000000000 Z
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -36,6 +36,7 @@ files:
36
36
  - ".gitignore"
37
37
  - ".rubocop.yml"
38
38
  - CHANGELOG.md
39
+ - CODEOWNERS
39
40
  - Gemfile
40
41
  - LICENSE.txt
41
42
  - README.md
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
73
  requirements: []
73
- rubygems_version: 3.4.5
74
+ rubygems_version: 3.5.11
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Single Packet Authorisation client