Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 7 commits into from

2 participants

@pmorton
  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.
@pmorton

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

@jtimberman
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!

@pmorton

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?

@jtimberman
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?

@jtimberman jtimberman closed this
@jtimberman
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.
View
6 windows/providers/auto_run.rb
@@ -19,13 +19,15 @@
#
action :create do
- windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do
+ windows_registry "CreateAutoRun #{new_resource.program} #{new_resource.args}" do
+ key_name 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
values new_resource.name => "\"#{new_resource.program}\" #{new_resource.args}"
end
end
action :remove do
- windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do
+ windows_registry "RemoveAutoRun #{new_resource.program} #{new_resource.args}" do
+ key_name 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
values new_resource.name => ''
action :remove
end
View
33 windows/providers/env_vars.rb
@@ -1,33 +0,0 @@
-#
-# Author:: Paul Morotn (<pmorton@biaprotect.com>)
-# Cookbook Name:: windows
-# Provider:: env_vars
-#
-# Copyright:: 2011, Business Intelligence Associates, Inc
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-action :create do
- windows_registry Windows::KeyHelper::ENV_KEY do
- values new_resource.name => new_resource.value
- action :create
- end
-end
-
-action :remove do
- windows_registry Windows::KeyHelper::ENV_KEY do
- values new_resource.name => ''
- action :remove
- end
-end
View
37 windows/providers/path.rb
@@ -18,37 +18,20 @@
# limitations under the License.
#
-action :add do
- path = ENV['PATH'].split(';')
- if !path.include?(new_resource.path)
- path.insert(-1,new_resource.path)
- end
- windows_registry Windows::KeyHelper::ENV_KEY do
- values 'Path' => path.join(';')
+action :add do
+ env "PATH" do
+ action :create
+ delim ";"
+ value new_resource.path
end
- timeoutVars
+
end
action :remove do
- path = ENV['PATH'].split(';')
- path.delete(new_resource.path)
- windows_registry Windows::KeyHelper::ENV_KEY do
- values 'Path' => path.join(';')
+ env "PATH" do
+ action :delete
+ delim ";"
+ value new_resource.path
end
- timeoutVars
-end
-
-private
-# Notify all processes that the environmental variables have been updated.
-def timeoutVars
- # Dosent seem to work... You may need to re-login
- Chef::Log.debug("Telling other processes that the env vars have been updated")
- require 'Win32API'
- sendMessageTimeout = Win32API.new('user32', 'SendMessageTimeout', 'LLLPLLP', 'L')
- hwnd_broadcast = 0xffff
- wm_settingchange = 0x001A
- smto_abortifhung = 2
- result = 0
- sendMessageTimeout.call(hwnd_broadcast, wm_settingchange, 0, 'Environment', smto_abortifhung, 5000, result)
end
View
0  windows/providers/shortcut.rb
No changes.
View
29 windows/resources/env_vars.rb
@@ -1,29 +0,0 @@
-#
-# Author:: Paul Morotn (<pmorton@biaprotect.com>)
-# Cookbook Name:: windows
-# Resource:: env_vars
-#
-# Copyright:: 2011, Business Intelligence Associates, Inc
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-def initianize(name,run_context=nil)
- super
- @action = :create
-end
-
-actions :create, :remove
-
-attribute :value, :kind_of => String
-attribute :name, :kind_of => String, :name_attribute => true
View
6 windows/resources/registry.rb
@@ -22,11 +22,11 @@
actions :create, :modify, :force_modify, :remove
-attribute :key_name, :kind_of => String, :name_attribute => true
-attribute :values, :kind_of => Hash
+attribute :name, :kind_of => String, :name_attribute => true
+attribute :key_name, :kind_of => String, :required => true
+attribute :values, :kind_of => Hash, :required => true
def initialize(name, run_context=nil)
super
@action = :modify
- @key_name = name
end
View
0  windows/resources/shortcut.rb
No changes.
Something went wrong with that request. Please try again.