summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Larionov <jlarionov@webmd.net>2022-03-25 13:09:24 -0700
committerJoseph Larionov <jlarionov@webmd.net>2022-06-07 09:29:40 -0700
commite6df8e887e702d2a581d31f5f657c7c39e09b8a4 (patch)
treec045b6502fe4a0ff8b51d324fe1cf18d242b8bf3
parent114e538e7ac1533729d2118861a3a0447be89b79 (diff)
downloadchef-e6df8e887e702d2a581d31f5f657c7c39e09b8a4.tar.gz
Add rubygems_url property to chef_client_config resource
Signed-off-by: Joseph Larionov <jlarionov@webmd.net>
-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 c2a6e4254b..33ff249b8f 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
@@ -3,6 +3,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 df97d7cc2f..ea41f46ae7 100644
--- a/lib/chef/resource/chef_client_config.rb
+++ b/lib/chef/resource/chef_client_config.rb
@@ -209,6 +209,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: []
@@ -297,6 +301,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 771c715ba2..90638034fd 100644
--- a/lib/chef/resource/support/client.erb
+++ b/lib/chef/resource/support/client.erb
@@ -16,6 +16,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