Class: DnsMadeEasy::CLI::Commands::Zone::Plan

Inherits:
Base
  • Object
show all
Includes:
DomainArguments
Defined in:
lib/dnsmadeeasy/cli/commands/zone.rb

Overview

Produces a non-destructive plan comparing a zone file to remote records.

Constant Summary

Constants inherited from Base

Base::DEFAULT_CREDENTIAL_PATHS, Base::SUPPORTED_FORMATS

Constants included from MessageHelpers

MessageHelpers::BOX_OPTIONS, MessageHelpers::KEY_WIDTH

Instance Method Summary collapse

Methods included from MessageHelpers

error, included, info, kv, print_box, success, warn

Instance Method Details

#call(domain:, file:, format: 'text', diff_ttl: false, credentials: nil, api_key: nil, api_secret: nil) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/dnsmadeeasy/cli/commands/zone.rb', line 233

def call(domain:, file:, format: 'text', diff_ttl: false, credentials: nil, api_key: nil, api_secret: nil, **)
  configure_authentication(credentials: credentials, api_key: api_key, api_secret: api_secret)

  desired_result = DnsMadeEasy::Zone::Parser.new(read_zone_source!(file, domain: domain)).call
  return fail_with('Zone file is invalid', desired_result.failure) if desired_result.failure?

  ensure_origin_matches!(domain: domain, origin: desired_result.value!.origin)

  plan_domain = normalize_domain(domain)
  remote_result = remote_records(plan_domain)
  return fail_with('Remote records are invalid', remote_result.failure) if remote_result.failure?

  plan = DnsMadeEasy::Zone::Diff.new(
    desired_records: desired_result.value!.records,
    remote_records: remote_result.value!.records,
    compare_ttl: diff_ttl
  ).call
  renderer = DnsMadeEasy::Zone::PlanRenderer.new(plan)

  puts(format == 'json' ? renderer.to_json : renderer.to_text)
  success(plan_summary(plan_domain, plan))
end