From 8935d7834c1ba894d5b574b112a79435782a6858 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 10 May 2018 17:59:37 -0400 Subject: [PATCH] Warn when we're running fix_auth in dry run mode https://bugzilla.redhat.com/show_bug.cgi?id=1577303 It's very easy to use -d incorrectly as the database name. We should remove the short option -d (for dry run) since it conflicts with pg_dump and other tooling for postgresql but regardless, we should have obvious feedback that we're in dry run mode. **Fix database.yml output with dry run** ``` $ tools/fix_auth.rb -h localhost -U root --password smartvm --hardcode bogus vmdb_development -d --verbose -y ** fix_database_yml is executing in dry-run mode, and no actual changes will be made** fixing /Users/joerafaniello/Code/manageiq/config/database.yml.yaml /Users/joerafaniello/Code/manageiq/config/database.yml: yaml: viewed 1 records ** This was executed in dry-run, and no actual changes will be made to /Users/joerafaniello/Code/manageiq/config/database.yml ** ``` **Fix database passwords with dry run** ``` $ tools/fix_auth.rb -h localhost -U root --password smartvm --hardcode bogus vmdb_development -d --verbose ** fix_database_passwords is executing in dry-run mode, and no actual changes will be made** fixing authentications.password, auth_key viewed 0 records fixing miq_databases.registration_http_proxy_server, session_secret_token, csrf_secret_token 1: session_secret_token: "v2:{...}" => v2:{...} csrf_secret_token: "v2:{...}" => v2:{...} viewed 1 records ** This was executed in dry-run, and no actual changes will be made to miq_databases ** fixing miq_ae_values.value viewed 0 records fixing miq_ae_fields.default_value viewed 0 records fixing settings_changes.value viewed 0 records fixing miq_requests.options viewed 0 records fixing miq_request_tasks.options viewed 0 records ``` --- tools/fix_auth/auth_model.rb | 3 +++ tools/fix_auth/fix_auth.rb | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/tools/fix_auth/auth_model.rb b/tools/fix_auth/auth_model.rb index 9e37d55694d..471423af6d6 100644 --- a/tools/fix_auth/auth_model.rb +++ b/tools/fix_auth/auth_model.rb @@ -87,6 +87,7 @@ def run(options = {}) puts "fixing #{table_name}.#{available_columns.join(", ")}" unless options[:silent] processed = 0 errors = 0 + would_make_changes = false contenders.each do |r| begin fix_passwords(r, options) @@ -96,6 +97,7 @@ def run(options = {}) display_column(r, column, options) end end + would_make_changes ||= r.changed? r.save! if !options[:dry_run] && r.changed? processed += 1 rescue ArgumentError # undefined class/module @@ -111,6 +113,7 @@ def run(options = {}) end puts "#{options[:dry_run] ? "viewed" : "processed"} #{processed} records" unless options[:silent] puts "found #{errors} errors" if errors > 0 && !options[:silent] + puts "** This was executed in dry-run, and no actual changes will be made to #{table_name} **" if would_make_changes && options[:dry_run] end def clean_up diff --git a/tools/fix_auth/fix_auth.rb b/tools/fix_auth/fix_auth.rb index 46d5ba4b56e..36ba21cf432 100644 --- a/tools/fix_auth/fix_auth.rb +++ b/tools/fix_auth/fix_auth.rb @@ -50,7 +50,15 @@ def generate_password raise Errno::EEXIST, e.message end + def print_dry_run_warning + method = caller_locations.first.label + # Move this message up to `run` if the other methods add dry-run support + puts "** #{method} is executing in dry-run mode, and no actual changes will be made **" if options[:dry_run] + end + def fix_database_passwords + print_dry_run_warning + begin # in specs, this is already setup ActiveRecord::Base.connection_config @@ -65,6 +73,7 @@ def fix_database_passwords end def fix_database_yml + print_dry_run_warning FixDatabaseYml.file_name = "#{options[:root]}/config/database.yml" FixDatabaseYml.run({:hardcode => options[:password]}.merge(run_options)) end