github-pages-health-check 0.2.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/lib/github-pages-health-check.rb +39 -14
- data/lib/github-pages-health-check/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8f1167cce6a19b07422bbb5375ff71b4fa78e01
|
4
|
+
data.tar.gz: 35a439eed34572584c770fc396082e1e82f8f0c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58afef1dd71269fc7190cbd8cadbff2e68f24ba23a49b10743151fd010d5fffef2c75b0f92f3c75d42ba8456d9257ced78b9462260bd489fb3a5e069d9bebb24
|
7
|
+
data.tar.gz: 0db8e4e38545e1a825d310c7994a66fa4bbd6c88f9d8e55fd5676c46763791b49b1ed9aa26580047660361b3601a4f1bfa729a869bfd15dd379dd8c977f17173
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
1
|
+
require "net/dns"
|
2
|
+
require "net/dns/resolver"
|
3
|
+
require "ipaddr"
|
4
|
+
require "public_suffix"
|
5
|
+
require "singleton"
|
6
|
+
require "net/http"
|
7
|
+
require_relative "github-pages-health-check/version"
|
8
|
+
require_relative "github-pages-health-check/cloudflare"
|
9
|
+
require_relative "github-pages-health-check/error"
|
10
|
+
require_relative "github-pages-health-check/errors/deprecated_ip"
|
11
|
+
require_relative "github-pages-health-check/errors/invalid_a_record"
|
12
|
+
require_relative "github-pages-health-check/errors/invalid_cname"
|
13
|
+
require_relative "github-pages-health-check/errors/not_served_by_pages"
|
14
14
|
|
15
15
|
class GitHubPages
|
16
16
|
class HealthCheck
|
@@ -23,6 +23,11 @@ class GitHubPages
|
|
23
23
|
199.27.73.133
|
24
24
|
]
|
25
25
|
|
26
|
+
CURRENT_IP_ADDRESSES = %w[
|
27
|
+
192.30.252.153
|
28
|
+
192.30.252.154
|
29
|
+
]
|
30
|
+
|
26
31
|
def initialize(domain)
|
27
32
|
@domain = domain
|
28
33
|
end
|
@@ -33,7 +38,7 @@ class GitHubPages
|
|
33
38
|
|
34
39
|
# Returns an array of DNS answers
|
35
40
|
def dns
|
36
|
-
@dns ||= without_warnings { Net::DNS::Resolver.start(
|
41
|
+
@dns ||= without_warnings { Net::DNS::Resolver.start(absolute_domain).answer } if domain
|
37
42
|
rescue Exception
|
38
43
|
false
|
39
44
|
end
|
@@ -76,6 +81,11 @@ class GitHubPages
|
|
76
81
|
dns.first.class == Net::DNS::RR::CNAME && pages_domain?(dns.first.cname.to_s)
|
77
82
|
end
|
78
83
|
|
84
|
+
# Is the domain's first response an A record to a valid GitHub Pages IP?
|
85
|
+
def pointed_to_github_pages_ip?
|
86
|
+
dns.first.class == Net::DNS::RR::A && CURRENT_IP_ADDRESSES.include?(dns.first.value)
|
87
|
+
end
|
88
|
+
|
79
89
|
# Is the given cname a pages domain?
|
80
90
|
#
|
81
91
|
# domain - the domain to check, generaly the target of a cname
|
@@ -98,6 +108,7 @@ class GitHubPages
|
|
98
108
|
:apex_domain? => apex_domain?,
|
99
109
|
:should_be_a_record? => should_be_a_record?,
|
100
110
|
:pointed_to_github_user_domain? => pointed_to_github_user_domain?,
|
111
|
+
:pointed_to_github_pages_ip? => pointed_to_github_pages_ip?,
|
101
112
|
:pages_domain? => pages_domain?,
|
102
113
|
:served_by_pages? => served_by_pages?,
|
103
114
|
:valid? => valid?,
|
@@ -109,6 +120,12 @@ class GitHubPages
|
|
109
120
|
scheme = github_domain? ? "https" : "http"
|
110
121
|
uri = URI("#{scheme}://#{domain}")
|
111
122
|
response = Net::HTTP.get_response(uri)
|
123
|
+
if response.is_a? Net::HTTPRedirection
|
124
|
+
for t in 1..3
|
125
|
+
response = Net::HTTP.get_response(uri)
|
126
|
+
break if response.is_a? Net::HTTPSuccess
|
127
|
+
end
|
128
|
+
end
|
112
129
|
response.to_hash["server"] == ["GitHub.com"]
|
113
130
|
rescue
|
114
131
|
false
|
@@ -165,5 +182,13 @@ class GitHubPages
|
|
165
182
|
$VERBOSE = warn_level
|
166
183
|
result
|
167
184
|
end
|
185
|
+
|
186
|
+
# Adjust `domain` so that it won't be searched for with /etc/resolv.conf's search rules.
|
187
|
+
#
|
188
|
+
# GitHubPages::HealthCheck.new("anything.io").absolute_domain
|
189
|
+
# => "anything.io."
|
190
|
+
def absolute_domain
|
191
|
+
domain.end_with?(".") ? domain : "#{domain}."
|
192
|
+
end
|
168
193
|
end
|
169
194
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-pages-health-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-dns
|