-
Notifications
You must be signed in to change notification settings - Fork 43
Port Cloudflare Updates #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
24d9a70
95b730a
a576027
8d9be98
714f2d9
7bd2819
9369c97
5d35227
55fed2e
e755faf
935253e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.gem | ||
/*.gem | ||
*.lock | ||
.bundle | ||
vendor/gems | ||
/bin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
199.27.128.0/21 | ||
173.245.48.0/20 | ||
103.21.244.0/22 | ||
103.22.200.0/22 | ||
103.31.4.0/22 | ||
141.101.64.0/18 | ||
108.162.192.0/18 | ||
190.93.240.0/20 | ||
188.114.96.0/20 | ||
197.234.240.0/22 | ||
198.41.128.0/17 | ||
162.158.0.0/15 | ||
104.16.0.0/12 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class GitHubPages | ||
class HealthCheck | ||
class CloudFlare | ||
include Singleton | ||
|
||
CONFIG_PATH = File.expand_path("../../config/cloudflare-ips.txt", File.dirname(__FILE__)) | ||
|
||
# Public: Does cloudflare control this address? | ||
def self.controls_ip?(address) | ||
instance.controls_ip?(address) | ||
end | ||
|
||
# Internal: Create a new cloudflare info instance. | ||
def initialize(options = {}) | ||
@path = options.fetch(:path) { CONFIG_PATH } | ||
end | ||
|
||
# Internal: The path of the config file. | ||
attr_reader :path | ||
|
||
# Internal: Does cloudflare control this address? | ||
def controls_ip?(address) | ||
ranges.any? { |range| range.include?(address) } | ||
end | ||
|
||
# Internal: The IP address ranges that cloudflare controls. | ||
def ranges | ||
@ranges ||= load_ranges | ||
end | ||
|
||
# Internal: Load IPAddr ranges from #path | ||
def load_ranges | ||
File.read(path).lines.map { |line| IPAddr.new(line.chomp) } | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class GitHubPages | ||
class HealthCheck | ||
VERSION = '0.0.2' | ||
VERSION = '0.0.3' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash -e | ||
|
||
script/update-cloudflare-ips >/dev/null 2>&1 | ||
|
||
# `git diff --quiet` suppresses output and sets a return code | ||
# 0 - no changes | ||
# 1 - changes | ||
if git diff -w --quiet --cached config/cloudflare-ips.txt | ||
then | ||
echo CloudFlare IP list is up-to-date. | ||
exit 0 | ||
else | ||
echo git reset config/cloudflare-ips.txt | ||
git reset --quiet config/cloudflare-ips.txt | ||
echo '*** CloudFlare IP list is out of date! Run script/update-cloudflare-ips!' | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash -e | ||
#/ Usage script/update-cloudflare-ips | ||
#/ updates config/cloudflare-ips.txt | ||
|
||
source=https://www.cloudflare.com/ips-v4 | ||
dest=config/cloudflare-ips.txt | ||
|
||
echo '====>' Downloading $source | ||
curl --silent --fail $source | tee $dest | ||
echo # cover for a missing newline | ||
|
||
echo '====>' git add $dest | ||
git diff -w $dest | ||
git add --verbose $dest |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
require 'json' | ||
|
||
describe(GitHubPages::HealthCheck::CloudFlare) do | ||
|
||
let(:instance) { GitHubPages::HealthCheck::CloudFlare.instance } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are somewhat fragile. Changes to cloudflare's list are likely to break these specs. If they instead use a custom instance of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great call. Seriously just leveled up my rspec game by reading your tests. Awesome stuff. |
||
|
||
it "loads the IPs" do | ||
expect(instance.ranges.size).to eql(13) | ||
end | ||
|
||
it "detects a cloudflare IP" do | ||
expect(instance.controls_ip?("108.162.196.20")).to be(true) | ||
end | ||
|
||
it "doesn't return false positives" do | ||
expect(instance.controls_ip?("1.1.1.1")).to be(false) | ||
end | ||
|
||
it "works as a singleton" do | ||
expect(GitHubPages::HealthCheck::CloudFlare.controls_ip?("108.162.196.20")).to be(true) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems weird to be in bootstrap. If this is just for CI, maybe move the
boostrap
incibuild
so it's after the env updates?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but without that, it bootstraps into global ruby, which is 1.8.x. Pulled from the Pages bootstrap.