8000 Allow disabling of all network accesses by ibbem · Pull Request #285 · jekyll/github-metadata · GitHub
[go: up one dir, main page]

Skip to content

Allow disabling of all network accesses #285

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 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Some `site.github` values can be overridden by environment variables.
- `PAGES_GITHUB_HOSTNAME` – the `site.github.hostname` (default: `github.com`)
- `PAGES_PAGES_HOSTNAME` – the `site.github.pages_hostname` (default: `github.io`)
- `NO_NETRC` – set if you don't want the fallback to `~/.netrc`
- `PAGES_DISABLE_NETWORK` – set to prevent all network accesses (disables features that need to access the GitHub API)

## Using with GitHub Enterprise

Expand Down
20 changes: 12 additions & 8 deletions lib/jekyll-github-metadata/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,19 @@ def authenticated?
def internet_connected?
return @internet_connected if defined?(@internet_connected)

require "resolv"
begin
Resolv::DNS.open do |dns|
dns.timeouts = 2
dns.getaddress("api.github.com")
end
@internet_connected = true
rescue Resolv::ResolvError
if ENV["PAGES_DISABLE_NETWORK"]
@internet_connected = false
else
require "resolv"
begin
Resolv::DNS.open do |dns|
dns.timeouts = 2
dns.getaddress("api.github.com")
end
@internet_connected = true
rescue Resolv::ResolvError
@internet_connected = false
end
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@
subject.contributors("jekyll/github-metadata")
end.to raise_error(described_class::BadCredentialsError)
end

it "supresses network accesses if requested" do
WebMock.disable_net_connect!

with_env("PAGES_DISABLE_NETWORK", "1") do
expect(subject.contributors("jekyll/github-metadata")).to be(false)
end
end

it "allows network accesses by default" do
WebMock.disable_net_connect!

expect do
subject.contributors("jekyll/github-metadata")
end.to raise_error(WebMock::NetConnectNotAllowedError)
end
end
0