Skip to content

Commit 2d184e2

Browse files
authored
Merge pull request #23382 from kbrock/v2_key_comments
Update fix_auth verbiage
2 parents 33a150b + a34a0dc commit 2d184e2

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

tools/fix_auth/auth_model.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def run(options = {})
102102

103103
puts "fixing #{table_name}.#{available_columns.join(", ")}" unless options[:silent]
104104
processed = 0
105+
records_changed = 0
105106
errors = 0
106-
would_make_changes = false
107107
contenders.each do |r|
108108
begin
109109
fix_passwords(r, options)
@@ -113,7 +113,7 @@ def run(options = {})
113113
display_column(r, column, options)
114114
end
115115
end
116-
would_make_changes ||= r.changed?
116+
records_changed += 1 if r.changed?
117117
r.save! if !options[:dry_run] && r.changed?
118118
processed += 1
119119
rescue ArgumentError # undefined class/module
@@ -127,9 +127,8 @@ def run(options = {})
127127
puts "processed #{processed} with #{errors} errors"
128128
end
129129
end
130-
puts "#{options[:dry_run] ? "viewed" : "processed"} #{processed} records" unless options[:silent]
130+
puts "#{records_changed} of #{processed} records #{options[:dry_run] ? 'would change (dry run enabled)' : 'changed'}" unless options[:silent]
131131
puts "found #{errors} errors" if errors > 0 && !options[:silent]
132-
puts "** This was executed in dry-run, and no actual changes will be made to #{table_name} **" if would_make_changes && options[:dry_run]
133132
end
134133

135134
def clean_up

tools/fix_auth/cli.rb

+15-8
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,37 @@ class Cli
77
def parse(args, env = {})
88
args.shift if args.first == "--" # Handle when called through script/runner
99
self.options = Optimist.options(args) do
10-
banner "Usage: ruby #{$PROGRAM_NAME} [options] database [...]\n" \
11-
" ruby #{$PROGRAM_NAME} [options] -P new_password database [...] to replace all passwords"
10+
banner "Usage: #{File.basename($PROGRAM_NAME)} [options] database # to migrate from a different or lost key\n" \
11+
" #{File.basename($PROGRAM_NAME)} -P new_password --databaseyml # to fix database.yml\n" \
12+
" #{File.basename($PROGRAM_NAME)} --key # to generate a new certs/v2_key "
1213

1314
opt :verbose, "Verbose", :short => "v"
1415
opt :dry_run, "Dry Run", :short => "d"
1516
opt :hostname, "Database Hostname", :type => :string, :short => "h", :default => env['PGHOST']
1617
opt :port, "Database Port", :type => :integer, :default => 5432
1718
opt :username, "Database Username", :type => :string, :short => "U", :default => (env['PGUSER'] || "root")
1819
opt :password, "Database Password", :type => :string, :short => "p", :default => env['PGPASSWORD']
19-
opt :hardcode, "Password to use for all passwords", :type => :string, :short => "P"
20-
opt :invalid, "Password to use for invalid passwords", :type => :string, :short => "i"
21-
opt :key, "Generate key", :type => :boolean, :short => "k"
20+
opt :hardcode, "Password used to replace all passwords", :type => :string, :short => "P"
21+
opt :invalid, "Password used to replace non-decryptable passwords", :type => :string, :short => "i"
22+
opt :key, "Generate encryption key", :type => :boolean, :short => "k"
2223
opt :v2, "ignored, available for backwards compatibility", :type => :boolean, :short => "f"
2324
opt :root, "Rails Root", :type => :string, :short => "r",
2425
:default => (env['RAILS_ROOT'] || File.expand_path(File.join(File.dirname(__FILE__), %w[.. ..])))
25-
opt :databaseyml, "Rewrite database.yml", :type => :boolean, :short => "y", :default => false
26+
opt :databaseyml, "Fix database.yml", :type => :boolean, :short => "y", :default => false
2627
opt :db, "Upgrade database", :type => :boolean, :short => 'x', :default => false
27-
opt :legacy_key, "Legacy Key", :type => :string, :short => "K"
28+
opt :legacy_key, "Key used to decrypt old passwords when migrating to new key", :type => :string, :short => "K"
2829
opt :allow_failures, "Run through all records, even with errors", :type => :boolean, :short => nil, :default => false
2930
end
3031

31-
options[:database] = args.first || "vmdb_production"
3232
# default to updating the db
3333
options[:db] = true if !options[:key] && !options[:databaseyml]
34+
35+
# When converting the database, require database name
36+
# When RAILS_ENV specified (aka on the appliance) default to production db
37+
Optimist::die "please specify a database as an argument" if args.empty? && ENV["RAILS_ENV"].nil? && options[:db]
38+
39+
# default to updating
40+
options[:database] = args.first || "vmdb_production"
3441
self.options = options.delete_if { |_n, v| v.blank? }
3542
self
3643
end

tools/fix_auth/fix_auth.rb

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def fix_database_passwords
6767
ActiveRecord::Base.logger = Logger.new("#{options[:root]}/log/fix_auth.log")
6868
ActiveRecord::Base.establish_connection(db_attributes(database))
6969
end
70+
71+
puts "processing database: #{options[:database]}"
72+
7073
models.each do |model|
7174
model.run(run_options)
7275
end

0 commit comments

Comments
 (0)