Class: Neetob::CLI::MonthlyAudit::InstancesAndAddons::Cloudflare::SpfRecordsAreValid

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/monthly_audit/instances_and_addons/cloudflare/spf_records_are_valid.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

#initializeSpfRecordsAreValid

Returns a new instance of SpfRecordsAreValid.



10
11
12
# File 'lib/neetob/cli/monthly_audit/instances_and_addons/cloudflare/spf_records_are_valid.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
# File 'lib/neetob/cli/monthly_audit/instances_and_addons/cloudflare/spf_records_are_valid.rb', line 14

def run
  ui.success "### 3.2.5. Checking whether SPF records are valid"

  domains_data = [["Domain", "SPF records data", "Comments", "Audit Passed"]]
  ui.info("\n", print_to_audit_log: false)
  Neetob::CLI::Cloudflare::Base::ZONE_IDS.keys.select { |domain|
 domain.to_s.include?(".com") }.map do |domain|
    ui.info("Checking SPF records data for #{domain}", print_to_audit_log: false)
    spf_records_verification_data = Neetob::CLI::Cloudflare::VerifySpf.new(domain).run
    audit_passed = (
      spf_records_verification_data[:hard_fail_not_set_message].present? ||
      spf_records_verification_data[:message].present?
    ) ? "No" : "Yes"
    comments =
      spf_records_verification_data[:hard_fail_not_set_message] ||
      spf_records_verification_data[:message]
    data = spf_records_verification_data[:spf_txt_records].map { |record|
      "#{record[:name]} => #{record[:content]}"
    }.join(", ")

    if audit_passed == "No"
      repo = domain_to_repo(domain.to_s)
      issue_url = GithubIssueCreation.new.create_issue(
        repo:, title: "Fix invalid SPF records for #{domain}",
        description: "#{comments} \n\n SPF records data: #{data}")
      audit_passed += " #{issue_url}"
    end
    domains_data << [domain, data, comments, audit_passed]
  end
  ui.print_table(domains_data)
end