forked from puppetlabs/puppetlabs-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, the component parts of the key and value types were stored as instance variables of the resource, even though they were derived from the path parameter. This commit introduces a KeyPath parameter which knows how to validate registry key paths. It also contains the instance data associated with the root key and subkey. The ValuePath parameter extends KeyPath and knows about validating registry value paths, including how to handle default values.
- Loading branch information
1 parent
64bba67
commit 74ebc80
Showing
7 changed files
with
99 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'puppet/parameter' | ||
require 'puppet/util/registry_base' | ||
|
||
class Puppet::Util::KeyPath < Puppet::Parameter | ||
include Puppet::Util::RegistryBase | ||
|
||
attr_reader :hkey, :subkey | ||
|
||
def validate(path) | ||
split(path.to_s) | ||
end | ||
|
||
def split(path) | ||
unless match = /^([^\\]*)((?:\\[^\\]{1,255})*)$/.match(path) | ||
raise ArgumentError, "Invalid registry key: #{path}" | ||
end | ||
|
||
@hkey = | ||
case match[1].downcase | ||
when /hkey_local_machine/, /hklm/ | ||
HKEYS[:hklm] | ||
when /hkey_classes_root/, /hkcr/ | ||
HKEYS[:hkcr] | ||
else | ||
raise ArgumentError, "Unsupported prefined key: #{path}" | ||
end | ||
|
||
# leading backslash is not part of the subkey name | ||
@subkey = match[2] | ||
@subkey = @subkey[1..-1] unless @subkey.empty? | ||
end | ||
|
||
def ascend(&block) | ||
s = subkey | ||
|
||
yield hkey, s | ||
|
||
while idx = s.rindex('\\') | ||
s = s[0, idx] | ||
yield hkey, s | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'puppet/parameter' | ||
require 'puppet/util/registry_base' | ||
|
||
class Puppet::Util::ValuePath < Puppet::Parameter::KeyPath | ||
attr_reader :valuename | ||
|
||
def split(path) | ||
unless path | ||
raise ArgumentError, "Invalid registry value" | ||
end | ||
|
||
if path[-1, 1] == '\\' # trailing backslash implies default value | ||
super(path.gsub(/\\*$/, '')) | ||
@valuename = '' | ||
else | ||
idx = path.rindex('\\') | ||
raise ArgumentError, "Registry value path must contain at least one backslash." unless idx | ||
|
||
super(path[0, idx]) | ||
@valuename = path[idx+1..-1] if idx > 0 | ||
end | ||
end | ||
end |