SuperTux88's Diaspora Saltstack Formula
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

70 lines
1.4KB

  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. @platform = build_platform
  10. end
  11. private
  12. def build_platform
  13. {
  14. family: build_platform_family,
  15. name: build_platform_name,
  16. release: build_platform_release,
  17. finger: build_platform_finger
  18. }
  19. end
  20. def build_platform_family
  21. case inspec.platform[:name]
  22. when 'arch'
  23. 'arch'
  24. else
  25. inspec.platform[:family]
  26. end
  27. end
  28. def build_platform_name
  29. case inspec.platform[:name]
  30. when 'amazon'
  31. 'amazonlinux'
  32. else
  33. inspec.platform[:name]
  34. end
  35. end
  36. def build_platform_release
  37. case inspec.platform[:name]
  38. when 'amazon'
  39. # `2018` relase is named `1` in kitchen.yaml
  40. inspec.platform[:release].gsub(/2018.*/, '1')
  41. when 'arch'
  42. 'base-latest'
  43. else
  44. inspec.platform[:release]
  45. end
  46. end
  47. def build_platform_finger
  48. "#{build_platform_name}-#{build_finger_release}"
  49. end
  50. def build_finger_release
  51. case inspec.platform[:name]
  52. when 'ubuntu'
  53. build_platform_release.split('.').slice(0, 2).join('.')
  54. else
  55. build_platform_release.split('.')[0]
  56. end
  57. end
  58. end