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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.yaml
  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_2019_datacenter'
  56. '2019-server'
  57. when 'windows_server_2016_datacenter'
  58. '2016-server'
  59. else
  60. inspec.platform[:release]
  61. end
  62. end
  63. # rubocop:enable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
  64. def derive_gentoo_init_system
  65. inspec.command('systemctl').exist? ? 'sysd' : 'sysv'
  66. end
  67. def build_platform_finger
  68. "#{build_platform_name}-#{build_finger_release}"
  69. end
  70. def build_finger_release
  71. case inspec.platform[:name]
  72. when 'ubuntu'
  73. build_platform_release.split('.').slice(0, 2).join('.')
  74. else
  75. build_platform_release.split('.')[0]
  76. end
  77. end
  78. end