Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ fixtures:
provision: 'https://github.com/puppetlabs/provision.git'
puppet_agent:
repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git'
ref: v4.13.0
symlinks:
registry: "#{source_dir}"
mixed_default_settings: "#{source_dir}/spec/fixtures/mixed_default_settings"
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ jobs:
Acceptance:
needs: Spec
uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main"
with:
flags: "--nightly"
secrets: "inherit"
2 changes: 2 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ jobs:
Acceptance:
needs: Spec
uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main"
with:
flags: "--nightly"
secrets: "inherit"

8 changes: 8 additions & 0 deletions .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
--fail-on-warnings
--relative
--no-80chars-check
--no-140chars-check
--no-class_inherits_from_params_class-check
--no-autoloader_layout-check
--no-documentation-check
--no-single_quote_string_with_variables-check
--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require:
AllCops:
NewCops: enable
DisplayCopNames: true
TargetRubyVersion: '2.6'
TargetRubyVersion: 3.1
Include:
- "**/*.rb"
Exclude:
Expand Down
89 changes: 56 additions & 33 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,78 +1,101 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
# frozen_string_literal: true

def location_for(place_or_version, fake_version = nil)
git_url_regex = %r{\A(?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
file_url_regex = %r{\Afile:\/\/(?<path>.*)}
# For puppetcore, set GEM_SOURCE_PUPPETCORE = 'https://rubygems-puppetcore.puppet.com'
gemsource_default = ENV['GEM_SOURCE'] || 'https://rubygems.org'
gemsource_puppetcore = if ENV['PUPPET_FORGE_TOKEN']
'https://rubygems-puppetcore.puppet.com'
else
ENV['GEM_SOURCE_PUPPETCORE'] || gemsource_default
end
source gemsource_default

def location_for(place_or_constraint, fake_constraint = nil, opts = {})
git_url_regex = /\A(?<url>(?:https?|git)[:@][^#]*)(?:#(?<branch>.*))?/
file_url_regex = %r{\Afile://(?<path>.*)}

if place_or_constraint && (git_url = place_or_constraint.match(git_url_regex))
# Git source → ignore :source, keep fake_constraint
[fake_constraint, { git: git_url[:url], branch: git_url[:branch], require: false }].compact

elsif place_or_constraint && (file_url = place_or_constraint.match(file_url_regex))
# File source → ignore :source, keep fake_constraint or default >= 0
[fake_constraint || '>= 0', { path: File.expand_path(file_url[:path]), require: false }]

if place_or_version && (git_url = place_or_version.match(git_url_regex))
[fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
elsif place_or_version && (file_url = place_or_version.match(file_url_regex))
['>= 0', { path: File.expand_path(file_url[:path]), require: false }]
else
[place_or_version, { require: false }]
# Plain version constraint → merge opts (including :source if provided)
[place_or_constraint, { require: false }.merge(opts)]
end
end

# Print debug information if DEBUG_GEMS or VERBOSE is set
def print_gem_statement_for(gems)
puts 'DEBUG: Gem definitions that will be generated:'
gems.each do |gem_name, gem_params|
puts "DEBUG: gem #{([gem_name.inspect] + gem_params.map(&:inspect)).join(', ')}"
end
end

group :development do
gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "deep_merge", '~> 1.2.2', require: false
gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false
gem "facterdb", '~> 2.1', require: false
gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "metadata-json-lint", '~> 4.0', require: false
gem "rspec-puppet-facts", '~> 4.0', require: false
gem "json-schema", '< 5.1.1', require: false
gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "dependency_checker", '~> 1.0.0', require: false
gem "parallel_tests", '= 3.12.1', require: false
gem "pry", '~> 0.10', require: false
gem "simplecov-console", '~> 0.9', require: false
gem "puppet-debugger", '~> 1.0', require: false
gem "puppet-debugger", '~> 1.6', require: false
gem "rubocop", '~> 1.50.0', require: false
gem "rubocop-performance", '= 1.16.0', require: false
gem "rubocop-rspec", '= 2.19.0', require: false
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "rexml", '>= 3.3.9', require: false
gem "bigdecimal", '< 3.2.2', require: false, platforms: [:mswin, :mingw, :x64_mingw]
end
group :development, :release_prep do
gem "puppet-strings", '~> 4.0', require: false
gem "puppetlabs_spec_helper", '~> 7.0', require: false
gem "puppetlabs_spec_helper", '~> 8.0', require: false
gem "puppet-blacksmith", '~> 7.0', require: false
end
group :system_tests do
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw]
gem "puppet_litmus", '~> 2.0', require: false, platforms: [:ruby, :x64_mingw] if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty?
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] if ENV['PUPPET_FORGE_TOKEN'].to_s.empty?
gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "serverspec", '~> 2.41', require: false
end

puppet_version = ENV['PUPPET_GEM_VERSION']
facter_version = ENV['FACTER_GEM_VERSION']
hiera_version = ENV['HIERA_GEM_VERSION']

gems = {}
puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil)
facter_version = ENV.fetch('FACTER_GEM_VERSION', nil)
hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil)

gems['puppet'] = location_for(puppet_version)

# If facter or hiera versions have been specified via the environment
# variables

gems['facter'] = location_for(facter_version) if facter_version
gems['hiera'] = location_for(hiera_version) if hiera_version
gems['puppet'] = location_for(puppet_version, nil, { source: gemsource_puppetcore })
gems['facter'] = location_for(facter_version, nil, { source: gemsource_puppetcore })
gems['hiera'] = location_for(hiera_version, nil, {}) if hiera_version

# Generate the gem definitions
print_gem_statement_for(gems) if ENV['DEBUG']
gems.each do |gem_name, gem_params|
gem gem_name, *gem_params
end

# Evaluate Gemfile.local and ~/.gemfile if they exist
extra_gemfiles = [
"#{__FILE__}.local",
File.join(Dir.home, '.gemfile'),
File.join(Dir.home, '.gemfile')
]

extra_gemfiles.each do |gemfile|
if File.file?(gemfile) && File.readable?(gemfile)
eval(File.read(gemfile), binding)
end
next unless File.file?(gemfile) && File.readable?(gemfile)

# rubocop:disable Security/Eval
eval(File.read(gemfile), binding)
# rubocop:enable Security/Eval
end
# vim: syntax=ruby
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings'

PuppetLint.configuration.send('disable_relative')
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_140chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_autoloader_layout')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"]

2 changes: 1 addition & 1 deletion lib/puppet/type/registry_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def eval_generate
is_values.each do |is_value|
unless should_values.include?(is_value.downcase)
resource_path = PuppetX::Puppetlabs::Registry::RegistryValuePath.combine_path_and_value(self[:path], is_value)
resources << Puppet::Type.type(:registry_value).new(path: resource_path, ensure: :absent, catalog: catalog)
resources << Puppet::Type.type(:registry_value).new(path: resource_path, ensure: :absent, catalog:)
end
end
resources
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 7.0.0 < 9.0.0"
"version_requirement": ">= 8.0.0 < 9.0.0"
}
],
"description": "This module provides a native type and provider to manage keys and values in the Windows Registry",
"pdk-version": "3.2.0",
"pdk-version": "3.5.0",
"template-url": "https://github.com/puppetlabs/pdk-templates.git#main",
"template-ref": "tags/3.2.0.4-0-g5d17ec1"
"template-ref": "heads/main-0-g19976cd"
}
8 changes: 4 additions & 4 deletions spec/defines/value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
arr1 = ['dword', 'qword']
arr1.each do |type|
context "with #{type} numeric data" do
let(:params) { super().merge(type: type, data: 42) }
let(:params) { super().merge(type:, data: 42) }

it { is_expected.to compile }

it {
expect(subject).to contain_registry_value('HKLM\Software\Vendor\\\\value_name')
.with(ensure: 'present', type: type, data: 42)
.with(ensure: 'present', type:, data: 42)
}
end
end
Expand All @@ -79,13 +79,13 @@
arr2 = ['string', 'expand']
arr2.each do |type|
context "with string data typed as '#{type}'" do
let(:params) { super().merge(type: type, data: 'some typed string data') }
let(:params) { super().merge(type:, data: 'some typed string data') }

it { is_expected.to compile }

it {
expect(subject).to contain_registry_value('HKLM\Software\Vendor\\\\value_name')
.with(ensure: 'present', type: type, data: 'some typed string data')
.with(ensure: 'present', type:, data: 'some typed string data')
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet/provider/registry_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def bytes_to_utf8(bytes)
end

it 'does not raise an error' do
reg_key = type.new(catalog: catalog,
reg_key = type.new(catalog:,
ensure: :absent,
name: "hklm\\#{reg_path}",
purge_values: true,
Expand Down Expand Up @@ -101,7 +101,7 @@ def bytes_to_utf8(bytes)
it 'does not use Rubys each_value, which unnecessarily string encodes' do
# endash and tm undergo LOCALE conversion during Rubys each_value
# which will generally lead to a conversion exception
reg_key = type.new(catalog: catalog,
reg_key = type.new(catalog:,
ensure: :absent,
name: "hklm\\#{reg_path}",
purge_values: true,
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/puppet/provider/registry_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,46 +57,46 @@
end

describe '#exists?' do
it 'returns true for a well known hive' do

Check warning on line 60 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#exists? returns true for a well known hive Skipped: Not on Windows platform
reg_value = type.new(title: 'hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareType', provider: described_class.name)
expect(reg_value.provider.exists?).to be(true)
end

it 'returns true for a well known hive with mixed case name' do

Check warning on line 65 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#exists? returns true for a well known hive with mixed case name Skipped: Not on Windows platform
reg_value = type.new(title: 'hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareType'.upcase, provider: described_class.name)
expect(reg_value.provider.exists?).to be(true)
end

it 'returns true for a well known hive with double backslash' do

Check warning on line 70 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#exists? returns true for a well known hive with double backslash Skipped: Not on Windows platform
reg_value = type.new(title: 'hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\\\\SoftwareType', provider: described_class.name)
expect(reg_value.provider.exists?).to be(true)
end

it 'returns true for a well known hive with mixed case name with double backslash' do

Check warning on line 75 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#exists? returns true for a well known hive with mixed case name with double backslash Skipped: Not on Windows platform
reg_value = type.new(title: 'hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\\\\SoftwareType'.upcase, provider: described_class.name)
expect(reg_value.provider.exists?).to be(true)
end

it 'returns false for a bogus hive/path' do

Check warning on line 80 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#exists? returns false for a bogus hive/path Skipped: Not on Windows platform
reg_value = type.new(path: 'hklm\foobar5000', catalog: catalog, provider: described_class.name)
reg_value = type.new(path: 'hklm\foobar5000', catalog:, provider: described_class.name)
expect(reg_value.provider.exists?).to be(false)
end
end

describe '#regvalue' do
it 'returns a valid string for a well known key' do

Check warning on line 87 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#regvalue returns a valid string for a well known key Skipped: Not on Windows platform
reg_value = type.new(path: 'hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRoot', provider: described_class.name)
expect(reg_value.provider.data).to equal([ENV.fetch('SystemRoot', nil)])
expect(reg_value.provider.type).to equal(:string)
end

it 'returns a string of lowercased hex encoded bytes' do

Check warning on line 93 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#regvalue returns a string of lowercased hex encoded bytes Skipped: Not on Windows platform
reg = described_class.new
_type, data = reg.from_native([3, "\u07AD"])
expect(data).to equal(['de ad'])
end

it 'left pads binary strings' do

Check warning on line 99 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#regvalue left pads binary strings Skipped: Not on Windows platform
reg = described_class.new
_type, data = reg.from_native([3, "\x1"])
expect(data).to equal(['01'])
Expand All @@ -109,9 +109,9 @@
let(:path) { "hklm\\#{puppet_key}\\#{subkey_name}\\#{valuename}" }

def create_and_destroy(path, reg_type, data)
reg_value = type.new(path: path,
reg_value = type.new(path:,
type: reg_type,
data: data,
data:,
provider: described_class.name)
already_exists = reg_value.provider.exists?
expect(already_exists).to be(false)
Expand Down Expand Up @@ -191,11 +191,11 @@
end
end

it 'can destroy a randomly created default REG_SZ value' do

Check warning on line 194 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#destroy can destroy a randomly created default REG_SZ value Skipped: Not on Windows platform
expect(create_and_destroy(default_path, :string, SecureRandom.uuid)).to be(true)
end

it 'can destroy a randomly created REG_SZ value' do

Check warning on line 198 in spec/unit/puppet/provider/registry_value_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Puppet::Type::Registry_value::ProviderRegistry#destroy can destroy a randomly created REG_SZ value Skipped: Not on Windows platform
expect(create_and_destroy(path, :string, SecureRandom.uuid)).to be(true)
end

Expand Down Expand Up @@ -224,13 +224,13 @@
let(:path) { "hklm\\#{puppet_key}\\#{subkey_name}\\#{SecureRandom.uuid}" }

after(:each) do
reg_value = type.new(path: path, provider: described_class.name)
reg_value = type.new(path:, provider: described_class.name)

reg_value.provider.destroy
end

def write_and_read_value(path, reg_type, value)
reg_value = type.new(path: path,
reg_value = type.new(path:,
type: reg_type,
data: value,
provider: described_class.name)
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/puppet/type/registry_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# This is overridden here so we get a consistent association with the key
# and a catalog using memoized let methods.
let(:key) { Puppet::Type.type(:registry_key).new(name: 'HKLM\Software', catalog: catalog) }
let(:key) { Puppet::Type.type(:registry_key).new(name: 'HKLM\Software', catalog:) }
let(:provider) { Puppet::Provider.new(key) }

before(:each) do
Expand Down Expand Up @@ -86,14 +86,14 @@

# This is overridden here so we get a consistent association with the key
# and a catalog using memoized let methods.
let(:key) { Puppet::Type.type(:registry_key).new(name: 'HKLM\Software', catalog: catalog) }
let(:key) { Puppet::Type.type(:registry_key).new(name: 'HKLM\Software', catalog:) }

before :each do
key[:purge_values] = true
catalog.add_resource(key)
catalog.add_resource(Puppet::Type.type(:registry_value).new(path: "#{key[:path]}\\val1", catalog: catalog))
catalog.add_resource(Puppet::Type.type(:registry_value).new(path: "#{key[:path]}\\vAl2", catalog: catalog))
catalog.add_resource(Puppet::Type.type(:registry_value).new(path: "#{key[:path]}\\\\val\\3", catalog: catalog))
catalog.add_resource(Puppet::Type.type(:registry_value).new(path: "#{key[:path]}\\val1", catalog:))
catalog.add_resource(Puppet::Type.type(:registry_value).new(path: "#{key[:path]}\\vAl2", catalog:))
catalog.add_resource(Puppet::Type.type(:registry_value).new(path: "#{key[:path]}\\\\val\\3", catalog:))
end

it "returns an empty array if the key doesn't have any values" do
Expand Down
Loading
Loading