Skip to content
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

Various Rubocop and lint fixes #164

Merged
merged 15 commits into from
Jul 6, 2022
Merged
3 changes: 3 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
spec/spec_helper.rb:
spec_overrides: "require 'spec_helper_methods'"
2 changes: 2 additions & 0 deletions lib/facter/rvm_installed.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Facter.add(:rvm_installed) do
rvm_binary = '/usr/local/rvm/bin/rvm'

Expand Down
2 changes: 2 additions & 0 deletions lib/facter/rvm_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Facter.add(:rvm_version) do
rvm_binary = '/usr/local/rvm/bin/rvm'

Expand Down
6 changes: 4 additions & 2 deletions lib/puppet/provider/rvm_alias/alias.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# RVM gemset support
Puppet::Type.type(:rvm_alias).provide(:alias) do
desc 'RVM alias support.'
Expand All @@ -24,8 +26,8 @@ def alias_list
list = []
begin
list = execute(command)
rescue Puppet::ExecutionFailure => detail
Puppet.debug "`rvmcmd` command failed with #{detail}"
rescue Puppet::ExecutionFailure => e
Puppet.debug "`rvmcmd` command failed with #{e}"
ekohl marked this conversation as resolved.
Show resolved Hide resolved
end

list.to_s
Expand Down
27 changes: 13 additions & 14 deletions lib/puppet/provider/rvm_gem/gem.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet/provider/package'
require 'uri'

Expand Down Expand Up @@ -33,13 +35,11 @@ def gemlist(hash)
end

if (name = hash[:justme])
command << '^' + name + '$'
command << ("^#{name}$")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the braces around it?

end

# use proxy if proxy_url is set
if resource[:proxy_url] && !resource[:proxy_url].empty?
command << '--http-proxy' << resource[:proxy_url]
end
command << '--http-proxy' << resource[:proxy_url] if resource[:proxy_url] && !resource[:proxy_url].empty?

list = []
begin
Expand All @@ -49,20 +49,21 @@ def gemlist(hash)
gemhash
end
end.compact
rescue Puppet::ExecutionFailure => detail
Puppet.debug "`rvmcmd` command failed with #{detail}"
rescue Puppet::ExecutionFailure => e
Puppet.debug "`rvmcmd` command failed with #{e}"
end

return list.shift if hash[:justme]

list
end

def self.gemsplit(desc)
desc = desc.gsub('default: ', '')

case desc
when %r{^\*\*\*}, %r{^\s*$}, %r{^\s+} then return nil
when %r{gem: not found} then nil
when %r{^\*\*\*}, %r{^\s*$}, %r{^\s+} then nil
when %r{gem: not found} then nil # rubocop:disable Lint/DuplicateBranch
Comment on lines +65 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or

Suggested change
when %r{^\*\*\*}, %r{^\s*$}, %r{^\s+} then nil
when %r{gem: not found} then nil # rubocop:disable Lint/DuplicateBranch
when %r{^\*\*\*}, %r{^\s*$}, %r{^\s+}, %r{gem: not found} then nil

when %r{^(\S+)\s+\((\d+.*)\)}
name = Regexp.last_match(1)
version = Regexp.last_match(2).split(%r{,\s*})
Expand All @@ -76,22 +77,20 @@ def self.gemsplit(desc)
end
end

def install(useversion = true)
def install(useversion = true) # rubocop:disable Style/OptionalBooleanParameter
command = gembinary + ['install']
command << '-v' << resource[:ensure] if (!resource[:ensure].is_a? Symbol) && useversion
# Dependencies are now installed by default
# command << "--include-dependencies"

# use proxy if proxy_url is set
if resource[:proxy_url] && !resource[:proxy_url].empty?
command << '--http-proxy' << resource[:proxy_url]
end
command << '--http-proxy' << resource[:proxy_url] if resource[:proxy_url] && !resource[:proxy_url].empty?

if (source = resource[:source])
begin
uri = URI.parse(source)
rescue => detail
raise "Invalid source '#{uri}': #{detail}"
rescue StandardError => e
raise "Invalid source '#{uri}': #{e}"
end

case uri.scheme
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/provider/rvm_gemset/gemset.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# RVM gemset support
Puppet::Type.type(:rvm_gemset).provide(:gemset) do
desc 'RVM gemset support.'
Expand Down Expand Up @@ -26,17 +28,15 @@ def gemset_list
command = gemsetcommand + ['list']

# use proxy if proxy_url is set
if resource[:proxy_url] && !resource[:proxy_url].empty?
command << '--http-proxy' << resource[:proxy_url]
end
command << '--http-proxy' << resource[:proxy_url] if resource[:proxy_url] && !resource[:proxy_url].empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I disagree with Rubocop on this change. It makes the line very long.


list = []
begin
list = execute(command).split("\n").map do |line|
line.strip if line =~ %r{^\s+\S+}
end.compact
rescue Puppet::ExecutionFailure => detail
Puppet.debug "`rvmcmd` command failed with #{detail}"
rescue Puppet::ExecutionFailure => e
Puppet.debug "`rvmcmd` command failed with #{e}"
end

list
Expand Down
14 changes: 7 additions & 7 deletions lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Type.type(:rvm_system_ruby).provide(:rvm) do
desc 'Ruby RVM support.'

Expand All @@ -22,16 +24,16 @@ def exists?
rvmcmd('list', 'strings').split("\n").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not list RVMs: #{detail}"
rescue Puppet::ExecutionFailure => e
raise Puppet::Error, "Could not list RVMs: #{e}"
end

def default_use
rvmcmd('list', 'default').split("\n").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not list default RVM: #{detail}"
rescue Puppet::ExecutionFailure => e
raise Puppet::Error, "Could not list default RVM: #{e}"
end

def default_use=(value)
Expand All @@ -51,9 +53,7 @@ def install
ENV['no_proxy'] = resource[:no_proxy] unless resource[:no_proxy].nil?
end
options = Array(resource[:build_opts])
if resource[:autolib_mode]
options << "--autolibs #{resource[:autolib_mode]}"
end
options << "--autolibs #{resource[:autolib_mode]}" if resource[:autolib_mode]
if resource[:proxy_url] && !resource[:proxy_url].empty?
rvmcmd 'install', resource[:name], '--proxy', resource[:proxy_url], *options
else
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/provider/rvm_wrapper/wrapper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# RVM gemset support
Puppet::Type.type(:rvm_wrapper).provide(:wrapper) do
desc 'RVM wrapper support.'
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/type/rvm_alias.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Type.newtype(:rvm_alias) do
@doc = 'Manage RVM Aliases.'

Expand Down
18 changes: 10 additions & 8 deletions lib/puppet/type/rvm_gem.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Type.newtype(:rvm_gem) do
@doc = 'Ruby Gem support using RVM.'

Expand Down Expand Up @@ -30,8 +32,8 @@ def self.title_patterns
current = retrieve
begin
provider.update
rescue => detail
raise "Could not update: #{detail}"
rescue StandardError => e
raise "Could not update: #{e}"
end

if current == :absent
Expand All @@ -44,8 +46,8 @@ def self.title_patterns
newvalue(%r{.}) do
begin
provider.install
rescue => detail
raise "Could not update: #{detail}"
rescue StandardError => e
raise "Could not update: #{e}"
end

if retrieve == :absent
Expand All @@ -55,7 +57,7 @@ def self.title_patterns
end
end

def insync?(is)
def insync?(is) # rubocop:disable Naming/MethodParameterName
@should ||= []

@latest ||= nil
Expand All @@ -78,9 +80,9 @@ def insync?(is)
begin
@latest = provider.latest
@lateststamp = Time.now.to_i
rescue => detail
error = Puppet::Error.new("Could not get latest version: #{detail}")
error.set_backtrace(detail.backtrace)
rescue StandardError => e
error = Puppet::Error.new("Could not get latest version: #{e}")
error.set_backtrace(e.backtrace)
raise error
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/type/rvm_gemset.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Type.newtype(:rvm_gemset) do
@doc = 'Manage RVM Gemsets.'

Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/type/rvm_system_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Type.newtype(:rvm_system_ruby) do
@doc = 'Manage RVM Ruby installations.'

Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/type/rvm_wrapper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Type.newtype(:rvm_wrapper) do
@doc = 'Manage RVM Wrappers.'

Expand Down
13 changes: 0 additions & 13 deletions manifests/gnupg_key.pp

This file was deleted.

5 changes: 2 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
$rvm_gems= {},
$proxy_url=$rvm::params::proxy_url,
$no_proxy=$rvm::params::no_proxy,
$key_server=$rvm::params::key_server,
$gnupg_key_id=$rvm::params::gnupg_key_id) inherits rvm::params {
$gnupg_key_id=$rvm::params::gnupg_key_id,
) inherits rvm::params {
if $install_rvm {
# rvm has now autolibs enabled by default so let it manage the dependencies
if $install_dependencies {
Expand All @@ -28,7 +28,6 @@
version => $version,
proxy_url => $proxy_url,
no_proxy => $no_proxy,
key_server => $key_server,
gnupg_key_id => $gnupg_key_id,
install_from => $install_from,
}
Expand Down
12 changes: 5 additions & 7 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@

$proxy_url = undef
$no_proxy = undef
$key_server = 'hkp://keys.gnupg.net'

# install the gpg key if gpg is installed or being installed in this puppet run
if defined(Class['gnupg']) or $facts['gnupg_installed'] {
$gnupg_key_id = '39499BDB'
} else {
$gnupg_key_id = false
}
# sadly the gpg module is ages old and doesn't support long key ids
$gnupg_key_id = [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably rename this to $gnupg_key_ids?

{ 'id' => 'D39DC0E3', 'source' => 'https://rvm.io/mpapis.asc' },
{ 'id' => '39499BDB', 'source' => 'https://rvm.io/pkuczynski.asc' },
]

# ignored param, using gnupg module
$gpg_package = $facts['kernel'] ? {
Expand Down
27 changes: 19 additions & 8 deletions manifests/system.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
$install_from=undef,
$proxy_url=undef,
$no_proxy=undef,
$key_server=undef,
$home=$facts['root_home'],
$gnupg_key_id=$rvm::params::gnupg_key_id
$gnupg_key_id=$rvm::params::gnupg_key_id,
) inherits rvm::params {
$actual_version = $version ? {
undef => 'latest',
Expand Down Expand Up @@ -38,10 +37,20 @@

# install the gpg key
if $gnupg_key_id {
class { 'rvm::gnupg_key':
key_server => $key_server,
key_id => $gnupg_key_id,
before => Exec['system-rvm'],
include gnupg

# https keys are downloaded with wget
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a require on the package somewhere? like gnupg_key?

ensure_packages(['wget'])
$gnupg_key_id.each |Hash[String[1], String[1]] $key| {
gnupg_key { $key['id']:
ensure => 'present',
user => 'root',
key_id => $key['id'],
key_source => $key['source'],
key_type => public,
before => Exec['system-rvm'],
require => Class['gnupg'],
}
}
}

Expand Down Expand Up @@ -76,8 +85,10 @@
# the fact won't work until rvm is installed before puppet starts
if $facts['rvm_version'] and !empty($facts['rvm_version']) {
if ($version != undef) and ($version != present) and ($version != $facts['rvm_version']) {
if defined(Class['rvm::gnupg_key']) {
Class['rvm::gnupg_key'] -> Exec['system-rvm-get']
if $gnupg_key_id {
$gnupg_key_id.each |Hash[String[1], String[1]] $key| {
Gnupg_key[$key['id']] -> Exec['system-rvm-get']
}
}

# Update the rvm installation to the version specified
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"name": "golja/gnupg",
"version_requirement": ">=1.2.0"
"version_requirement": ">= 1.2.0 < 2.0.0"
}
],
"operatingsystem_support": [
Expand Down
Loading