X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Frm%2Frm_runner.rb;h=1c2d344475e27d3f763553d15dfbbfb37fbe4d40;hp=114aabc355ad1c215f0b95e3cf1f20a2a626ea4d;hb=fa7782720ff15fce29b6f875678e9fd0c197485a;hpb=483d14dc8228a81d12fb109d3ed6510e2d2b03c1 diff --git a/lib/rm/rm_runner.rb b/lib/rm/rm_runner.rb index 114aabc..1c2d344 100644 --- a/lib/rm/rm_runner.rb +++ b/lib/rm/rm_runner.rb @@ -1,41 +1,51 @@ +require 'common/errors' require 'common/runner' +# Perform the removal of users/domains using {RmPlugin}s. +# class RmRunner include Runner - def run(plugin, *targets) + # Run *plugin* to remove the users/domains in *targets*. The method + # signature includes the unused *cfg* for consistency with the + # runners that do need a {Configuration}. + # + # @param cfg [Configuration] unused. + # + # @param plugin [Class] plugin class that will perform the removal. + # + # @param targets [Array] the users and domains to be + # removed. + # + def run(cfg, plugin, *targets) targets.each do |target| - # Why think too hard? An account has an @, a domain doesn't. - if target.include?('@') then - begin - account_description = plugin.describe_account(target) - plugin.delete_account(target) - report(plugin, "Removed account: #{target} (#{account_description})") + remove_target(plugin, target) + end + end - rescue NonexistentAccountError => e - report(plugin, "Account not found: #{e.to_s}") - rescue StandardError => e - report(plugin, "There was an error removing the account: #{e.to_s}") - Kernel.exit(ExitCodes::DATABASE_ERROR) - end - else - begin - domain_description = plugin.describe_domain(target) - plugin.delete_domain(target) - report(plugin, "Removed domain: #{target} (#{domain_description})") - rescue NonexistentAccountError => e - # Can happen in the usernames.each... block. - report(plugin, "Account not found: #{e.to_s}") - rescue NonexistentDomainError => e - report(plugin, "Domain not found: #{e.to_s}") - rescue StandardError => e - report(plugin, "There was an error removing the domain: #{e.to_s}") - Kernel.exit(ExitCodes::DATABASE_ERROR) - end - end - end + protected; - end + # Remove *target* using *plugin*. This operation is separate from + # the run() method so that it can be accessed by the prune + # runner. + # + # @param plugin [RmPlugin] the plugin that will remove the *target*. + # + # @param target [User,Domain] the user or domain to remove. + # + def remove_target(plugin, target) + target_description = plugin.describe(target) + begin + plugin.remove(target) + msg = "Removed #{target.class.to_s().downcase()} " + msg += add_description(target, target_description) + msg += '.' + + report(plugin, msg) + rescue NonexistentDomainError, NonexistentUserError => e + report(plugin, "#{target.class.to_s()} #{e.to_s} not found.") + end + end end