Class: ExpiryScanner
- Inherits:
-
Object
- Object
- ExpiryScanner
- Defined in:
- app/models/expiry_scanner.rb
Overview
Adding comment to trigger manifest deployment
Constant Summary collapse
- REMAINING_DAYS =
60
- URGENT_REMAINING_DAYS =
30
- API_PATH =
'https://slack.com/api/chat.postMessage'
Class Method Summary collapse
- .define_expiry_urgency(cert_path) ⇒ Object
- .directories ⇒ Object
- .request_body(message) ⇒ Object
- .request_headers ⇒ Object
- .scan_certs ⇒ Object
Class Method Details
.define_expiry_urgency(cert_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/expiry_scanner.rb', line 33 def self.define_expiry_urgency(cert_path) now = DateTime.now cert = OpenSSL::X509::Certificate.new(File.read(cert_path)) expiry = cert.not_after.to_datetime return nil if expiry > now + REMAINING_DAYS if now + URGENT_REMAINING_DAYS > expiry "URGENT: #{cert_path} expires in less than #{URGENT_REMAINING_DAYS} days: #{expiry}" else "ATTENTION: #{cert_path} expires in less than #{REMAINING_DAYS} days: #{expiry}" end end |
.directories ⇒ Object
60 61 62 |
# File 'app/models/expiry_scanner.rb', line 60 def self.directories Settings.expiry_scanner.directories end |
.request_body(message) ⇒ Object
46 47 48 49 50 51 |
# File 'app/models/expiry_scanner.rb', line 46 def self.request_body() { text: , channel: Settings.expiry_scanner.slack.channel_id }.to_json end |
.request_headers ⇒ Object
53 54 55 56 57 58 |
# File 'app/models/expiry_scanner.rb', line 53 def self.request_headers { 'Content-type' => 'application/json; charset=utf-8', 'Authorization' => "Bearer #{Settings.argocd.slack.api_key}" } end |
.scan_certs ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/expiry_scanner.rb', line 15 def self.scan_certs result = false = ["Vets-Api #{Settings.vsp_environment} - SSL certificate scan result"] cert_paths = Dir.glob(directories) cert_paths.each do |cert_path| if File.extname(cert_path) == '.pem' || File.extname(cert_path) == '.crt' = define_expiry_urgency(cert_path) if .present? << result = true end end rescue Rails.logger.debug { "ERROR: Could not parse certificate #{cert_path}" } end Faraday.post(API_PATH, request_body(.join("\n")), request_headers) if result end |