mirror of
https://github.com/saltstack-formulas/sudoers-formula.git
synced 2024-11-30 19:35:26 +01:00
style: fix rubocop
This commit is contained in:
parent
c5acbc696a
commit
d67a06254a
@ -4,47 +4,18 @@
|
|||||||
# Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
|
# Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
|
||||||
# Copyright (C) 2020 Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
|
# Copyright (C) 2020 Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
|
||||||
|
|
||||||
HOSTNAME_CMDS = %w[hostname hostnamectl].freeze
|
|
||||||
HOSTNAME_CMDS_OPT = {
|
|
||||||
'hostname' => '-s',
|
|
||||||
'hostnamectl' => '--static'
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
class SystemResource < Inspec.resource(1)
|
class SystemResource < Inspec.resource(1)
|
||||||
name 'system'
|
name 'system'
|
||||||
|
|
||||||
attr_reader :platform
|
attr_reader :platform
|
||||||
attr_reader :hostname
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
super
|
||||||
@platform = build_platform
|
@platform = build_platform
|
||||||
@hostname = found_hostname
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def found_hostname
|
|
||||||
cmd = guess_hostname_cmd
|
|
||||||
|
|
||||||
unless cmd.exit_status.zero?
|
|
||||||
raise Inspec::Exceptions::ResourceSkipped,
|
|
||||||
"Error running '#{cmd}': #{cmd.stderr}"
|
|
||||||
end
|
|
||||||
|
|
||||||
cmd.stdout.chomp
|
|
||||||
end
|
|
||||||
|
|
||||||
def guess_hostname_cmd
|
|
||||||
HOSTNAME_CMDS.each do |cmd|
|
|
||||||
if inspec.command(cmd).exist?
|
|
||||||
return inspec.command("#{cmd} #{HOSTNAME_CMDS_OPT[cmd]}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
raise Inspec::Exceptions::ResourceSkipped,
|
|
||||||
"Error: #{@platform[:finger]}} has none of #{HOSTNAME_CMDS.join(', ')}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def build_platform
|
def build_platform
|
||||||
{
|
{
|
||||||
family: build_platform_family,
|
family: build_platform_family,
|
||||||
@ -79,11 +50,22 @@ class SystemResource < Inspec.resource(1)
|
|||||||
inspec.platform[:release].gsub(/2018.*/, '1')
|
inspec.platform[:release].gsub(/2018.*/, '1')
|
||||||
when 'arch'
|
when 'arch'
|
||||||
'base-latest'
|
'base-latest'
|
||||||
|
when 'gentoo'
|
||||||
|
"#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
|
||||||
else
|
else
|
||||||
inspec.platform[:release]
|
inspec.platform[:release]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def derive_gentoo_init_system
|
||||||
|
case inspec.command('systemctl').exist?
|
||||||
|
when true
|
||||||
|
'sysd'
|
||||||
|
else
|
||||||
|
'sysv'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def build_platform_finger
|
def build_platform_finger
|
||||||
"#{build_platform_name}-#{build_finger_release}"
|
"#{build_platform_name}-#{build_finger_release}"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user