zonesync 0.1.2 → 0.3.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 +4 -4
- data/README.md +14 -1
- data/exe/zonesync +3 -0
- data/lib/zonesync/cli.rb +29 -0
- data/lib/zonesync/http.rb +1 -0
- data/lib/zonesync/logger.rb +25 -0
- data/lib/zonesync/provider.rb +9 -1
- data/lib/zonesync/version.rb +1 -1
- data/lib/zonesync.rb +11 -9
- data/log/.keep +0 -0
- data/zonesync.gemspec +2 -0
- metadata +36 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 58c4f6168ca0355c6aa7f0580ede2f8c080b04b44f196a24ecb827b38a3edda8
|
|
4
|
+
data.tar.gz: 9064bdd19540cc12d5cc48dfd93cbbb4a940c3e4cb4423255a0f66c9b282287a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e06ff17f120b42693ca00fd27fcd3c56501bb01abb2b72c9dea149ef8173f3f3f02765767805b03210d6df1a40dee0c84f872d5f07f549ec7ccc95b9d250c6c
|
|
7
|
+
data.tar.gz: 8ddf71739ae861c356f27162484e9a1f006e841bbe8900471a1c098046db4287efae357df715b78f60154df7d54e03247892726e8156f68ba8400560951c2147
|
data/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Zonesync
|
|
2
|
+
|
|
3
|
+
[](https://github.com/botandrose/zonesync/actions?query=workflow%3ACI+branch%3Amaster)
|
|
2
4
|
|
|
3
5
|
Sync your DNS host with your DNS zone file, making it easy to version your zone file and sync changes.
|
|
4
6
|
|
|
@@ -70,6 +72,17 @@ aws_secret_access_key: <AWS_SECRET_ACCESS_KEY>
|
|
|
70
72
|
|
|
71
73
|
### Usage
|
|
72
74
|
|
|
75
|
+
#### CLI
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
$ bundle exec zonesync
|
|
79
|
+
```
|
|
80
|
+
```
|
|
81
|
+
$ bundle exec zonesync --dry-run # log to STDOUT but don't actually perform the sync
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Ruby
|
|
85
|
+
|
|
73
86
|
Assuming your zone file lives in `hostfile.txt` and your DNS provider credentials are configured in `provider.yml`:
|
|
74
87
|
|
|
75
88
|
```ruby
|
data/exe/zonesync
ADDED
data/lib/zonesync/cli.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "thor"
|
|
2
|
+
|
|
3
|
+
module Zonesync
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
def self.exit_on_failure?
|
|
6
|
+
true
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
default_command :sync
|
|
10
|
+
desc "sync", "syncs the contents of Zonefile to the DNS server configured in Rails.application.credentials.zonesync"
|
|
11
|
+
method_option :dry_run, type: :boolean, default: false, aliases: :n, desc: "log operations to STDOUT but don't perform the sync"
|
|
12
|
+
def sync
|
|
13
|
+
Zonesync.call credentials: default_credentials, dry_run: options[:dry_run]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def default_credentials
|
|
19
|
+
if defined?(Rails.application.credentials)
|
|
20
|
+
Rails.application.credentials.zonesync
|
|
21
|
+
else
|
|
22
|
+
require "active_support/encrypted_configuration"
|
|
23
|
+
require "active_support/core_ext/hash/keys"
|
|
24
|
+
credentials = ActiveSupport::EncryptedConfiguration.new(config_path: "config/credentials.yml.enc", key_path: "config/master.key", raise_if_missing_key: true, env_key: "RAILS_MASTER_KEY")
|
|
25
|
+
credentials.zonesync
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/zonesync/http.rb
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "logger"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
|
|
4
|
+
class Logger
|
|
5
|
+
def self.log method, args, dry_run: false
|
|
6
|
+
loggers = [::Logger.new(STDOUT)]
|
|
7
|
+
|
|
8
|
+
if !dry_run
|
|
9
|
+
FileUtils.mkdir_p("log")
|
|
10
|
+
loggers << ::Logger.new("log/zonesync.log")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
loggers.each do |logger|
|
|
14
|
+
operation = case args
|
|
15
|
+
when Array
|
|
16
|
+
args.map { |h| h.values.join(" ") }.join(" -> ")
|
|
17
|
+
when Hash
|
|
18
|
+
args.values.join(" ")
|
|
19
|
+
else
|
|
20
|
+
raise args.inspect
|
|
21
|
+
end
|
|
22
|
+
logger.info "Zonesync: #{method.capitalize} #{operation}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/zonesync/provider.rb
CHANGED
|
@@ -8,13 +8,21 @@ module Zonesync
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def diffable_records
|
|
11
|
-
|
|
11
|
+
zonefile.records.map do |record|
|
|
12
12
|
Record.from_dns_zonefile_record(record)
|
|
13
13
|
end.select do |record|
|
|
14
14
|
%w[A AAAA CNAME MX TXT SPF NAPTR PTR].include?(record.type)
|
|
15
15
|
end.sort
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
private def zonefile
|
|
19
|
+
body = read
|
|
20
|
+
if body !~ /\sSOA\s/ # insert dummy SOA to trick parser if needed
|
|
21
|
+
body.sub!(/\n([^$])/, "\n@ 1 SOA example.com example.com ( 2000010101 1 1 1 1 )\n\\1")
|
|
22
|
+
end
|
|
23
|
+
DNS::Zonefile.load(body)
|
|
24
|
+
end
|
|
25
|
+
|
|
18
26
|
def read record
|
|
19
27
|
raise NotImplementedError
|
|
20
28
|
end
|
data/lib/zonesync/version.rb
CHANGED
data/lib/zonesync.rb
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
require "zonesync/provider"
|
|
2
2
|
require "zonesync/diff"
|
|
3
|
+
require "zonesync/logger"
|
|
4
|
+
require "zonesync/cli"
|
|
3
5
|
|
|
4
6
|
module Zonesync
|
|
5
|
-
def self.call zonefile:,
|
|
6
|
-
Sync.new(zonefile, credentials).call
|
|
7
|
+
def self.call zonefile: "Zonefile", credentials:, dry_run: false
|
|
8
|
+
Sync.new({ provider: "Filesystem", path: zonefile }, credentials).call(dry_run: dry_run)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
class Sync < Struct.new(:
|
|
10
|
-
def call
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
operations = Diff.call(from:
|
|
11
|
+
class Sync < Struct.new(:source, :destination)
|
|
12
|
+
def call dry_run: false
|
|
13
|
+
source = Provider.from(self.source)
|
|
14
|
+
destination = Provider.from(self.destination)
|
|
15
|
+
operations = Diff.call(from: destination, to: source)
|
|
14
16
|
operations.each do |method, args|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
Logger.log(method, args, dry_run: dry_run)
|
|
18
|
+
destination.send(method, args) unless dry_run
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
data/log/.keep
ADDED
|
File without changes
|
data/zonesync.gemspec
CHANGED
|
@@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
|
|
30
30
|
spec.add_dependency "dns-zonefile", "~>1.0"
|
|
31
31
|
spec.add_dependency "diff-lcs", "~>1.4"
|
|
32
|
+
spec.add_dependency "thor", "~>1.0"
|
|
32
33
|
|
|
34
|
+
spec.add_development_dependency "rake"
|
|
33
35
|
spec.add_development_dependency "rspec"
|
|
34
36
|
spec.add_development_dependency "webmock"
|
|
35
37
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zonesync
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Micah Geisel
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2024-01-
|
|
12
|
+
date: 2024-01-29 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: dns-zonefile
|
|
@@ -39,6 +39,34 @@ dependencies:
|
|
|
39
39
|
- - "~>"
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
41
|
version: '1.4'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: thor
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - "~>"
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '1.0'
|
|
49
|
+
type: :runtime
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - "~>"
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '1.0'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: rake
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
42
70
|
- !ruby/object:Gem::Dependency
|
|
43
71
|
name: rspec
|
|
44
72
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -71,7 +99,8 @@ description: Sync your Zone file with your DNS host
|
|
|
71
99
|
email:
|
|
72
100
|
- micah@botandrose.com
|
|
73
101
|
- git@james.ottaway.io
|
|
74
|
-
executables:
|
|
102
|
+
executables:
|
|
103
|
+
- zonesync
|
|
75
104
|
extensions: []
|
|
76
105
|
extra_rdoc_files: []
|
|
77
106
|
files:
|
|
@@ -81,13 +110,17 @@ files:
|
|
|
81
110
|
- LICENSE.txt
|
|
82
111
|
- README.md
|
|
83
112
|
- Rakefile
|
|
113
|
+
- exe/zonesync
|
|
84
114
|
- lib/zonesync.rb
|
|
115
|
+
- lib/zonesync/cli.rb
|
|
85
116
|
- lib/zonesync/cloudflare.rb
|
|
86
117
|
- lib/zonesync/diff.rb
|
|
87
118
|
- lib/zonesync/http.rb
|
|
119
|
+
- lib/zonesync/logger.rb
|
|
88
120
|
- lib/zonesync/provider.rb
|
|
89
121
|
- lib/zonesync/record.rb
|
|
90
122
|
- lib/zonesync/version.rb
|
|
123
|
+
- log/.keep
|
|
91
124
|
- zonesync.gemspec
|
|
92
125
|
homepage: https://github.com/botandrose/zonesync
|
|
93
126
|
licenses:
|