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

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Instance Method Details

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



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/dnsmadeeasy/cli/commands/zone.rb', line 179

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

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

  plan_domain = domain || desired_result.value!.origin
  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
  ).call
  renderer = DnsMadeEasy::Zone::PlanRenderer.new(plan)

  puts(format == 'json' ? renderer.to_json : renderer.to_text)
end