radd 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1b144c324d733fdabbee7eada3e800e3e9c1cba8aee8e2de1a02c67fd6e5a34
4
- data.tar.gz: 27a536a5b377f7762a6c8bf26c9978e27ac08218745cca493af8f45680fc9f10
3
+ metadata.gz: 3839d4afb39cef8bced2dd146aff7ef7a08dd7e130f2bd534cd820856e6f9c90
4
+ data.tar.gz: d3ff659868d45d89068ab1628090c7f40370407cd2a162d17ddca5c5bf1c8a21
5
5
  SHA512:
6
- metadata.gz: f46802e9687b2cd65da92e5866dce85e14a2a8de8fb04b1b1bf29431b485c4979c50f71292d850af787d7e7163a13c5b3282e5ac45548482d66f70ea8d1be5cf
7
- data.tar.gz: d2a5de1d3da7ad395f77eda95bd72f39796bdb7b64c072ca1df336207c064ca405624f0f09142bac1c44ee937436696d0afbfbbb094000f24d4444e5b3d5b825
6
+ metadata.gz: 5d79c2896c91af7aee9d4d4c4d86f250f03f1f5fcf8233379c47be57eab5d6d519b0dc2008db930326a6420f0afcc91c7aedbe57c0563919b7acb647bc3d259c
7
+ data.tar.gz: ad478c2fea9f293b3164d3ab7e73b059b87ce84a2493063962261c0c0b82922d39b0e3a1ac88185b61ccde9738cfb52db997971495900c7aabc6766682a8974c
data/lib/radd/cli.rb CHANGED
@@ -4,25 +4,21 @@ module Radd::Cli
4
4
 
5
5
  class << self
6
6
 
7
- def start
7
+ def load_config
8
8
  config = {}
9
9
  parser = OptionParser.new
10
- parser.banner = 'Usage: radd -i IP -d DOMAIN [options]'
11
- parser.on('--ip IP', 'Public IP address') do |ip|
12
- config['ip'] = ip
13
- end
14
- parser.on('--domain DOMAIN', 'Root FQDN') do |domain|
15
- config['domain'] = domain
16
- end
17
- parser.on('--http-port [PORT]', 'HTTP port') do |port|
18
- config['http_port'] = port
19
- end
20
- parser.on('--dns-port [PORT]', 'DNS port') do |port|
21
- config['dns_port'] = port
10
+ parser.banner = 'Usage: radd --config [FILE]'
11
+ parser.on('--config FILE', 'Config file') do |file|
12
+ config['file'] = file
22
13
  end
14
+
23
15
  parser.parse!
24
16
 
25
- Radd.configure!(config)
17
+ Radd.configure!(config['file'])
18
+ end
19
+
20
+ def start
21
+ load_config
26
22
  puts "Starting Radd server for #{Radd.domain}"
27
23
 
28
24
  dns, http = Radd::Nameserver.new, Radd::Webserver.new
@@ -0,0 +1,50 @@
1
+ module Radd
2
+
3
+ class << self
4
+ def configure!(file)
5
+ file_path = Pathname.new(file || 'radd.yml')
6
+ file_path = Radd.root + file_path unless file_path.absolute?
7
+ raise Radd::ConfigurationError, "could not open config file #{file_path}" unless file_path.file?
8
+ @config = YAML.load(file_path.read).slice(*%w[domain ip host dns_port http_port db])
9
+ raise Radd::ConfigurationError, 'domain missing' unless Radd.domain
10
+ raise Radd::ConfigurationError, 'invalid IP' unless Radd.valid_ip?(Radd.ip)
11
+ db_path = Pathname.new(@config.delete('db') || 'db/radd.sqlite3')
12
+ db_path = Radd.root + db_path unless db_path.absolute?
13
+ @config['db'] = db_path
14
+ raise Radd::ConfigurationError, 'invalid database' unless Radd.db.file?
15
+ # Late loading required by Sequel architecture
16
+ require_relative 'db'
17
+ require_relative 'record'
18
+ end
19
+
20
+ def domain
21
+ @config['domain']
22
+ end
23
+
24
+ def ip
25
+ @config['ip']
26
+ end
27
+
28
+ def db
29
+ @config['db']
30
+ end
31
+
32
+ def host
33
+ @config['host'] || '127.0.0.1'
34
+ end
35
+
36
+ def dns_port
37
+ @config['dns_port'] || 5300
38
+ end
39
+
40
+ def http_port
41
+ @config['http_port'] || 3000
42
+ end
43
+
44
+ # Check whether +ip+ is a valid IP address string
45
+ def valid_ip?(ip)
46
+ !!(ip && ip.match(Resolv::IPv4::Regex))
47
+ end
48
+ end
49
+
50
+ end
data/lib/radd/db.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'sequel'
2
2
 
3
- DB = Sequel.connect("sqlite://#{Pathname.new(__FILE__).dirname.join('..', '..', 'db', 'radd.sqlite3')}")
3
+ DB = Sequel.connect("sqlite://#{Radd.db}")
@@ -0,0 +1,7 @@
1
+ module Radd
2
+ class RaddError < StandardError; end
3
+ class ConfigurationError < StandardError; end
4
+ class Forbidden < RaddError; end
5
+ class InvalidRequest < RaddError; end
6
+ class UpdateError < RaddError; end
7
+ end
data/lib/radd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Radd
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/lib/radd.rb CHANGED
@@ -10,53 +10,25 @@ require 'async/http/endpoint'
10
10
  require 'protocol/rack/adapter'
11
11
 
12
12
  require_relative 'radd/version'
13
+ require_relative 'radd/errors'
14
+ require_relative 'radd/config'
13
15
  require_relative 'radd/ip'
14
- require_relative 'radd/db'
15
- require_relative 'radd/record'
16
16
  require_relative 'radd/update'
17
17
  require_relative 'radd/nameserver'
18
18
  require_relative 'radd/webserver'
19
19
  require_relative 'radd/app'
20
+ require_relative 'radd/cli'
20
21
 
21
22
  module Radd
22
- class RaddError < StandardError; end
23
- class ConfigurationError < StandardError; end
24
- class Forbidden < RaddError; end
25
- class InvalidRequest < RaddError; end
26
- class UpdateError < RaddError; end
27
-
28
23
  class << self
29
- def configure!(config)
30
- @config = config.slice(*%w[domain ip host dns_port http_port])
31
- raise Radd::ConfigurationError, 'domain missing' unless Radd.domain
32
- raise Radd::ConfigurationError, 'invalid IP' unless Radd.valid_ip?(Radd.ip)
24
+ def root=(path)
25
+ @root = Pathname.new(path)
33
26
  end
34
27
 
35
- def domain
36
- config['domain']
37
- end
38
-
39
- def ip
40
- config['ip']
41
- end
42
-
43
- def host
44
- config['host'] || '127.0.0.1'
45
- end
46
-
47
- def dns_port
48
- config['dns_port'] || 5300
28
+ def root
29
+ @root ||= Pathname.new(Dir.pwd)
49
30
  end
50
31
 
51
- def http_port
52
- config['http_port'] || 3000
53
- end
54
-
55
- # Check whether +ip+ is a valid IP address string
56
- def valid_ip?(ip)
57
- !!(ip && ip.match(Resolv::IPv4::Regex))
58
- end
59
-
60
32
  # Check whether +name+ is authorized with +password+
61
33
  def authorized?(name, password)
62
34
  return false unless record = Record.where(name: name).first
@@ -71,10 +43,6 @@ module Radd
71
43
  record.ip
72
44
  end
73
45
 
74
- def run
75
-
76
- end
77
-
78
46
  private
79
47
 
80
48
  def config
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Grosser
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-02-23 00:00:00.000000000 Z
10
+ date: 2026-04-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: yaml
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: optparse
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -159,14 +173,15 @@ files:
159
173
  - CHANGELOG
160
174
  - LICENSE
161
175
  - README.md
162
- - bin/console
163
176
  - bin/radd
164
177
  - lib/radd.rb
165
178
  - lib/radd/app.rb
166
179
  - lib/radd/cli.rb
180
+ - lib/radd/config.rb
167
181
  - lib/radd/db.rb
168
182
  - lib/radd/dns.rb
169
183
  - lib/radd/dns_service.rb
184
+ - lib/radd/errors.rb
170
185
  - lib/radd/http.rb
171
186
  - lib/radd/http_service.rb
172
187
  - lib/radd/ip.rb
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'radd'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start