diff options
author | Gary Ewan Park <gep13@gep13.co.uk> | 2019-06-03 13:57:10 -0700 |
---|---|---|
committer | Gary Ewan Park <gep13@gep13.co.uk> | 2019-06-04 21:46:37 +0100 |
commit | 1671fe7bbaf122a2d4e13e2d3ac432b916d26a5a (patch) | |
tree | d09c9ff4d538430075fcde526d5726e1f9b57279 /lib/chef/resource | |
parent | a25d9108d4d6d15f173a86b82dcbf1911d2f2810 (diff) | |
download | chef-1671fe7bbaf122a2d4e13e2d3ac432b916d26a5a.tar.gz |
(GH-8634) Add ability to further configure source
This provides the ability to set additional properties for a Chocolatey
source with properties `admin_only` and `allow_self_service`. As well
as the ability to enable/disable a source.
Signed-off-by: Gary Ewan Park <gep13@gep13.co.uk>
Diffstat (limited to 'lib/chef/resource')
-rw-r--r-- | lib/chef/resource/chocolatey_source.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/chef/resource/chocolatey_source.rb b/lib/chef/resource/chocolatey_source.rb index e8ef95aad5..c9b3316300 100644 --- a/lib/chef/resource/chocolatey_source.rb +++ b/lib/chef/resource/chocolatey_source.rb @@ -17,6 +17,7 @@ class Chef class Resource class ChocolateySource < Chef::Resource + preview_resource true resource_name :chocolatey_source description "Use the chocolatey_source resource to add or remove Chocolatey sources." @@ -31,9 +32,17 @@ class Chef property :bypass_proxy, [TrueClass, FalseClass], default: false, description: "Whether or not to bypass the system's proxy settings to access the source." + property :admin_only, [TrueClass, FalseClass], default: false, + description: "Whether or not to set the source to be accessible to only admins." + + property :allow_self_service, [TrueClass, FalseClass], default: false, + description: "Whether or not to set the source to be used for self service." + property :priority, Integer, default: 0, description: "The priority level of the source." + property :source_state, [TrueClass, FalseClass], default: false, desired_state: false, skip_docs: true + load_current_value do element = fetch_source_element(source_name) current_value_does_not_exist! if element.nil? @@ -41,13 +50,16 @@ class Chef source_name element["id"] source element["value"] bypass_proxy element["bypassProxy"] == "true" + admin_only element["adminOnly"] == "true" + allow_self_service element["selfService"] == "true" priority element["priority"].to_i + source_state element["disabled"] == "true" end # @param [String] id the source name # @return [REXML::Attributes] finds the source element with the def fetch_source_element(id) - require "rexml/document" unless defined?(REXML::Document) + require "rexml/document" config_file = "#{ENV['ALLUSERSPROFILE']}\\chocolatey\\config\\chocolatey.config" raise "Could not find the Chocolatey config at #{config_file}!" unless ::File.exist?(config_file) @@ -77,6 +89,26 @@ class Chef end end + action :disable do + description "Disables a Chocolatey source." + + if current_resource.source_state != true + converge_by("disable Chocolatey source '#{new_resource.source_name}'") do + shell_out!(choco_cmd("disable")) + end + end + end + + action :enable do + description "Enables a Chocolatey source." + + if current_resource.source_state == true + converge_by("enable Chocolatey source '#{new_resource.source_name}'") do + shell_out!(choco_cmd("enable")) + end + end + end + action_class do # @param [String] action the name of the action to perform # @return [String] the choco source command string @@ -85,6 +117,8 @@ class Chef if action == "add" cmd << " -s #{new_resource.source} --priority=#{new_resource.priority}" cmd << " --bypassproxy" if new_resource.bypass_proxy + cmd << " --allowselfservice" if new_resource.allow_self_service + cmd << " --adminonly" if new_resource.admin_only end cmd end |