zonesync 0.2.0 → 0.4.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: 4483586b922fcb40130de86a415fdf440dd46afa556dfa45e87e0d6d398f52d7
4
- data.tar.gz: 88cbb6f82331655a9f78d49ee9b4013c2011bd94c3bb04831b6ebd58b4b968e5
3
+ metadata.gz: 00751af08d69afada768a779c3e2344b3e728e0b3ee9162436f82f936737bcab
4
+ data.tar.gz: 772a439ddfd4f9e9cd96bffeade456ba7023732e221a81ef48c39595f0e2328d
5
5
  SHA512:
6
- metadata.gz: 8bdd45b0a0d43e91856f488a53f8880c3946f6ab566f9e13a54209a76b295ca76f3f6fb1e62e607594d0abea3963ddefd9576c593e804832bd2580e3b51e18fc
7
- data.tar.gz: d5afd17873627c461936dfd62038bd471fa7c83296981daca019ba9b2614c269cfa68b865d69a54dfd543c6b9a5d9c537bfe88c12cdca4885898b7db433bfa6a
6
+ metadata.gz: 896d74bfd34d5f4609c5e4ab9d79bcad73b812b694941ab24f3807f6d3a08f9d25c28b13dc73201a6e6ed318ae475e43f641f7c9376c8b4af612ea0ba0c3d78d
7
+ data.tar.gz: a6568612418b311a6c3c89bf8a8e680214336d0075e05373aad7ca7ad32938e000175ed72c198d230dc3d9c7ecfbfcc6ce37b4125c14cf3376d83834ba9e9b4b
data/README.md CHANGED
@@ -72,6 +72,17 @@ aws_secret_access_key: <AWS_SECRET_ACCESS_KEY>
72
72
 
73
73
  ### Usage
74
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
+
75
86
  Assuming your zone file lives in `hostfile.txt` and your DNS provider credentials are configured in `provider.yml`:
76
87
 
77
88
  ```ruby
data/exe/zonesync ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/zonesync"
3
+ Zonesync::CLI.start ARGV
@@ -0,0 +1,14 @@
1
+ require "thor"
2
+
3
+ module Zonesync
4
+ class CLI < Thor
5
+ default_command :sync
6
+ desc "sync", "syncs the contents of Zonefile to the DNS server configured in Rails.application.credentials.zonesync"
7
+ method_option :dry_run, type: :boolean, default: false, aliases: :n, desc: "log operations to STDOUT but don't perform the sync"
8
+ def sync
9
+ Zonesync.call dry_run: options[:dry_run]
10
+ end
11
+
12
+ def self.exit_on_failure? = true
13
+ end
14
+ end
data/lib/zonesync/http.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "net/http"
2
+ require "json"
2
3
 
3
4
  module Zonesync
4
5
  class HTTP < Struct.new(:base)
@@ -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
@@ -0,0 +1,5 @@
1
+ require "rake"
2
+
3
+ task :zonesync => :environment do
4
+ Zonesync.call
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zonesync
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/zonesync.rb CHANGED
@@ -1,19 +1,33 @@
1
1
  require "zonesync/provider"
2
2
  require "zonesync/diff"
3
+ require "zonesync/logger"
4
+ require "zonesync/cli"
5
+ require "zonesync/rake"
3
6
 
4
7
  module Zonesync
5
- def self.call zonefile:, credentials:
6
- Sync.new({ provider: "Filesystem", path: zonefile }, credentials).call
8
+ def self.call zonefile: "Zonefile", credentials: default_credentials, dry_run: false
9
+ Sync.new({ provider: "Filesystem", path: zonefile }, credentials).call(dry_run: dry_run)
10
+ end
11
+
12
+ def self.default_credentials
13
+ require "active_support/encrypted_configuration"
14
+ require "active_support/core_ext/hash/keys"
15
+ ActiveSupport::EncryptedConfiguration.new(
16
+ config_path: "config/credentials.yml.enc",
17
+ key_path: "config/master.key",
18
+ env_key: "RAILS_MASTER_KEY",
19
+ raise_if_missing_key: true,
20
+ ).zonesync
7
21
  end
8
22
 
9
23
  class Sync < Struct.new(:source, :destination)
10
- def call
24
+ def call dry_run: false
11
25
  source = Provider.from(self.source)
12
26
  destination = Provider.from(self.destination)
13
27
  operations = Diff.call(from: destination, to: source)
14
28
  operations.each do |method, args|
15
- puts [method, args].inspect
16
- destination.send(method, args)
29
+ Logger.log(method, args, dry_run: dry_run)
30
+ destination.send(method, args) unless dry_run
17
31
  end
18
32
  end
19
33
  end
data/log/.keep ADDED
File without changes
data/zonesync.gemspec CHANGED
@@ -29,6 +29,7 @@ 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
 
33
34
  spec.add_development_dependency "rake"
34
35
  spec.add_development_dependency "rspec"
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.2.0
4
+ version: 0.4.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-28 00:00:00.000000000 Z
12
+ date: 2024-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dns-zonefile
@@ -39,6 +39,20 @@ 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'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rake
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +99,8 @@ description: Sync your Zone file with your DNS host
85
99
  email:
86
100
  - micah@botandrose.com
87
101
  - git@james.ottaway.io
88
- executables: []
102
+ executables:
103
+ - zonesync
89
104
  extensions: []
90
105
  extra_rdoc_files: []
91
106
  files:
@@ -95,13 +110,18 @@ files:
95
110
  - LICENSE.txt
96
111
  - README.md
97
112
  - Rakefile
113
+ - exe/zonesync
98
114
  - lib/zonesync.rb
115
+ - lib/zonesync/cli.rb
99
116
  - lib/zonesync/cloudflare.rb
100
117
  - lib/zonesync/diff.rb
101
118
  - lib/zonesync/http.rb
119
+ - lib/zonesync/logger.rb
102
120
  - lib/zonesync/provider.rb
121
+ - lib/zonesync/rake.rb
103
122
  - lib/zonesync/record.rb
104
123
  - lib/zonesync/version.rb
124
+ - log/.keep
105
125
  - zonesync.gemspec
106
126
  homepage: https://github.com/botandrose/zonesync
107
127
  licenses: