Class: Neetob::CLI::Cloudflare::VerifySpf
- Defined in:
- lib/neetob/cli/cloudflare/verify_spf.rb
Constant Summary
Constants inherited from Base
Base::NEETO_DEPLOY_DOCS, Base::ZONE_IDS
Constants inherited from Base
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(domain) ⇒ VerifySpf
constructor
A new instance of VerifySpf.
- #run ⇒ Object
Methods inherited from Base
Methods included from Utils
#camel_case_to_slug, #is_upper?, #symbolize_keys
Constructor Details
#initialize(domain) ⇒ VerifySpf
Returns a new instance of VerifySpf.
11 12 13 14 |
# File 'lib/neetob/cli/cloudflare/verify_spf.rb', line 11 def initialize(domain) super() @domain = domain end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
9 10 11 |
# File 'lib/neetob/cli/cloudflare/verify_spf.rb', line 9 def domain @domain end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/neetob/cli/cloudflare/verify_spf.rb', line 16 def run zone_id = ZONE_IDS[domain.to_sym] raise(StandardError, "Domain '#{domain}' not found.") if zone_id.nil? url = create_url(zone_id, "dns_records") response = get(url) raise(StandardError, "No DNS records found") if response[:result].empty? spf_txt_records = response[:result].filter { |dns| dns[:type] == "TXT" && (dns[:content].start_with?("v=spf1") || dns[:content].start_with?("\"v=spf1")) } if spf_txt_records.count > 1 ui.error("More than one TXT record found for SPF") elsif spf_txt_records.count == 0 ui.success("No TXT record for SPF present") else ui.success("Only one TXT record for SPF present") end spf_txt_records.each_with_index do |dns, index| ui.info("SPF TXT #{index + 1}: #{dns[:content]}") end if spf_txt_records.count == 1 unique_spf_txt_record = spf_txt_records.first if unique_spf_txt_record[:content].end_with?("-all") || unique_spf_txt_record[:content].end_with?("-all\"") ui.success("SPF TXT record is set to hard fail for SPF compliance") else ui.error("SPF TXT record is not set to hard fail for SPF compliance") end end end |