Class: Neetob::CLI::MonthlyAudit::InstancesAndAddons::NeetoDeployOrHeroku::CloudfrontCdnEnabled

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/monthly_audit/instances_and_addons/neeto_deploy_or_heroku/cloudfront_cdn_enabled.rb

Constant Summary

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initializeCloudfrontCdnEnabled

Returns a new instance of CloudfrontCdnEnabled.



10
11
12
# File 'lib/neetob/cli/monthly_audit/instances_and_addons/neeto_deploy_or_heroku/cloudfront_cdn_enabled.rb', line 10

def initialize
  super()
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/neetob/cli/monthly_audit/instances_and_addons/neeto_deploy_or_heroku/cloudfront_cdn_enabled.rb', line 14

def run
  ui.success "### 3.1.2. Checking whether Cloudfront CDN is enabled"

  apps_data = [["App", "ASSET_HOST value", "Comments", "Audit Passed"]]
  ui.info("\n", print_to_audit_log: false)
  Neetob::CLI::Sre::Base::APPS_LIST[:neetodeploy].select { |app| app.include?("production") }.each do |app|
    ui.info("Checking ASSET_HOST value for #{app}", print_to_audit_log: false)
    config_vars_result = Neetob::CLI::NeetoDeploy::ConfigVars::List.new([app]).run
    begin
      config_vars = JSON.parse(config_vars_result.first)
    rescue JSON::ParserError
      config_vars = config_vars_result.first
    end
    audit_passed = nil
    comments = nil
    asset_host_value = nil
    repo = app.gsub("-production", "")
    if config_vars.is_a?(Hash) && config_vars["error"] == "Forbidden"
      audit_passed = "No"
      comments = "You do not have permission to access the config vars for this app."
    else
      asset_host_line = config_vars.split("\n").select { |line| line.include?("ASSET_HOST") }.first
      if asset_host_line.nil?
        audit_passed = "No"
        comments = "ASSET_HOST value not found."
        issue_url = GithubIssueCreation.new.create_issue(
          repo:, title: "Cloudfront CDN audit failed",
          description: comments)
        audit_passed += " #{issue_url}"
      else
        asset_host_value = asset_host_line.split("|")[2].strip
        is_direct_cloudfront_asset_host = asset_host_value.include?("cloudfront.net")
        is_cdn_subdomain_asset_host = asset_host_value == "cdn.#{app.gsub("-web-production", "").gsub("-", "")}.com"
        audit_passed = is_direct_cloudfront_asset_host || is_cdn_subdomain_asset_host ? "Yes" : "No"
        if audit_passed == "No"
          comments = "ASSET_HOST value is not a Cloudfront CDN URL or a CDN subdomain URL."
          issue_url = GithubIssueCreation.new.create_issue(
            repo:, title: "Set ASSET_HOST to a valid Cloudfront CDN URL",
            description: comments)
          audit_passed += " #{issue_url}"
        end
      end
    end

    apps_data << [app, asset_host_value, comments, audit_passed]
  end
  Neetob::CLI::Sre::Base::APPS_LIST[:heroku].select { |app| app.include?("production") }.each do |app|
    ui.info("Checking ASSET_HOST value for #{app}", print_to_audit_log: false)
    config_vars_result = Neetob::CLI::Heroku::ConfigVars::List.new([app]).run[0]
    asset_host_value = config_vars_result["ASSET_HOST"]
    if asset_host_value.nil?
      audit_passed = "No"
      comments = "ASSET_HOST value not found."
    else
      is_direct_cloudfront_asset_host = asset_host_value.include?("cloudfront.net")
      is_cdn_subdomain_asset_host = asset_host_value == "cdn.#{app.gsub("-web-production", "").gsub("-", "")}.com"
      audit_passed = is_direct_cloudfront_asset_host || is_cdn_subdomain_asset_host ? "Yes" : "No"
      if audit_passed == "No"
        comments = "ASSET_HOST value is not a Cloudfront CDN URL or a CDN subdomain URL."
      end
    end
    apps_data << [app, asset_host_value, comments, audit_passed]
  end
  ui.print_table(apps_data)
end