Skip to content

Commit

Permalink
Warn when we're running fix_auth in dry run mode
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
jrafanie committed May 31, 2018
1 parent 5985004 commit 8935d78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/fix_auth/auth_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tools/fix_auth/fix_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8935d78

Please sign in to comment.