zonesync 0.3.0 → 0.4.1

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: 58c4f6168ca0355c6aa7f0580ede2f8c080b04b44f196a24ecb827b38a3edda8
4
- data.tar.gz: 9064bdd19540cc12d5cc48dfd93cbbb4a940c3e4cb4423255a0f66c9b282287a
3
+ metadata.gz: b070a5e3abcb48ba61c4b751babd7e0cd96bce294de28bebdd2a32af9f0e8104
4
+ data.tar.gz: 0b947cfa076f5ece8f69d093fc3c8512820369f3df2c85ea505517fb6b8aefb0
5
5
  SHA512:
6
- metadata.gz: 3e06ff17f120b42693ca00fd27fcd3c56501bb01abb2b72c9dea149ef8173f3f3f02765767805b03210d6df1a40dee0c84f872d5f07f549ec7ccc95b9d250c6c
7
- data.tar.gz: 8ddf71739ae861c356f27162484e9a1f006e841bbe8900471a1c098046db4287efae357df715b78f60154df7d54e03247892726e8156f68ba8400560951c2147
6
+ metadata.gz: bb90f015f8692698c7a922640cdc0b35e67d0e81298201ff4eda130a8c52cde32cabaf86c7bb10e1d92e7c4365079ebaa9d701933e6d73f79aa0350531ee0287
7
+ data.tar.gz: 3239bb7f0b41cdbd61a4a0c6b0b73d8452ec732eb34deae66ed16788e96a7d66fd4a780bef79a033fd72634e63005445985222f6babd014565ebb89e30958948
data/lib/zonesync/cli.rb CHANGED
@@ -2,28 +2,13 @@ require "thor"
2
2
 
3
3
  module Zonesync
4
4
  class CLI < Thor
5
- def self.exit_on_failure?
6
- true
7
- end
8
-
9
5
  default_command :sync
10
6
  desc "sync", "syncs the contents of Zonefile to the DNS server configured in Rails.application.credentials.zonesync"
11
7
  method_option :dry_run, type: :boolean, default: false, aliases: :n, desc: "log operations to STDOUT but don't perform the sync"
12
8
  def sync
13
- Zonesync.call credentials: default_credentials, dry_run: options[:dry_run]
9
+ Zonesync.call dry_run: options[:dry_run]
14
10
  end
15
11
 
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
12
+ def self.exit_on_failure? = true
28
13
  end
29
14
  end
@@ -35,18 +35,31 @@ module Zonesync
35
35
  @records ||= begin
36
36
  response = http.get(nil)
37
37
  response["result"].reduce({}) do |map, attrs|
38
- map.merge attrs["id"] => Record.new(
39
- attrs["name"] + ".", # normalize to trailing period
40
- attrs["type"],
41
- attrs["ttl"].to_i,
42
- attrs["content"],
43
- ).to_h
44
- end.invert
38
+ map.merge to_record(attrs) => attrs["id"]
39
+ end
45
40
  end
46
41
  end
47
42
 
48
43
  private
49
44
 
45
+ def to_record attrs
46
+ rdata = attrs["content"]
47
+ if %w[CNAME MX].include?(attrs["type"])
48
+ rdata = normalize_trailing_period(rdata)
49
+ end
50
+
51
+ Record.new(
52
+ normalize_trailing_period(attrs["name"]),
53
+ attrs["type"],
54
+ attrs["ttl"].to_i,
55
+ rdata,
56
+ ).to_h
57
+ end
58
+
59
+ def normalize_trailing_period value
60
+ value =~ /\.$/ ? value : value + "."
61
+ end
62
+
50
63
  def http
51
64
  return @http if @http
52
65
  @http = HTTP.new("https://api.cloudflare.com/client/v4/zones/#{credentials[:zone_id]}/dns_records")
@@ -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.3.0"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/zonesync.rb CHANGED
@@ -2,12 +2,24 @@ require "zonesync/provider"
2
2
  require "zonesync/diff"
3
3
  require "zonesync/logger"
4
4
  require "zonesync/cli"
5
+ require "zonesync/rake"
5
6
 
6
7
  module Zonesync
7
- def self.call zonefile: "Zonefile", credentials:, dry_run: false
8
+ def self.call zonefile: "Zonefile", credentials: default_credentials, dry_run: false
8
9
  Sync.new({ provider: "Filesystem", path: zonefile }, credentials).call(dry_run: dry_run)
9
10
  end
10
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
21
+ end
22
+
11
23
  class Sync < Struct.new(:source, :destination)
12
24
  def call dry_run: false
13
25
  source = Provider.from(self.source)
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.3.0
4
+ version: 0.4.1
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-29 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
@@ -118,6 +118,7 @@ files:
118
118
  - lib/zonesync/http.rb
119
119
  - lib/zonesync/logger.rb
120
120
  - lib/zonesync/provider.rb
121
+ - lib/zonesync/rake.rb
121
122
  - lib/zonesync/record.rb
122
123
  - lib/zonesync/version.rb
123
124
  - log/.keep