ddig 0.3.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: f89a50e96e5fb9468cb699e1f034c999ee1e063441d70a95e17aa2bb93b57878
4
- data.tar.gz: fd2c8ede252e8b56756f0e5859f999aa3dadff4016bf005b41dbe388a291ff0d
3
+ metadata.gz: d93fb27dc9867081364927eec31f893777d413c599ec112c563ef071c11d3e4e
4
+ data.tar.gz: 190b3a707eb4f844e60e8b47ec498a7c10c98338ad3d686371e7fd3e59c08e68
5
5
  SHA512:
6
- metadata.gz: 44f6e9dd26e26964dd52d0ce0b9e94e60d66b9a9b1c4d7299ec49b130c20465e3a413058860895d272f89dec80108b8b9e6cde75236ba04c63b3207f536a783e
7
- data.tar.gz: 19d7a1c4e7660b8cbb0f4aa5d7e4e10ac32a8c1b817e15646161d948e342c700b8c0de36cb931e70ded9cede816edbefb82f82dd57ae86c6026e1b3b6e6e9048
6
+ metadata.gz: 0655d40f0f9971c9b324e768c2f27cb2ee8536b2869681c5c084f37726d5d04e40c0b525e2eab2230daf27af661778d5f23b33cf00e77012613d0eff279cc5d2
7
+ data.tar.gz: 56f7054def0155579a087e1d16aa1755c5b8fb84d03581807d37b3914d02b9c5d9d9c0de600acf136c09febd68ed9c850ad811d953fb2306a1b80e1df2cb512f
data/lib/ddig/cli.rb CHANGED
@@ -86,7 +86,8 @@ module Ddig
86
86
  @ddig = Ddig.lookup(@hostname, nameservers: @options[:nameserver], use_ipv4: @use_ipv4, use_ipv6: @use_ipv6)
87
87
 
88
88
  if @options[:format] == 'json'
89
- # TODO: to_json
89
+ puts @ddig.to_json
90
+
90
91
  else
91
92
  unless @ddig[:do53][:ipv4].nil?
92
93
  puts "# Do53 (IPv4)"
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module Ddig
2
4
  class Ddr
3
5
  class DesignatedResolver
@@ -61,6 +63,27 @@ module Ddig
61
63
  end
62
64
  end
63
65
 
66
+ def as_json(*)
67
+ {
68
+ unencrypted_resolver: @unencrypted_resolver,
69
+ target: @target,
70
+ protocol: @protocol,
71
+ port: @port,
72
+ dohpath: @dohpath,
73
+ address: @address,
74
+ ip: @ip,
75
+ verify: @verify_cert&.verify,
76
+ hostname: @hostname,
77
+ a: @a,
78
+ aaaa: @aaaa,
79
+ errors: @errors,
80
+ }
81
+ end
82
+
83
+ def to_json(*args)
84
+ as_json.to_json
85
+ end
86
+
64
87
  def to_cli
65
88
  @resolver.to_cli
66
89
  end
@@ -77,9 +100,7 @@ module Ddig
77
100
  # ref: https://www.rfc-editor.org/rfc/rfc9461.html#section-4.2
78
101
  def set_default_port
79
102
  case @protocol
80
- when 'http/1.1'
81
- @port = 80
82
- when 'h2', 'h3'
103
+ when 'http/1.1', 'h2', 'h3'
83
104
  @port = 443
84
105
  when 'dot', 'doq'
85
106
  @port = 853
data/lib/ddig/ddr.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'resolv'
2
+ require 'json'
2
3
 
3
4
  require_relative "ddr/verify_cert"
4
5
  require_relative "ddr/designated_resolver"
@@ -129,6 +130,19 @@ module Ddig
129
130
  end
130
131
  end
131
132
 
133
+ def as_json(*)
134
+ {
135
+ designated_resolvers: @designated_resolvers.map { |designated_resolver| designated_resolver.as_json },
136
+ hostname: @hostname,
137
+ nameservers: @nameservers,
138
+ ip: @ip,
139
+ }
140
+ end
141
+
142
+ def to_json(*args)
143
+ as_json.to_json
144
+ end
145
+
132
146
  def to_cli
133
147
  @designated_resolvers.each do |designated_resolver|
134
148
  puts designated_resolver.to_s
@@ -1,4 +1,5 @@
1
1
  require 'resolv'
2
+ require 'json'
2
3
 
3
4
  module Ddig
4
5
  module Resolver
@@ -33,6 +34,20 @@ module Ddig
33
34
  self
34
35
  end
35
36
 
37
+ def as_json(*)
38
+ {
39
+ a: @a,
40
+ aaaa: @aaaa,
41
+ hostname: @hostname,
42
+ nameservers: @nameservers,
43
+ ip: @ip,
44
+ }
45
+ end
46
+
47
+ def to_json(*args)
48
+ as_json.to_json
49
+ end
50
+
36
51
  def to_cli
37
52
  @a.each do |address|
38
53
  rr_type = 'A'
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'resolv'
3
3
  require 'base64'
4
+ require 'json'
4
5
 
5
6
  require_relative 'dns_message'
6
7
 
@@ -57,6 +58,22 @@ module Ddig
57
58
  end
58
59
  end
59
60
 
61
+ def as_json(*)
62
+ {
63
+ a: @a,
64
+ aaaa: @aaaa,
65
+ hostname: @hostname,
66
+ server: @server,
67
+ address: @address,
68
+ dohpath: @dohpath,
69
+ port: @port,
70
+ }
71
+ end
72
+
73
+ def to_json(*args)
74
+ as_json.to_json
75
+ end
76
+
60
77
  def to_cli
61
78
  @a.each do |address|
62
79
  rr_type = 'A'
@@ -1,5 +1,6 @@
1
1
  require 'openssl'
2
2
  require 'resolv'
3
+ require 'json'
3
4
 
4
5
  require_relative 'dns_message'
5
6
 
@@ -75,6 +76,21 @@ module Ddig
75
76
  end
76
77
  end
77
78
 
79
+ def as_json(*)
80
+ {
81
+ a: @a,
82
+ aaaa: @aaaa,
83
+ hostname: @hostname,
84
+ server: @server,
85
+ server_name: @server_name,
86
+ port: @port,
87
+ }
88
+ end
89
+
90
+ def to_json(*args)
91
+ as_json.to_json
92
+ end
93
+
78
94
  def to_cli
79
95
  @a.each do |address|
80
96
  rr_type = 'A'
data/lib/ddig/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ddig
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taketo Takashima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-13 00:00:00.000000000 Z
11
+ date: 2024-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resolv
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.5.3
89
+ rubygems_version: 3.5.11
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: DNS lookup utility for Ruby