Saltstack Official Syslog-NG Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

system.rb 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # frozen_string_literal: true
  2. # system.rb -- InSpec resources for system values
  3. # Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
  4. # Copyright (C) 2020 Daniel Dehennin <daniel.dehennin@ac-dijon.fr>
  5. class SystemResource < Inspec.resource(1)
  6. name 'system'
  7. attr_reader :platform
  8. def initialize
  9. super
  10. @platform = build_platform
  11. end
  12. private
  13. def build_platform
  14. {
  15. family: build_platform_family,
  16. name: build_platform_name,
  17. release: build_platform_release,
  18. finger: build_platform_finger
  19. }
  20. end
  21. def build_platform_family
  22. case inspec.platform[:name]
  23. when 'arch', 'gentoo'
  24. inspec.platform[:name]
  25. else
  26. inspec.platform[:family]
  27. end
  28. end
  29. def build_platform_name
  30. case inspec.platform[:name]
  31. when 'amazon', 'oracle', 'rocky'
  32. "#{inspec.platform[:name]}linux"
  33. when /^windows_/
  34. inspec.platform[:family]
  35. else
  36. inspec.platform[:name]
  37. end
  38. end
  39. # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  40. def build_platform_release
  41. case inspec.platform[:name]
  42. when 'amazon'
  43. # `2018` relase is named `1` in `kitchen.yml`
  44. inspec.platform[:release].gsub(/2018.*/, '1')
  45. when 'arch'
  46. 'base-latest'
  47. when 'gentoo'
  48. "#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
  49. when 'opensuse'
  50. # rubocop:disable Style/NumericLiterals,Layout/LineLength
  51. inspec.platform[:release].to_i > 20210101 ? 'tumbleweed' : inspec.platform[:release]
  52. # rubocop:enable Style/NumericLiterals,Layout/LineLength
  53. when 'windows_8.1_pro'
  54. '8.1'
  55. when 'windows_server_2022_datacenter'
  56. '2022-server'
  57. when 'windows_server_2019_datacenter'
  58. '2019-server'
  59. when 'windows_server_2016_datacenter'
  60. '2016-server'
  61. else
  62. inspec.platform[:release]
  63. end
  64. end
  65. # rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  66. def derive_gentoo_init_system
  67. inspec.command('systemctl').exist? ? 'sysd' : 'sysv'
  68. end
  69. def build_platform_finger
  70. "#{build_platform_name}-#{build_finger_release}"
  71. end
  72. def build_finger_release
  73. case inspec.platform[:name]
  74. when 'ubuntu'
  75. build_platform_release.split('.').slice(0, 2).join('.')
  76. else
  77. build_platform_release.split('.')[0]
  78. end
  79. end
  80. end