Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

COOK-710, COOK-711 Refactor of registry provider #184

Closed
wants to merge 7 commits into from

2 participants

Paul Morton Joshua Timberman
Paul Morton
  1. The registry should open in the *bitedness of the operating system (Ruby is 32 bit, so it gets the 32 bit registry by default)
  2. Refactor of the registry provider to allow multiple functions to take advantage of some damn good code (thanks dougm)
  3. Addition convenience methods which allow for checks like key_exists? value_exists?
  4. Convenience methods available for reading and writing to the registry.
Paul Morton

Updated this pull request to include a couple of new providers.

Environmental Variable Provider - For creating/removing environmental variables.
Auto Run Provider - For creating/removing items that should be run at login
Path Provider - A provider for adding/removing items from the system path

Joshua Timberman
Owner

Hi Paul,

Thank you for taking the time to create the pull request and the tickets at tickets.opscode.com. I apologize that this has been open so long without a response from us! We're working through the back log of pull requests and open tickets. I've set the ticket to resolved status so it gets picked up for review in our triage meeting.

Thank you!

Paul Morton

Joshua - COOK-710. Yes backwards compatibility is the great. However, I am concerned in this instance because not taking this change makes it so that the resource will silently fail. If you are setting a value in the same key in three different recipes only one instance will run cause gremlins in the system. At the very least I think that it would make sense to spit out a warning if the users has specified the key as the name attribute. Thoughts?

Joshua Timberman
Owner

Paul, I see you closed both COOK-710 and COOK-711 as won't fix. Are these issues not relevant, or otherwise fixed from other changes in the cookbook?

Joshua Timberman
Owner

(closing this pull request since the tickets are closed, please do reopen the tickets if further action is required. Thanks!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6 windows/providers/auto_run.rb
@@ -19,13 +19,15 @@
19 19 #
20 20
21 21 action :create do
22   - windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do
  22 + windows_registry "CreateAutoRun #{new_resource.program} #{new_resource.args}" do
  23 + key_name 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
23 24 values new_resource.name => "\"#{new_resource.program}\" #{new_resource.args}"
24 25 end
25 26 end
26 27
27 28 action :remove do
28   - windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do
  29 + windows_registry "RemoveAutoRun #{new_resource.program} #{new_resource.args}" do
  30 + key_name 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
29 31 values new_resource.name => ''
30 32 action :remove
31 33 end
33 windows/providers/env_vars.rb
... ... @@ -1,33 +0,0 @@
1   -#
2   -# Author:: Paul Morotn (<pmorton@biaprotect.com>)
3   -# Cookbook Name:: windows
4   -# Provider:: env_vars
5   -#
6   -# Copyright:: 2011, Business Intelligence Associates, Inc
7   -#
8   -# Licensed under the Apache License, Version 2.0 (the "License");
9   -# you may not use this file except in compliance with the License.
10   -# You may obtain a copy of the License at
11   -#
12   -# http://www.apache.org/licenses/LICENSE-2.0
13   -#
14   -# Unless required by applicable law or agreed to in writing, software
15   -# distributed under the License is distributed on an "AS IS" BASIS,
16   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   -# See the License for the specific language governing permissions and
18   -# limitations under the License.
19   -#
20   -
21   -action :create do
22   - windows_registry Windows::KeyHelper::ENV_KEY do
23   - values new_resource.name => new_resource.value
24   - action :create
25   - end
26   -end
27   -
28   -action :remove do
29   - windows_registry Windows::KeyHelper::ENV_KEY do
30   - values new_resource.name => ''
31   - action :remove
32   - end
33   -end
37 windows/providers/path.rb
@@ -18,37 +18,20 @@
18 18 # limitations under the License.
19 19 #
20 20
21   -action :add do
22   - path = ENV['PATH'].split(';')
23   - if !path.include?(new_resource.path)
24   - path.insert(-1,new_resource.path)
25   - end
26 21
27   - windows_registry Windows::KeyHelper::ENV_KEY do
28   - values 'Path' => path.join(';')
  22 +action :add do
  23 + env "PATH" do
  24 + action :create
  25 + delim ";"
  26 + value new_resource.path
29 27 end
30   - timeoutVars
  28 +
31 29 end
32 30
33 31 action :remove do
34   - path = ENV['PATH'].split(';')
35   - path.delete(new_resource.path)
36   - windows_registry Windows::KeyHelper::ENV_KEY do
37   - values 'Path' => path.join(';')
  32 + env "PATH" do
  33 + action :delete
  34 + delim ";"
  35 + value new_resource.path
38 36 end
39   - timeoutVars
40   -end
41   -
42   -private
43   -# Notify all processes that the environmental variables have been updated.
44   -def timeoutVars
45   - # Dosent seem to work... You may need to re-login
46   - Chef::Log.debug("Telling other processes that the env vars have been updated")
47   - require 'Win32API'
48   - sendMessageTimeout = Win32API.new('user32', 'SendMessageTimeout', 'LLLPLLP', 'L')
49   - hwnd_broadcast = 0xffff
50   - wm_settingchange = 0x001A
51   - smto_abortifhung = 2
52   - result = 0
53   - sendMessageTimeout.call(hwnd_broadcast, wm_settingchange, 0, 'Environment', smto_abortifhung, 5000, result)
54 37 end
0  windows/providers/shortcut.rb
No changes.
29 windows/resources/env_vars.rb
... ... @@ -1,29 +0,0 @@
1   -#
2   -# Author:: Paul Morotn (<pmorton@biaprotect.com>)
3   -# Cookbook Name:: windows
4   -# Resource:: env_vars
5   -#
6   -# Copyright:: 2011, Business Intelligence Associates, Inc
7   -#
8   -# Licensed under the Apache License, Version 2.0 (the "License");
9   -# you may not use this file except in compliance with the License.
10   -# You may obtain a copy of the License at
11   -#
12   -# http://www.apache.org/licenses/LICENSE-2.0
13   -#
14   -# Unless required by applicable law or agreed to in writing, software
15   -# distributed under the License is distributed on an "AS IS" BASIS,
16   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   -# See the License for the specific language governing permissions and
18   -# limitations under the License.
19   -#
20   -
21   -def initianize(name,run_context=nil)
22   - super
23   - @action = :create
24   -end
25   -
26   -actions :create, :remove
27   -
28   -attribute :value, :kind_of => String
29   -attribute :name, :kind_of => String, :name_attribute => true
6 windows/resources/registry.rb
@@ -22,11 +22,11 @@
22 22
23 23 actions :create, :modify, :force_modify, :remove
24 24
25   -attribute :key_name, :kind_of => String, :name_attribute => true
26   -attribute :values, :kind_of => Hash
  25 +attribute :name, :kind_of => String, :name_attribute => true
  26 +attribute :key_name, :kind_of => String, :required => true
  27 +attribute :values, :kind_of => Hash, :required => true
27 28
28 29 def initialize(name, run_context=nil)
29 30 super
30 31 @action = :modify
31   - @key_name = name
32 32 end
0  windows/resources/shortcut.rb
No changes.

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.