summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCrae <john.mccrae@progress.com>2022-03-30 15:19:27 -0700
committerGitHub <noreply@github.com>2022-03-30 15:19:27 -0700
commit18d274a881ace4df130239bdc9952f8245e518d5 (patch)
tree751defb32086edef276154a66da92b69ce641361
parent7690c5a138ecdd755920b497cb1970179be3cefe (diff)
parenta8a688763cc6f1615dae8ee60c5ce96f8f0d3115 (diff)
downloadchef-18d274a881ace4df130239bdc9952f8245e518d5.tar.gz
Merge pull request #12724 from DecoyJoe/feature/add-rubygems_url-to-chef_client_config
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb1
-rw-r--r--kitchen-tests/test/integration/end-to-end/_chef_client_config.rb1
-rw-r--r--lib/chef/resource/chef_client_config.rb5
-rw-r--r--lib/chef/resource/support/client.erb1
-rw-r--r--spec/unit/resource/chef_client_config_spec.rb8
5 files changed, 16 insertions, 0 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb
index 31dac49fc6..c0e095a50e 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb
@@ -4,6 +4,7 @@ chef_client_config "Create chef-client's client.rb" do
chef_license "accept"
ohai_optional_plugins %i{Passwd Lspci Sysctl}
ohai_disabled_plugins %i{Sessions Interrupts}
+ rubygems_url "https://rubygems.org/"
additional_config <<~CONFIG
begin
require 'aws-sdk'
diff --git a/kitchen-tests/test/integration/end-to-end/_chef_client_config.rb b/kitchen-tests/test/integration/end-to-end/_chef_client_config.rb
index 4cc1459b7b..60228978c2 100644
--- a/kitchen-tests/test/integration/end-to-end/_chef_client_config.rb
+++ b/kitchen-tests/test/integration/end-to-end/_chef_client_config.rb
@@ -7,5 +7,6 @@ client_rb = if os.windows?
describe file(client_rb) do
its("content") { should match(%r{chef_server_url "https://localhost"}) }
its("content") { should match(/chef_license "accept"/) }
+ its("content") { should match(%r{rubygems_url "https://rubygems.org/"}) }
its("content") { should match(/require 'aws-sdk'/) }
end
diff --git a/lib/chef/resource/chef_client_config.rb b/lib/chef/resource/chef_client_config.rb
index a9b1fa825e..916dbffe7e 100644
--- a/lib/chef/resource/chef_client_config.rb
+++ b/lib/chef/resource/chef_client_config.rb
@@ -208,6 +208,10 @@ class Chef
description: %q(An array of hashes that contain a report handler class and the arguments to pass to that class on initialization. The hash should include `class` and `argument` keys where `class` is a String and `argument` is an array of quoted String values. For example: `[{'class' => 'MyHandler', %w('"argument1"', '"argument2"')}]`),
default: []
+ property :rubygems_url, [String, Array],
+ description: "The location to source rubygems. It can be set to a string or array of strings for URIs to set as rubygems sources. This allows individuals to setup an internal mirror of rubygems for “airgapped” environments.",
+ introduced: "17.11"
+
property :exception_handlers, Array,
description: %q(An array of hashes that contain a exception handler class and the arguments to pass to that class on initialization. The hash should include `class` and `argument` keys where `class` is a String and `argument` is an array of quoted String values. For example: `[{'class' => 'MyHandler', %w('"argument1"', '"argument2"')}]`),
default: []
@@ -295,6 +299,7 @@ class Chef
policy_group: new_resource.policy_group,
policy_name: new_resource.policy_name,
report_handlers: format_handler(new_resource.report_handlers),
+ rubygems_url: new_resource.rubygems_url,
ssl_verify_mode: new_resource.ssl_verify_mode,
start_handlers: format_handler(new_resource.start_handlers),
additional_config: new_resource.additional_config,
diff --git a/lib/chef/resource/support/client.erb b/lib/chef/resource/support/client.erb
index 8e96ca49e2..724adc9325 100644
--- a/lib/chef/resource/support/client.erb
+++ b/lib/chef/resource/support/client.erb
@@ -18,6 +18,7 @@
@pid_file
@policy_group
@policy_name
+ @rubygems_url
@ssl_verify_mode
@policy_persist_run_list).each do |prop| -%>
<% next if instance_variable_get(prop).nil? || instance_variable_get(prop).empty? -%>
diff --git a/spec/unit/resource/chef_client_config_spec.rb b/spec/unit/resource/chef_client_config_spec.rb
index 7e6d7a5c5c..a7d1152e3d 100644
--- a/spec/unit/resource/chef_client_config_spec.rb
+++ b/spec/unit/resource/chef_client_config_spec.rb
@@ -134,4 +134,12 @@ describe Chef::Resource::ChefClientConfig do
expect(provider.format_handler([{ "class" => "Foo", "arguments" => ["'one'", "two", "three"] }])).to eql(["Foo.new('one',two,three)"])
end
end
+
+ describe "rubygems_url property" do
+ it "accepts nil, a single URL, or an array of URLs" do
+ expect { resource.rubygems_url(nil) }.not_to raise_error
+ expect { resource.rubygems_url("https://rubygems.internal.example.com") }.not_to raise_error
+ expect { resource.rubygems_url(["https://rubygems.east.example.com", "https://rubygems.west.example.com"]) }.not_to raise_error
+ end
+ end
end