From b731df4d74cc510d16d5db15ba54ab13fbf14373 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Wed, 3 May 2023 12:34:20 -0600 Subject: feat(apt_repository): Allow specifying arbitrary options (#13728) This allows specifying additional options to apt repositories, in addition to `trusted` and `arch`. By using an array of strings we also allow using multivalue operators like -= and += Fixes: #13727 Signed-off-by: Thayne McCombs --- lib/chef/resource/apt_repository.rb | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/chef/resource/apt_repository.rb b/lib/chef/resource/apt_repository.rb index 7e2ced5c92..5ea3b31a75 100644 --- a/lib/chef/resource/apt_repository.rb +++ b/lib/chef/resource/apt_repository.rb @@ -98,6 +98,18 @@ class Chef end ``` + **Add repository that needs custom options**: + ```ruby + apt_repository 'corretto' do + uri 'https://apt.corretto.aws' + arch 'amd64' + distribution 'stable' + components ['main'] + options ['target-=Contents-deb'] + key 'https://apt.corretto.aws/corretto.key' + end + ``` + **Remove a repository from the list**: ```ruby @@ -159,6 +171,10 @@ class Chef description: "Determines whether to rebuild the APT package cache.", default: true, desired_state: false + property :options, [String, Array], + description: "Additional options to set for the repository", + default: [], coerce: proc { |x| Array(x) } + default_action :add allowed_actions :add, :remove @@ -388,19 +404,21 @@ class Chef # @param [Array] components # @param [Boolean] trusted # @param [String] arch + # @param [Array] options # @param [Boolean] add_src # # @return [String] complete repo config text - def build_repo(uri, distribution, components, trusted, arch, add_src = false) + def build_repo(uri, distribution, components, trusted, arch, options, add_src = false) uri = make_ppa_url(uri) if is_ppa_url?(uri) uri = Addressable::URI.parse(uri) components = Array(components).join(" ") - options = [] - options << "arch=#{arch}" if arch - options << "trusted=yes" if trusted - optstr = unless options.empty? - "[" + options.join(" ") + "]" + options_list = [] + options_list << "arch=#{arch}" if arch + options_list << "trusted=yes" if trusted + options_list += options + optstr = unless options_list.empty? + "[" + options_list.join(" ") + "]" end info = [ optstr, uri.normalize.to_s, distribution, components ].compact.join(" ") repo = "deb #{info}\n" @@ -461,6 +479,7 @@ class Chef repo_components, new_resource.trusted, new_resource.arch, + new_resource.options, new_resource.deb_src ) -- cgit v1.2.1