Skip to content

Commit cdfeacb

Browse files
committed
fix rubocop issues
1 parent d5246d6 commit cdfeacb

File tree

8 files changed

+339
-349
lines changed

8 files changed

+339
-349
lines changed

lib/facter/ssh_client_version.rb

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
Facter.add("ssh_client_version_full") do
2-
confine :kernel => [ 'Linux' , 'SunOS' , 'FreeBSD' , 'Darwin' ]
1+
Facter.add('ssh_client_version_full') do
2+
confine kernel: %w(Linux SunOS FreeBSD Darwin)
33

44
version = Facter::Util::Resolution.exec('ssh -V 2>&1').
5-
lines.
6-
to_a.
7-
select { |line| line.match(/^OpenSSH_/) }.
8-
first.
9-
rstrip
5+
lines.
6+
to_a.
7+
select { |line| line.match(%r{^OpenSSH_}) }.
8+
first.
9+
rstrip
1010

1111
setcode do
12-
if not version.nil?
13-
version.gsub(/^OpenSSH_([^ ]+).*$/, '\1')
14-
end
12+
version.gsub(%r{^OpenSSH_([^ ]+).*$}, '\1') unless version.nil?
1513
end
1614
end
1715

18-
Facter.add("ssh_client_version_major") do
19-
confine :kernel => [ 'Linux' , 'SunOS' , 'FreeBSD' , 'Darwin' ]
20-
confine :ssh_client_version_full => true
16+
Facter.add('ssh_client_version_major') do
17+
confine kernel: %w(Linux SunOS FreeBSD Darwin)
18+
confine ssh_client_version_full: true
2119
setcode do
2220
version = Facter.value('ssh_client_version_full')
2321

24-
version.gsub(/^([0-9]+\.[0-9]+).*$/, '\1')
22+
version.gsub(%r{^([0-9]+\.[0-9]+).*$}, '\1')
2523
end
2624
end
2725

28-
Facter.add("ssh_client_version_release") do
29-
confine :kernel => [ 'Linux' , 'SunOS' , 'FreeBSD' , 'Darwin' ]
30-
confine :ssh_client_version_full => true
26+
Facter.add('ssh_client_version_release') do
27+
confine kernel: %w(Linux SunOS FreeBSD Darwin)
28+
confine ssh_client_version_full: true
3129
setcode do
3230
version = Facter.value('ssh_client_version_full')
3331

34-
version.gsub(/^([0-9]+\.[0-9]+(?:\.[0-9]+)?).*$/, '\1')
32+
version.gsub(%r{^([0-9]+\.[0-9]+(?:\.[0-9]+)?).*$}, '\1')
3533
end
3634
end

lib/facter/ssh_server_version.rb

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
1-
Facter.add("ssh_server_version_full") do
2-
confine :kernel => [ 'Linux' , 'SunOS' , 'FreeBSD' , 'Darwin' ]
1+
Facter.add('ssh_server_version_full') do
2+
confine kernel: %w(Linux SunOS FreeBSD Darwin)
33

44
# sshd doesn't actually have a -V option (hopefully one will be added),
55
# by happy coincidence the usage information that is printed includes the
66
# version number.
77
version = Facter::Util::Resolution.exec('sshd -V 2>&1').
8-
lines.
9-
to_a.
10-
select { |line| line.match(/^OpenSSH_/) }.
11-
first.
12-
rstrip
8+
lines.
9+
to_a.
10+
select { |line| line.match(%r{^OpenSSH_}) }.
11+
first.
12+
rstrip
1313

1414
setcode do
15-
if not version.nil?
16-
version.gsub(/^OpenSSH_([^ ]+).*$/, '\1')
17-
end
15+
version.gsub(%r{^OpenSSH_([^ ]+).*$}, '\1') unless version.nil?
1816
end
1917
end
2018

21-
Facter.add("ssh_server_version_major") do
22-
confine :kernel => [ 'Linux' , 'SunOS' , 'FreeBSD' , 'Darwin' ]
23-
confine :ssh_server_version_full => true
19+
Facter.add('ssh_server_version_major') do
20+
confine kernel: %w(Linux SunOS FreeBSD Darwin)
21+
confine ssh_server_version_full: true
2422
setcode do
2523
version = Facter.value('ssh_server_version_full')
2624

27-
version.gsub(/^([0-9]+\.[0-9]+).*$/, '\1')
25+
version.gsub(%r{^([0-9]+\.[0-9]+).*$}, '\1')
2826
end
2927
end
3028

31-
Facter.add("ssh_server_version_release") do
32-
confine :kernel => [ 'Linux' , 'SunOS' , 'FreeBSD' , 'Darwin' ]
33-
confine :ssh_server_version_full => true
29+
Facter.add('ssh_server_version_release') do
30+
confine kernel: %w(Linux SunOS FreeBSD Darwin)
31+
confine ssh_server_version_full: true
3432
setcode do
3533
version = Facter.value('ssh_server_version_full')
3634

37-
version.gsub(/^([0-9]+\.[0-9]+(?:\.[0-9]+)?).*$/, '\1')
35+
version.gsub(%r{^([0-9]+\.[0-9]+(?:\.[0-9]+)?).*$}, '\1')
3836
end
3937
end
Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,34 @@
11
module Puppet::Parser::Functions
2-
newfunction(:ipaddresses, :type => :rvalue, :doc => <<-EOS
2+
newfunction(:ipaddresses, type: :rvalue, doc: <<-EOS
33
Returns all ip addresses of network interfaces (except lo) found by facter.
44
EOS
5-
) do |args|
6-
interfaces = lookupvar('interfaces')
5+
) do |_args|
6+
interfaces = lookupvar('interfaces')
77

8-
# In Puppet v2.7, lookupvar returns :undefined if the variable does
9-
# not exist. In Puppet 3.x, it returns nil.
10-
# See http://docs.puppetlabs.com/guides/custom_functions.html
11-
return false if (interfaces.nil? || interfaces == :undefined)
8+
# In Puppet v2.7, lookupvar returns :undefined if the variable does
9+
# not exist. In Puppet 3.x, it returns nil.
10+
# See http://docs.puppetlabs.com/guides/custom_functions.html
11+
return false if interfaces.nil? || interfaces == :undefined
1212

13-
result = []
14-
if interfaces.count(',') > 0
15-
interfaces = interfaces.split(',')
16-
interfaces.each do |iface|
17-
if ! iface.include?('lo')
18-
ipaddr = lookupvar("ipaddress_#{iface}")
19-
ipaddr6 = lookupvar("ipaddress6_#{iface}")
20-
if ipaddr and (ipaddr!= :undefined)
21-
result << ipaddr
22-
end
23-
if ipaddr6 and (ipaddr6!= :undefined)
24-
result << ipaddr6
25-
end
26-
end
27-
end
28-
else
29-
if ! interfaces.include?('lo')
30-
ipaddr = lookupvar("ipaddress_#{interfaces}")
31-
ipaddr6 = lookupvar("ipaddress6_#{interfaces}")
32-
if ipaddr and (ipaddr!= :undefined)
33-
result << ipaddr
34-
end
35-
if ipaddr6 and (ipaddr6!= :undefined)
36-
result << ipaddr6
37-
end
38-
end
39-
end
40-
41-
return result
13+
result = []
14+
if interfaces.count(',') > 0
15+
interfaces = interfaces.split(',')
16+
interfaces.each do |iface|
17+
next if iface.include?('lo')
18+
ipaddr = lookupvar("ipaddress_#{iface}")
19+
ipaddr6 = lookupvar("ipaddress6_#{iface}")
20+
result << ipaddr if ipaddr && (ipaddr != :undefined)
21+
result << ipaddr6 if ipaddr6 && (ipaddr6 != :undefined)
22+
end
23+
else
24+
unless interfaces.include?('lo')
25+
ipaddr = lookupvar("ipaddress_#{interfaces}")
26+
ipaddr6 = lookupvar("ipaddress6_#{interfaces}")
27+
result << ipaddr if ipaddr && (ipaddr != :undefined)
28+
result << ipaddr6 if ipaddr6 && (ipaddr6 != :undefined)
29+
end
4230
end
31+
32+
return result
33+
end
4334
end

spec/classes/client_spec.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
require 'spec_helper'
22

3-
describe 'ssh::client', :type => 'class' do
4-
context "On Debian with no other parameters" do
5-
let :facts do
6-
{
7-
:osfamily => 'Debian',
8-
:interfaces => 'eth0',
9-
:ipaddress_eth0 => '192.168.1.1',
10-
:concat_basedir => '/tmp'
11-
}
12-
end
13-
it {
14-
should contain_package('openssh-client').with(:ensure => 'present')
15-
}
3+
describe 'ssh::client', type: 'class' do
4+
context 'On Debian with no other parameters' do
5+
let :facts do
6+
{
7+
osfamily: 'Debian',
8+
interfaces: 'eth0',
9+
ipaddress_eth0: '192.168.1.1',
10+
concat_basedir: '/tmp'
11+
}
1612
end
17-
context "On Debian with custom ensure" do
18-
let :facts do
19-
{
20-
:osfamily => 'Debian',
21-
:interfaces => 'eth0',
22-
:ipaddress_eth0 => '192.168.1.1',
23-
:concat_basedir => '/tmp'
24-
}
25-
end
26-
let :params do
27-
{
28-
:ensure => 'latest'
29-
}
30-
end
31-
it {
32-
should contain_package('openssh-client').with(:ensure => 'latest')
33-
}
13+
it do
14+
should contain_package('openssh-client').with(ensure: 'present')
3415
end
16+
end
17+
context 'On Debian with custom ensure' do
18+
let :facts do
19+
{
20+
osfamily: 'Debian',
21+
interfaces: 'eth0',
22+
ipaddress_eth0: '192.168.1.1',
23+
concat_basedir: '/tmp'
24+
}
25+
end
26+
let :params do
27+
{
28+
ensure: 'latest'
29+
}
30+
end
31+
it do
32+
should contain_package('openssh-client').with(ensure: 'latest')
33+
end
34+
end
3535
end

spec/classes/init_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
require 'spec_helper'
22

3-
describe 'ssh', :type => 'class' do
4-
context "On Debian with no other parameters" do
5-
let :facts do
6-
{
7-
:osfamily => 'Debian',
8-
:interfaces => 'eth0',
9-
:ipaddress_eth0 => '192.168.1.1',
10-
:concat_basedir => '/tmp'
11-
}
12-
end
13-
it {
14-
should contain_class('ssh::client')
15-
}
16-
it {
17-
should contain_class('ssh::server')
18-
}
3+
describe 'ssh', type: 'class' do
4+
context 'On Debian with no other parameters' do
5+
let :facts do
6+
{
7+
osfamily: 'Debian',
8+
interfaces: 'eth0',
9+
ipaddress_eth0: '192.168.1.1',
10+
concat_basedir: '/tmp'
11+
}
1912
end
13+
it do
14+
should contain_class('ssh::client')
15+
end
16+
it do
17+
should contain_class('ssh::server')
18+
end
19+
end
2020
end

0 commit comments

Comments
 (0)