-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
24d9a70
port cloudflare class
benbalter 95b730a
version bump
benbalter a576027
add list tooling
benbalter 8d9be98
bootstrap before building
benbalter 714f2d9
vendor :gem:s
benbalter 7bd2819
add cloudflare to gemspec
benbalter 9369c97
set ruby version
benbalter 5d35227
moar bootstrapping
benbalter 55fed2e
local rspec
benbalter e755faf
moar bootstrap
benbalter 935253e
smarter tests that dont rely on real cloudflare IPs
benbalter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.gem | ||
/*.gem | ||
*.lock | ||
.bundle | ||
vendor/gems | ||
/bin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'spec_helper' | ||
require 'json' | ||
require 'tempfile' | ||
require 'ipaddr' | ||
|
||
describe(GitHubPages::HealthCheck::CloudFlare) do | ||
|
||
let(:instance) { GitHubPages::HealthCheck::CloudFlare.send(:new, :path => ipaddr_path) } | ||
let(:tempfile) { Tempfile.new("pages-jekyll-alarmist-cloudflare-ips").tap { |f| f.sync = true } } | ||
let(:ipaddr_path) { tempfile.path } | ||
|
||
context "default" do | ||
let(:instance) { GitHubPages::HealthCheck::CloudFlare.instance } | ||
|
||
it "loads the default config" do | ||
path = File.expand_path(instance.path) | ||
expected = File.expand_path("../config/cloudflare-ips.txt", File.dirname(__FILE__)) | ||
expect(path).to eql(expected) | ||
end | ||
end | ||
|
||
context "no config file" do | ||
before { tempfile.unlink } | ||
|
||
it "raises an error" do | ||
expect { instance.ranges }.to raise_error | ||
end | ||
end | ||
|
||
context "parses config" do | ||
before { tempfile.write("199.27.128.0/21\n173.245.48.0/20") } | ||
|
||
it "has two IPs" do | ||
expect(instance.ranges.size).to eql(2) | ||
end | ||
|
||
it "loads the IP addresses" do | ||
expect(instance.ranges).to include(IPAddr.new("199.27.128.0/21")) | ||
expect(instance.ranges).to include(IPAddr.new("173.245.48.0/20")) | ||
end | ||
|
||
it("controls? 199.27.128.55") { expect(instance.controls_ip?(IPAddr.new("199.27.128.55"))).to be_truthy } | ||
it("controls? 173.245.48.55") { expect(instance.controls_ip?(IPAddr.new("173.245.48.55"))).to be_truthy } | ||
it("controls? 200.27.128.55") { expect(instance.controls_ip?(IPAddr.new("200.27.128.55"))).to be_falsey } | ||
end | ||
|
||
it "works as a singleton" do | ||
expect(GitHubPages::HealthCheck::CloudFlare.controls_ip?("108.162.196.20")).to be(true) | ||
end | ||
end |
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.