Skip to content

Commit b91af9d

Browse files
Update to use puppetcore
Also adds an integration test to verify that the puppetcore gems are indeed being used. Signed-off-by: Gavin Didrichsen <[email protected]>
1 parent cbde9ad commit b91af9d

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

Gemfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@ facter_version = ENV['FACTER_GEM_VERSION']
5252
hiera_version = ENV['HIERA_GEM_VERSION']
5353

5454
gems = {}
55+
puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil)
56+
facter_version = ENV.fetch('FACTER_GEM_VERSION', nil)
57+
hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil)
5558

56-
gems['puppet'] = location_for(puppet_version)
57-
58-
# If facter or hiera versions have been specified via the environment
59-
# variables
59+
# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
60+
# Otherwise, do as before and use location_for to fetch gems from the default source
61+
if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty?
62+
gems['puppet'] = [puppet_version || '~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
63+
gems['facter'] = [facter_version || '~> 4.0', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
64+
else
65+
gems['puppet'] = location_for(puppet_version)
66+
gems['facter'] = location_for(facter_version) if facter_version
67+
end
6068

61-
gems['facter'] = location_for(facter_version) if facter_version
6269
gems['hiera'] = location_for(hiera_version) if hiera_version
6370

6471
gems.each do |gem_name, gem_params|

spec/integration/puppetcore_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'bundler'
5+
6+
RSpec.describe 'Gemfile.lock verification' do
7+
let(:parser) { Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile)) }
8+
let(:private_source) { 'https://rubygems-puppetcore.puppet.com/' }
9+
10+
# Helper method to get source remotes for a specific gem
11+
def get_gem_source_remotes(gem_name)
12+
spec = parser.specs.find { |s| s.name == gem_name }
13+
return [] unless spec
14+
15+
source = spec.source
16+
return [] unless source.is_a?(Bundler::Source::Rubygems)
17+
18+
source.remotes.map(&:to_s)
19+
end
20+
21+
context 'when the environment is configured with a valid PUPPET_FORGE_TOKEN' do
22+
it 'returns puppet from puppetcore' do
23+
remotes = get_gem_source_remotes('puppet')
24+
expect(remotes).to eq([private_source]),
25+
"Expected puppet to come from puppetcore, got: #{remotes.join(', ')}"
26+
end
27+
28+
it 'returns facter from puppetcore' do
29+
remotes = get_gem_source_remotes('facter')
30+
expect(remotes).to eq([private_source]),
31+
"Expected facter to come from puppetcore, got: #{remotes.join(', ')}"
32+
end
33+
34+
it 'has PUPPET_FORGE_TOKEN set' do
35+
expect(ENV.fetch('PUPPET_FORGE_TOKEN', nil)).not_to be_nil,
36+
'Expected PUPPET_FORGE_TOKEN to be set'
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)