Skip to content

Commit

Permalink
(puppetlabsGH-121) Extract module name during creating module object
Browse files Browse the repository at this point in the history
Previously the monkey patch to inject the editor workspace as a module did not
extract the module name correctly. While this was ok for older Puppet 3 API,
the Puppet 4 API namespaces objects based on the module name, so this TODO
item needed to be completed.  Now we extract the module name correctly.
  • Loading branch information
glennsarti committed May 21, 2019
1 parent da5d292 commit 0e2ff9c
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ def create_workspace_module_object(path)
begin
metadata = workspace_load_json(File.read(md_file, :encoding => 'utf-8'))
return nil if metadata['name'].nil?
# TODO : Need to rip out the module name
# Extract the actual module name
if Puppet::Module.is_module_directory_name?(metadata['name'])
module_name = metadata['name']
elsif Puppet::Module.is_module_namespaced_name?(metadata['name'])
# Based on regex at https://github.com/puppetlabs/puppet/blob/f5ca8c05174c944f783cfd0b18582e2160b77d0e/lib/puppet/module.rb#L54
result = /^[a-zA-Z0-9]+[-]([a-z][a-z0-9_]*)$/.match(metadata['name'])
module_name = result[1]
else
# TODO: This is an invalid puppet module name in the metadata.json. Should we log an error/warning?
return nil
end

# The Puppet::Module initializer was changed in
# https://github.com/puppetlabs/puppet/commit/935c0311dbaf1df03937822525c36b26de5390ef
# We need to switch the creation based on whether the modules_strict_semver? method is available
return Puppet::Module.new(metadata['name'], path, self, modules_strict_semver?) if respond_to?('modules_strict_semver?')
return Puppet::Module.new(metadata['name'], path, self)
return Puppet::Module.new(module_name, path, self, modules_strict_semver?) if respond_to?('modules_strict_semver?')
return Puppet::Module.new(module_name, path, self)
rescue StandardError
return nil
end
Expand Down

0 comments on commit 0e2ff9c

Please sign in to comment.