# frozen_string_literal: true require_relative "base" module Neetob class CLI module Sre class Checklist < Base attr_accessor :app, :environment def initialize(app, environment) super() @app = app @environment = environment end def run raise(StandardError, "Environment should be staging or production.") unless environments.include?(environment) app_info = RESOURCES[app.to_sym][environment.to_sym] domain = app_info[:dns] app_name = app_info[:app] ui.info "Validating the SRE checklist for #{app} in the #{environment} environment..." ui.info "SSL mode" ui.info `neetob cloudflare ssl_mode -d #{domain} | sed 's/^/ /'` ui.info "Validating CDN" ui.info `neetob cloudflare ensure_cdn -a #{app_name} | sed 's/^/ /'` ui.info "DNS Proxy status" ui.info `neetob cloudflare dns_proxy -d #{domain} | sed 's/^/ /'` ui.info "Minimum TLS version" ui.info `neetob cloudflare min_tls_version -d #{domain} | sed 's/^/ /'` ui.info "HTTPS redirect" ui.info `neetob cloudflare always_use_https -d #{domain} | sed 's/^/ /'` ui.info "Bot fight mode" ui.info `neetob cloudflare bot_fight_mode -d #{domain} | sed 's/^/ /'` ui.info "Validating SPF records" ui.info `neetob cloudflare verify_spf -d #{domain} | sed 's/^/ /'` if is_heroku(app_name) ui.info "Heroku maintenance time" ui.info `neetob heroku maintenance_window -a #{app_name} | sed 's/^/ /'` ui.info "Heroku stack" ui.info `neetob heroku stack -a #{app_name} | sed 's/^/ /'` ui.info "Heroku autoscaling enabled" ui.info `neetob heroku autoscaling_config -a #{app_name} | sed 's/^/ /'` else ui.info "NeetoDeploy autoscaling status" ui.info `neetodeploy autoscaling_config list -a #{app_name} | sed 's/^/ /'` ui.info "Scheduled exports status" ui.info `neetodeploy addon scheduled_exports_enabled -a #{app_name} | sed 's/^/ /'` end ui.info "Validating essential envs" ui.info `neetob sre check_essential_env -a #{app_name} | sed 's/^/ /'` end private def environments ["staging", "production"] end def pretty_print(command) ui.info `echo #{command} | sed 's/^/ /'` end end end end end