Skip to content

(maint) Unnest module and class names in Ruby tasks #687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2023
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
(maint) Unnest module and class names in Ruby tasks
  • Loading branch information
MartyEwings committed Dec 7, 2023
commit 6c54cc4e547e17c7e792986645feb0ecbefbe88b
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ Style/BlockDelimiters:
be consistent then.
EnforcedStyle: braces_for_chaining
Style/ClassAndModuleChildren:
Description: Compact style reduces the required amount of indentation.
EnforcedStyle: compact
Enabled: false
Style/EmptyElse:
Description: Enforce against empty else clauses, but allow `nil` for clarity.
EnforcedStyle: empty
Expand Down
2 changes: 2 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Enabled: false
RSpec/SubjectStub:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Gemfile:
optional:
":development":
Expand Down
105 changes: 54 additions & 51 deletions files/rb_task_helper.rb
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
# frozen_string_literal: true

# Puppet Agent task helper
module PuppetAgent::RbTaskHelper
private

def error_result(error_type, error_message)
{
'_error' => {
'msg' => error_message,
'kind' => error_type,
'details' => {},
},
}
end

def puppet_bin_present?
File.exist?(puppet_bin)
end

# Returns the path to the Puppet agent executable
def puppet_bin
@puppet_bin ||= if Puppet.features.microsoft_windows?
puppet_bin_windows
else
'/opt/puppetlabs/bin/puppet'
end
end

# Returns the path to the Puppet agent executable on Windows
def puppet_bin_windows
require 'win32/registry'

install_dir = begin
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg|
# Rescue missing key
dir = begin
reg['RememberedInstallDir64']
rescue StandardError
''
end
# Both keys may exist, make sure the dir exists
break dir if File.exist?(dir)

# Rescue missing key
begin
reg['RememberedInstallDir']
rescue StandardError
''
module PuppetAgent
# Puppet Agent Ruby task helper
module RbTaskHelper
private

def error_result(error_type, error_message)
{
'_error' => {
'msg' => error_message,
'kind' => error_type,
'details' => {},
},
}
end

def puppet_bin_present?
File.exist?(puppet_bin)
end

# Returns the path to the Puppet agent executable
def puppet_bin
@puppet_bin ||= if Puppet.features.microsoft_windows?
puppet_bin_windows
else
'/opt/puppetlabs/bin/puppet'
end
end

# Returns the path to the Puppet agent executable on Windows
def puppet_bin_windows
require 'win32/registry'

install_dir = begin
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg|
# Rescue missing key
dir = begin
reg['RememberedInstallDir64']
rescue StandardError
''
end
# Both keys may exist, make sure the dir exists
break dir if File.exist?(dir)

# Rescue missing key
begin
reg['RememberedInstallDir']
rescue StandardError
''
end
end
rescue Win32::Registry::Error
# Rescue missing registry path
''
end
rescue Win32::Registry::Error
# Rescue missing registry path
''
end

File.join(install_dir, 'bin', 'puppet.bat')
File.join(install_dir, 'bin', 'puppet.bat')
end
end
end