Sha256: 441d24f46cbb334dd762d9be075068d3ace838062d088f434b7838a04278f439

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require 'thor'
require 'canari'
require 'eventmachine'
require 'net/http'
require 'uri'
require 'logger'
require 'yaml'
require 'dalli'

module Canari
  # Command-line interface.
  class CLI < Thor
    desc 'start', 'Start monitoring TLS certificates'
    method_option :config, aliases: %i[c], default: 'canari.yml'
    method_option :domains, aliases: %i[d], default: 'domains.txt'
    def start
      Canari.load_config(options[:config])
      DomainCache.preload(options[:domains])
      run(URI.parse('wss://certstream.calidog.io'))
      loop do
        sleep 1
      end
    end

    def run(uri)
      EM.run do
        EM.connect(uri.host, 443, CertStream) do |stream|
          stream.url = uri.to_s
          stream.start_tls(sni_hostname: uri.host)
        end
      end
    end
  end

  def self.logger
    @logger ||= Logger.new(STDOUT)
  end

  def self.load_config(file)
    config = @config = YAML.safe_load(
      File.open(File.expand_path(file)), [Symbol]
    )
    Mail.defaults do
      delivery_method :smtp, config[:smtp]
    end
  end

  def self.config
    @config
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
canari-0.2.0 lib/canari/cli.rb
canari-0.1.0 lib/canari/cli.rb