Skip to content

Commit

Permalink
(puppetlabsGH-75) Including module name in vendored module path
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcmaw committed Jan 19, 2021
1 parent 363e89d commit 29953ea
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
Expand Up @@ -364,11 +364,43 @@ def should_to_resource(should, context, dsc_invoke_method)
else
File.expand_path("#{root_module_path}/puppet_x/dsc_resources")
end

# This handles setting the vendored_modules_path to include the puppet module name
# We now add the puppet module name into the path to allow multiple modules to with shared dsc_resources to be installed side by side
# The old vendored_modules_path: puppet_x/dsc_resources
# The new vendored_modules_path: puppet_x/powershellget/dsc_resources
unless File.exists? resource[:vendored_modules_path]
resource[:vendored_modules_path] = if root_module_path.nil?
File.expand_path(Pathname.new(__FILE__).dirname + '../../../' + "puppet_x/#{puppetize_name(resource[:dscmeta_module_name])}/dsc_resources") # rubocop:disable Style/StringConcatenation
else
File.expand_path("#{root_module_path}/puppet_x/#{puppetize_name(resource[:dscmeta_module_name])}/dsc_resources")
end
end

# A warning is thrown if the something went wrong and the file was not created
unless File.exists? resource[:vendored_modules_path]
raise "Unable to find expected vendored DSC Resource #{resource[:vendored_modules_path]}"
end

resource[:attributes] = nil

context.debug("should_to_resource: #{resource.inspect}")
resource
end

# Return a String containing a puppetized name. A puppetized name is a string that only
# includes lowercase letters, digits, underscores and cannot start with a digit.
#
# @return [String] with a puppeized module name
def puppetize_name(name)
# Puppet module names must be lower case
name = name.downcase
# Puppet module names must only include lowercase letters, digits and underscores
name = name.gsub(%r{[^a-z0-9_]}, '_')
# Puppet module names must not start with a number so if it does, append the letter 'a' to the name. Eg: '7zip' becomes 'a7zip'
name = name.match?(%r{^\d}) ? "a#{name}" : name
end

# Return a UUID with the dashes turned into underscores to enable the specifying of guaranteed-unique
# variables in the PowerShell script.
#
Expand Down

0 comments on commit 29953ea

Please sign in to comment.