Skip to content

Commit

Permalink
Fix for password secret
Browse files Browse the repository at this point in the history
  • Loading branch information
Genki Sugawara committed Aug 2, 2016
1 parent ceb6a54 commit a018628
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -12,6 +12,8 @@ It defines the state of MySQL permissions using Ruby DSL, and updates permission

* `>= 0.3.0`
* Support template
* `>= 0.3.1`
* Fix `<secret>` password

## Installation

Expand Down Expand Up @@ -61,6 +63,7 @@ Usage: gratan [options]
--ignore-object REGEXP
--enable-expired
--ignore-not-exist
--ignore-password-secret
--skip-disable-log-bin
--no-color
--debug
Expand Down
49 changes: 25 additions & 24 deletions bin/gratan
Expand Up @@ -30,30 +30,31 @@ options = {

ARGV.options do |opt|
begin
opt.on('' , '--host HOST') {|v| mysql_options[:host] = v }
opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v }
opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v }
opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v }
opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v }
opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v }
opt.on('-a', '--apply') { mode = :apply }
opt.on('-f', '--file FILE') {|v| file = v }
opt.on('' , '--dry-run') { options[:dry_run] = true }
opt.on('-e', '--export') { mode = :export }
opt.on('' , '--with-identifier') { options[:with_identifier] = true }
opt.on('' , '--split') { split = true }
opt.on('' , '--chunk-by-user') { options[:chunk_by_user] = true }
opt.on('-o', '--output FILE') {|v| output_file = v }
opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) }
opt.on('' , '--ignore-object REGEXP') {|v| options[:ignore_object] = Regexp.new(v) }
opt.on('' , '--enable-expired') { options[:enable_expired] = true }
opt.on('' , '--ignore-not-exist') {|v| options[:ignore_not_exist] = true }
opt.on('' , '--skip-disable-log-bin') { options[:skip_disable_log_bin] = true }
opt.on('' , '--no-color') { options[:color] = false }
opt.on('' , '--debug') { options[:debug] = true }
opt.on('' , '--auto-identify OUTPUT') {|v| options[:identifier] = Gratan::Identifier::Auto.new(v, options) }
opt.on('' , '--csv-identify CSV') {|v| options[:identifier] = Gratan::Identifier::CSV.new(v, options) }
opt.on('' , '--host HOST') {|v| mysql_options[:host] = v }
opt.on('' , '--port PORT', Integer) {|v| mysql_options[:port] = v }
opt.on('' , '--socket SOCKET') {|v| mysql_options[:socket] = v }
opt.on('' , '--username USERNAME') {|v| mysql_options[:username] = v }
opt.on('' , '--password PASSWORD') {|v| mysql_options[:password] = v }
opt.on('' , '--database DATABASE') {|v| mysql_options[:database] = v }
opt.on('-a', '--apply') { mode = :apply }
opt.on('-f', '--file FILE') {|v| file = v }
opt.on('' , '--dry-run') { options[:dry_run] = true }
opt.on('-e', '--export') { mode = :export }
opt.on('' , '--with-identifier') { options[:with_identifier] = true }
opt.on('' , '--split') { split = true }
opt.on('' , '--chunk-by-user') { options[:chunk_by_user] = true }
opt.on('-o', '--output FILE') {|v| output_file = v }
opt.on('' , '--ignore-user REGEXP') {|v| options[:ignore_user] = Regexp.new(v) }
opt.on('' , '--target-user REGEXP') {|v| options[:target_user] = Regexp.new(v) }
opt.on('' , '--ignore-object REGEXP') {|v| options[:ignore_object] = Regexp.new(v) }
opt.on('' , '--enable-expired') { options[:enable_expired] = true }
opt.on('' , '--ignore-not-exist') {|v| options[:ignore_not_exist] = true }
opt.on('' , '--ignore-password-secret') {|v| options[:ignore_password_secret] = true }
opt.on('' , '--skip-disable-log-bin') { options[:skip_disable_log_bin] = true }
opt.on('' , '--no-color') { options[:color] = false }
opt.on('' , '--debug') { options[:debug] = true }
opt.on('' , '--auto-identify OUTPUT') {|v| options[:identifier] = Gratan::Identifier::Auto.new(v, options) }
opt.on('' , '--csv-identify CSV') {|v| options[:identifier] = Gratan::Identifier::CSV.new(v, options) }

opt.on('' , '--mysql2-options JSON') do |json|
json = JSON.parse(json)
Expand Down
8 changes: 7 additions & 1 deletion lib/gratan/client.rb
@@ -1,4 +1,6 @@
class Gratan::Client
include Gratan::Logger::Helper

def initialize(options = {})
@options = options
@options[:identifier] ||= Gratan::Identifier::Null.new
Expand Down Expand Up @@ -130,7 +132,11 @@ def walk_options(user, host, expected_options, actual_options)
end

def walk_identified(user, host, expected_identified, actual_identified)
if expected_identified != actual_identified
if actual_identified == 'PASSWORD <secret>'
unless @options[:ignore_password_secret]
log(:warn, "cannot change the password (`PASSWORD <secret>`)", :color => :yellow)
end
elsif expected_identified != actual_identified
@driver.identify(user, host, expected_identified)
update!
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gratan/version.rb
@@ -1,3 +1,3 @@
module Gratan
VERSION = '0.3.0'
VERSION = '0.3.1.beta'
end

0 comments on commit a018628

Please sign in to comment.