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.

grade.rb 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module CryptCheck
  2. module Tls
  3. class Grade
  4. attr_reader :server, :grade
  5. def initialize(server)
  6. @server = server
  7. @states = @server.states
  8. @checks = @server.performed_checks
  9. Logger.info { '' }
  10. Logger.ap :checks, @checks
  11. Logger.ap :states, @states
  12. @grade = calculate_grade
  13. color = case @grade
  14. when 'A', 'A+'
  15. :best
  16. when 'B', 'B+'
  17. :perfect
  18. when 'C', 'C+'
  19. :good
  20. when 'E'
  21. :warning
  22. when 'F'
  23. :error
  24. when 'G'
  25. :critical
  26. when 'T', 'V'
  27. :unknown
  28. end
  29. Logger.info { "Grade : #{self.grade.colorize color }" }
  30. end
  31. private
  32. def calculate_grade
  33. return 'V' unless @server.valid?
  34. return 'T' unless @server.trusted?
  35. case
  36. when !@states[:critical].empty?
  37. return 'G'
  38. when !@states[:error].empty?
  39. return 'F'
  40. when !@states[:warning].empty?
  41. return 'E'
  42. end
  43. [[:good, 'D', 'C'],
  44. [:perfect, 'C', 'B'],
  45. [:best, 'B', 'A']].each do |type, score1, score2|
  46. expected = @checks[type]
  47. unless expected.empty?
  48. available = @states[type]
  49. return score1 if available.empty?
  50. missed = expected - available
  51. unless missed.empty?
  52. Logger.info { "Missing #{type} : #{missed}" }
  53. return score2
  54. end
  55. end
  56. end
  57. 'A+'
  58. end
  59. end
  60. end
  61. end