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.

73 lines
1.6KB

  1. module CryptCheck
  2. module Tls
  3. class Grade
  4. attr_reader :server, :grade, :states
  5. def initialize(server)
  6. @server = server
  7. @checks = checks
  8. @states = calculate_states
  9. @grade = calculate_grade
  10. end
  11. def display
  12. color = case @grade
  13. when 'A', 'A+'
  14. :best
  15. when 'B', 'B+'
  16. :perfect
  17. when 'C', 'C+'
  18. :good
  19. when 'E'
  20. :warning
  21. when 'F'
  22. :error
  23. when 'G'
  24. :critical
  25. when 'M', 'T'
  26. :unknown
  27. end
  28. Logger.info { "Grade : #{self.grade.colorize color }" }
  29. Logger.info { '' }
  30. Status.each do |color|
  31. states = @states[color]
  32. Logger.info { "#{color.to_s.capitalize} : #{states.collect { |s| s.to_s.colorize color }.join ' '}" } unless states.empty?
  33. end
  34. end
  35. private
  36. def calculate_grade
  37. case
  38. when !@states[:critical].empty?
  39. return 'G'
  40. when !@states[:error].empty?
  41. return 'F'
  42. when !@states[:warning].empty?
  43. return 'E'
  44. end
  45. goods = @checks.select { |c| c.last == :good }.collect &:first
  46. unless goods.empty?
  47. return 'D' if @states[:good].empty?
  48. return 'C' if @states[:good] != goods
  49. end
  50. perfects = @checks.select { |c| c.last == :perfect }.collect &:first
  51. unless perfects.empty?
  52. return 'C+' if @states[:perfect].empty?
  53. return 'B' if @states[:perfect] != perfects
  54. end
  55. bests = @checks.select { |c| c.last == :best }.collect &:first
  56. unless bests.empty?
  57. return 'B+' if @states[:best].empty?
  58. return 'A' if @states[:best] != bests
  59. end
  60. 'A+'
  61. end
  62. end
  63. end
  64. end