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

90 line
1.9KB

  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'
  32. "#{inspec.platform[:name]}linux"
  33. when 'windows_8.1_pro', 'windows_server_2019_datacenter'
  34. 'windows'
  35. else
  36. inspec.platform[:name]
  37. end
  38. end
  39. # rubocop:disable Metrics/MethodLength
  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 'windows_8.1_pro'
  50. '8.1'
  51. when 'windows_server_2019_datacenter'
  52. '2019-server'
  53. else
  54. inspec.platform[:release]
  55. end
  56. end
  57. # rubocop:enable Metrics/MethodLength
  58. def derive_gentoo_init_system
  59. case inspec.command('systemctl').exist?
  60. when true
  61. 'sysd'
  62. else
  63. 'sysv'
  64. end
  65. end
  66. def build_platform_finger
  67. "#{build_platform_name}-#{build_finger_release}"
  68. end
  69. def build_finger_release
  70. case inspec.platform[:name]
  71. when 'ubuntu'
  72. build_platform_release.split('.').slice(0, 2).join('.')
  73. else
  74. build_platform_release.split('.')[0]
  75. end
  76. end
  77. end