File tree Expand file tree Collapse file tree 2 files changed +51
-5
lines changed Expand file tree Collapse file tree 2 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,20 @@ facter_version = ENV['FACTER_GEM_VERSION']
52
52
hiera_version = ENV [ 'HIERA_GEM_VERSION' ]
53
53
54
54
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 )
55
58
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
60
68
61
- gems [ 'facter' ] = location_for ( facter_version ) if facter_version
62
69
gems [ 'hiera' ] = location_for ( hiera_version ) if hiera_version
63
70
64
71
gems . each do |gem_name , gem_params |
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments