doh_client 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c31280c85539525b4474898248ed44f33f65c93f7034192dace9f007ab3093fb
4
+ data.tar.gz: 3cad406e40224d755df4e0034a51fca19f828d492280f69635db723e7fa8b2ec
5
+ SHA512:
6
+ metadata.gz: 633d2b12ed9ef98110b6f2a5bf5847030f845bd8c08058ac0717d96d2644357759e481741c60eb194af830906abf8d9b1759e8db97522f9a5e99d4ac1a575dae
7
+ data.tar.gz: 40db845a5a5bb9869a61a28164031e73290011d098c3cd47350ab449341ce258bc1c2335176d7a16e153b0649c9e274c56a4bbb893687c3ebc6657ed19c1eb93
data/.gitignore ADDED
@@ -0,0 +1,53 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+
53
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5
7
+ before_install: gem install bundler -v 1.16.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in doh_client.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Manabu Niseki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # doh_client
2
+
3
+ [![Build Status](https://travis-ci.org/ninoseki/doh_client.svg?branch=master)](https://travis-ci.org/ninoseki/doh_client)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e9119ee2021f1cfb895d/maintainability)](https://codeclimate.com/github/ninoseki/doh_client/maintainability)
5
+ [![Coverage Status](https://coveralls.io/repos/github/ninoseki/doh_client/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/doh_client?branch=master)
6
+
7
+ DNS over HTTPS(DoH) client for Ruby
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'doh_client'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install doh_client
24
+
25
+ ## Supported platforms
26
+
27
+ - [Google Public DNS](https://developers.google.com/speed/public-dns/docs/dns-over-https)
28
+ - [Cloudflare](https://developers.cloudflare.com/1.1.1.1/dns-over-https/)
29
+
30
+ ## Usage
31
+
32
+ ### As a Library
33
+
34
+ ```rb
35
+ require 'doh_client'
36
+
37
+ DoHClient::Google.resolve("example.com", { type: "A" })
38
+ DoHClient::Google.resolve("example.com", { type: "A", edns_client_subnet: "0.0.0.0/0", random_padding: "XmkMw~o_mgP2pf.gpw-Oi5dK" })
39
+
40
+ DoHClient::Cloudflare.resolve("example.com", { type: "A" })
41
+ DoHClient::Cloudflare.resolve("example.com", { type: "A", do: true, cd: false })
42
+ ```
43
+
44
+ ### As a CLI
45
+
46
+ ```bash
47
+ $ doh_client
48
+ Commands:
49
+ console help [COMMAND] # Describe available commands or one specific command
50
+ console resolve [NAME] # resolve a given name
51
+
52
+ Options:
53
+ [--resolver=RESOLVER] # a resolver to use ('google' or 'cloudflare', default: google)
54
+
55
+ $ doh_client resolve example.com --type A
56
+ # => {"Status":0,"TC":false,"RD":true,"RA":true,"AD":true,"CD":false,"Question":[{"name":"example.com.","type":1}],"Answer":[{"name":"example.com.","type":1,"TTL":5169,"data":"93.184.216.34"}]}
57
+ ```
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "doh_client"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "doh_client/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "doh_client"
9
+ spec.version = DoHClient::VERSION
10
+ spec.authors = ["Manabu Niseki"]
11
+ spec.email = ["manabu.niseki@gmail.com"]
12
+
13
+ spec.summary = "DNS over HTTPS(DoH) client for Ruby"
14
+ spec.description = "DNS over HTTPS(DoH) client for Ruby"
15
+ spec.homepage = "https://github.com/ninoseki/doh_client"
16
+ spec.license = "MIT"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "coveralls", "~> 0.8"
29
+ spec.add_development_dependency "rake", "~> 12.3"
30
+ spec.add_development_dependency "rspec", "~> 3.8"
31
+ spec.add_development_dependency "vcr", "~> 4.0"
32
+ spec.add_development_dependency "webmock", "~> 3.4"
33
+
34
+ spec.add_dependency "http", "~> 3.3"
35
+ spec.add_dependency "thor", "~> 0.19"
36
+ end
data/lib/doh_client.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "doh_client/version"
4
+ require "doh_client/error"
5
+
6
+ require "doh_client/client/request"
7
+ require "doh_client/client/base"
8
+ require "doh_client/client/cloudflare"
9
+ require "doh_client/client/google"
10
+
11
+ require "doh_client/cli"
12
+
13
+ module DoHClient
14
+ # Your code goes here...
15
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "json"
5
+
6
+ module DoHClient
7
+ class CLI < Thor
8
+ class_option :resolver, type: :string, desc: "a resolver to use ('google' or 'cloudflare', default: google)"
9
+
10
+ desc "resolve [NAME]", "resolve a given name"
11
+ method_option :type, type: :string, default: "A"
12
+ method_option :cd, type: :boolean
13
+ method_option :do, type: :boolean
14
+ method_option :edns_client_subnet, type: :string
15
+ method_option :random_padding, type: :string
16
+ def resolve(name)
17
+ hash = resolver.resolve(name, options)
18
+ puts hash.to_json
19
+ end
20
+
21
+ no_commands do
22
+ def resolver
23
+ case options[:resolver]
24
+ when "google"
25
+ DoHClient::Client::Google
26
+ when "cloudflare"
27
+ DoHClient::Client::Cloudflare
28
+ else
29
+ DoHClient::Client::Google
30
+ end
31
+ end
32
+
33
+ def with_error_handling
34
+ yield
35
+ rescue ResponseError => e
36
+ puts "Warning: #{e}"
37
+ rescue ArgumentError => _
38
+ puts "Warning: #{e}"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "http"
5
+
6
+ module DoHClient
7
+ module Client
8
+ class Base
9
+ def resolve(name, options)
10
+ query = build_query(name, options)
11
+ validate(query)
12
+ Request.get(endpoint, query)
13
+ end
14
+
15
+ def self.resolve(name, options)
16
+ new.resolve(name, options)
17
+ end
18
+
19
+ def endpoint
20
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
21
+ end
22
+
23
+ def build_query
24
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
25
+ end
26
+
27
+ def validate(query)
28
+ raise ArgumentError, "name is a required parameter" if query[:name].nil?
29
+ raise ArgumentError, "type is a required parameter" if query[:type].nil?
30
+ raise ArgumentError, "cd must be a boolean value" if query[:cd] && !boolean?(query[:cd])
31
+ end
32
+
33
+ private
34
+
35
+ def boolean?(param)
36
+ [true, false].include? param
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoHClient
4
+ module Client
5
+ class Cloudflare < Base
6
+ def endpoint
7
+ "https://cloudflare-dns.com/dns-query"
8
+ end
9
+
10
+ def build_query(name, options)
11
+ {
12
+ name: name,
13
+ type: options[:type],
14
+ cd: options[:cd],
15
+ do: options[:do]
16
+ }.compact
17
+ end
18
+
19
+ def validate(query)
20
+ super(query)
21
+ raise ArgumentError, "do must be a boolean value" if query[:do] && !boolean?(query[:do])
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoHClient
4
+ module Client
5
+ class Google < Base
6
+ def endpoint
7
+ "https://dns.google.com/resolve"
8
+ end
9
+
10
+ def build_query(name, options)
11
+ {
12
+ name: name,
13
+ type: options[:type],
14
+ cd: options[:cd],
15
+ edns_client_subnet: options[:edns_client_subnet],
16
+ random_padding: options[:random_padding]
17
+ }.compact
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoHClient
4
+ module Client
5
+ class Request
6
+ def get(url, query)
7
+ res = http.headers(headers).get(url, params: query);
8
+ return JSON.parse(res.body.to_s) if res.code == 200
9
+ raise ResponseError, res.body.to_s
10
+ end
11
+
12
+ def self.get(url, query)
13
+ new.get(url, query);
14
+ end
15
+
16
+ def headers
17
+ {
18
+ accept: "application/dns-json",
19
+ user_agent: "curl/7.54.0"
20
+ }
21
+ end
22
+
23
+ def http
24
+ if proxy = ENV["HTTPS_RPOXY"] || ENV["https_proxy"]
25
+ uri = URI(proxy)
26
+ HTTP.via(uri.hostname, uri.port)
27
+ else
28
+ HTTP
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoHClient
4
+ class ResponseError < StandardError; end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoHClient
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doh_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Niseki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: http
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.19'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.19'
125
+ description: DNS over HTTPS(DoH) client for Ruby
126
+ email:
127
+ - manabu.niseki@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - doh_client.gemspec
142
+ - lib/doh_client.rb
143
+ - lib/doh_client/cli.rb
144
+ - lib/doh_client/client/base.rb
145
+ - lib/doh_client/client/cloudflare.rb
146
+ - lib/doh_client/client/google.rb
147
+ - lib/doh_client/client/request.rb
148
+ - lib/doh_client/error.rb
149
+ - lib/doh_client/version.rb
150
+ homepage: https://github.com/ninoseki/doh_client
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.7.6
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: DNS over HTTPS(DoH) client for Ruby
174
+ test_files: []