Saltstack Official Logrotate 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.

139 lines
3.6KB

  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. # rubocop:disable Metrics/ClassLength
  6. class SystemResource < Inspec.resource(1)
  7. name 'system'
  8. attr_reader :platform
  9. def initialize
  10. super
  11. @platform = build_platform
  12. end
  13. private
  14. def build_platform
  15. {
  16. family: build_platform_family,
  17. name: build_platform_name,
  18. release: build_platform_release,
  19. finger: build_platform_finger,
  20. codename: build_platform_codename
  21. }
  22. end
  23. def build_platform_family
  24. case inspec.platform[:name]
  25. when 'arch', 'gentoo'
  26. inspec.platform[:name]
  27. else
  28. inspec.platform[:family]
  29. end
  30. end
  31. def build_platform_name
  32. case inspec.platform[:name]
  33. when 'amazon', 'oracle', 'rocky'
  34. "#{inspec.platform[:name]}linux"
  35. when /^windows_/
  36. inspec.platform[:family]
  37. else
  38. inspec.platform[:name]
  39. end
  40. end
  41. # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  42. def build_platform_release
  43. case inspec.platform[:name]
  44. when 'amazon'
  45. # `2018` relase is named `1` in `kitchen.yml`
  46. inspec.platform[:release].gsub(/2018.*/, '1')
  47. when 'arch'
  48. 'base-latest'
  49. when 'gentoo'
  50. "#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
  51. when 'mac_os_x'
  52. inspec.command('sw_vers -productVersion').stdout.to_s
  53. when 'opensuse'
  54. # rubocop:disable Style/NumericLiterals,Layout/LineLength
  55. inspec.platform[:release].to_i > 20210101 ? 'tumbleweed' : inspec.platform[:release]
  56. # rubocop:enable Style/NumericLiterals,Layout/LineLength
  57. when 'windows_8.1_pro'
  58. '8.1'
  59. when 'windows_server_2022_datacenter'
  60. '2022-server'
  61. when 'windows_server_2019_datacenter'
  62. '2019-server'
  63. when 'windows_server_2016_datacenter'
  64. '2016-server'
  65. else
  66. inspec.platform[:release]
  67. end
  68. end
  69. # rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  70. def derive_gentoo_init_system
  71. inspec.command('systemctl').exist? ? 'sysd' : 'sysv'
  72. end
  73. def build_platform_finger
  74. "#{build_platform_name}-#{build_finger_release}"
  75. end
  76. def build_finger_release
  77. case inspec.platform[:name]
  78. when 'ubuntu'
  79. build_platform_release.split('.').slice(0, 2).join('.')
  80. else
  81. build_platform_release.split('.')[0]
  82. end
  83. end
  84. # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
  85. def build_platform_codename
  86. case build_platform_finger
  87. when 'ubuntu-22.04'
  88. 'jammy'
  89. when 'ubuntu-20.04'
  90. 'focal'
  91. when 'ubuntu-18.04'
  92. 'bionic'
  93. when 'debian-11'
  94. 'bullseye'
  95. when 'debian-10'
  96. 'buster'
  97. when 'debian-9'
  98. 'stretch'
  99. when 'almalinux-8'
  100. "AlmaLinux #{build_platform_release} (Arctic Sphynx)"
  101. when 'amazonlinux-2'
  102. 'Amazon Linux 2'
  103. when 'arch-base-latest'
  104. 'Arch Linux'
  105. when 'centos-7'
  106. 'CentOS Linux 7 (Core)'
  107. when 'centos-8'
  108. 'CentOS Stream 8'
  109. when 'opensuse-tumbleweed'
  110. 'openSUSE Tumbleweed'
  111. when 'opensuse-15'
  112. "openSUSE Leap #{build_platform_release}"
  113. when 'oraclelinux-8', 'oraclelinux-7'
  114. "Oracle Linux Server #{build_platform_release}"
  115. when 'gentoo-2-sysd', 'gentoo-2-sysv'
  116. 'Gentoo/Linux'
  117. when 'rockylinux-8'
  118. "Rocky Linux #{build_platform_release} (Green Obsidian)"
  119. else
  120. ''
  121. end
  122. end
  123. # rubocop:enable Metrics/MethodLength,Metrics/CyclomaticComplexity
  124. end
  125. # rubocop:enable Metrics/ClassLength