Skip to content

Commit

Permalink
Merge tonsky#253
Browse files Browse the repository at this point in the history
253: Add config to ignore Gemfile source r=bronzdoc a=ericzpd

This PR adds `:ignore_gemfile_source` config to ignore source specified in Gemfile and always use `:rubygems_url` as gems upstream.

Valid config values: `true` or `false`.

This change allows Gemstash to use a Bundler mirror site for fetching remote gems, instead of fetching from Gemfile source. 

Related Issue: tonsky#252 

Co-authored-by: Zheng Piaodan <zhengpiaodan@gmail.com>
  • Loading branch information
bundlerbot[bot] and zhengpd authored Feb 20, 2020
2 parents 1e43793 + 46b7d74 commit ab6b67c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/gemstash-configuration.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ already gems stashed for the previous value.

A valid gem source URL

# Ignore Gemfile source

`:ignore_gemfile_source`

Ignore the source specified in Gemfile and always use `:rubygems_url` as gems upstream.

## Default value

`false`

## Valid values

Boolean: `true` or `false`

# Puma Threads

`:puma_threads`
Expand Down
1 change: 1 addition & 0 deletions lib/gemstash/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Configuration
db_adapter: "sqlite3",
bind: "tcp://0.0.0.0:9292",
rubygems_url: "https://rubygems.org",
ignore_gemfile_source: false,
protected_fetch: false,
fetch_timeout: 20,
# Actual default for db_connection_options is dynamic based on the adapter
Expand Down
2 changes: 1 addition & 1 deletion lib/gemstash/gem_source/upstream_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def fetch_remote_gem(gem_name, gem_resource, resource_type)
# default upstream).
class RubygemsSource < Gemstash::GemSource::UpstreamSource
def self.matches?(env)
env["gemstash.upstream"] = if env["HTTP_X_GEMFILE_SOURCE"].to_s.empty?
env["gemstash.upstream"] = if env["gemstash.env"].config[:ignore_gemfile_source] || env["HTTP_X_GEMFILE_SOURCE"].to_s.empty?
env["gemstash.env"].config[:rubygems_url]
else
env["HTTP_X_GEMFILE_SOURCE"]
Expand Down
15 changes: 15 additions & 0 deletions man/gemstash-configuration.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gemstash-configuration
:test: true
:pool_timeout: 2
:rubygems_url: https://my.gem-source.local
:ignore_gemfile_source: false
:puma_threads: 32
:bind: tcp://0.0.0.0:4242
:protected_fetch: true
Expand Down Expand Up @@ -147,6 +148,20 @@ for the previous value.

A valid gem source URL

# Ignore Gemfile source

`:ignore_gemfile_source`

Ignore the source specified in Gemfile and always use `:rubygems_url` as gems upstream.

## Default value

`false`

## Valid values

Boolean: `true` or `false`

# Puma Threads

`:puma_threads`
Expand Down
28 changes: 28 additions & 0 deletions spec/gemstash/gem_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@
end
end

context "ignoring an upstream defined in a header" do
let(:env) do
config = Gemstash::Configuration.new(config: { ignore_gemfile_source: true })
current_env = Gemstash::Env.new(config)

{
"gemstash.env" => current_env,
"REQUEST_URI" => "/some/path?arg=abc",
"PATH_INFO" => "/some/path",
"HTTP_X_GEMFILE_SOURCE" => upstream_url
}
end

let(:upstream_url) { "https://some.gemsite.com" }
let(:default_upstream_url) { "https://rubygems.org" }
let(:result) { double }

it "sets the source to RubygemsSource" do
expect(app).to receive(:call).with(env).and_return(result)
expect(middleware.call(env)).to eq(result)
expect(env["gemstash.gem_source"]).to eq(Gemstash::GemSource::RubygemsSource)
expect(env["gemstash.upstream"]).to eq(default_upstream_url)
expect(env["REQUEST_URI"]).to eq("/some/path?arg=abc")
expect(env["PATH_INFO"]).to eq("/some/path")
expect(the_log).to_not include("Rewriting ")
end
end

context "using the default upstream" do
let(:env) do
{
Expand Down

0 comments on commit ab6b67c

Please sign in to comment.