Skip to content
Permalink
Browse files

Merge pull request #23 from codenize-tools/support_5.7

Support MySQL 5.7
  • Loading branch information...
winebarrel committed Nov 5, 2018
2 parents f3044ed + 2d2b48c commit aaa1e32a9cef1e8fdf3ae791eb5f18ba73b82804
@@ -9,8 +9,8 @@ cache:
- apt
env:
matrix:
- MYSQ_PORT=14406 # MySQL 5.6
- MYSQ_PORT=14407 # MySQL 5.7
- MYSQL57=0 MYSQ_PORT=14406 # MySQL 5.6
- MYSQL57=1 MYSQ_PORT=14407 # MySQL 5.7
before_script:
- sudo service mysql stop
- bundle install
@@ -65,6 +65,8 @@ Usage: gratan [options]
--ignore-not-exist
--ignore-password-secret
--skip-disable-log-bin
--override-sql-mode
--use-show-create-user
--no-color
--debug
--auto-identify OUTPUT
@@ -142,7 +144,7 @@ end
bundle install
docker-compose up -d
bundle exec rake
#MYSQL_PORT=14407 bundle exec rake # MySQL 5.7
# MYSQL57=1 bundle exec rake
```

## Similar tools
@@ -56,6 +56,8 @@ ARGV.options do |opt|
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('' , '--override-sql-mode') { options[:override_sql_mode] = true }
opt.on('' , '--use-show-create-user') { options[:use_show_create_user] = 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) }
@@ -5,7 +5,7 @@ mysql56:
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
mysql57:
image: "mysql:5.6"
image: "mysql:5.7"
ports:
- "14407:3306"
environment:
@@ -245,6 +245,7 @@ def in_progress

begin
@driver.disable_log_bin_local
@driver.override_sql_mode
@updated = false
yield
updated = @updated
@@ -20,6 +20,10 @@ def show_grants(user, host)
end
end

def show_create_user(user, host)
query("SHOW CREATE USER #{quote_user(user, host)}").first.values.first
end

def show_databases
query("SHOW DATABASES").map {|i| i.values.first }
end
@@ -205,6 +209,12 @@ def disable_log_bin_local
end
end

def override_sql_mode
if @options[:override_sql_mode]
query('SET SQL_MODE = ""')
end
end

private

def query(sql)
@@ -18,8 +18,12 @@ def export
next unless user =~ @options[:target_user]
end

if @options[:use_show_create_user]
create_user = @driver.show_create_user(user, host)
end

@driver.show_grants(user, host) do |stmt|
grants << Gratan::GrantParser.parse(stmt)
grants << Gratan::GrantParser.parse(stmt, create_user)
end
end

@@ -1,11 +1,12 @@
class Gratan::GrantParser
def initialize(stmt)
def initialize(stmt, create_user = nil)
@stmt = stmt.strip
@create_user = create_user
@parsed = {}
end

def self.parse(stmt)
parser = self.new(stmt)
def self.parse(stmt, create_user = nil)
parser = self.new(stmt, create_user)
parser.parse!
end

@@ -32,7 +33,12 @@ def parse_require
@stmt.slice!(/\s+REQUIRE\s+(.+?)\z/)
required = $1

if required
if @create_user
@create_user.slice!(/\s+REQUIRE\s+(\S+(?:\s+'[^']+')?)(?:\s+.+)?\s+PASSWORD\s+.+\z/)
required = $1
end

if required && required != 'NONE'
@parsed[:require] = required.strip
end
end
@@ -41,6 +47,12 @@ def parse_identified
@stmt.slice!(/\s+IDENTIFIED BY\s+(.+?)\z/)
identified = $1

if @create_user
@create_user.slice!(/\s+IDENTIFIED\s+WITH\s+'[^']+'\s+AS\s+('[^']+')/)
identified = $1
identified = "PASSWORD #{identified}" if identified
end

if identified
@parsed[:identified] = identified.strip
end
@@ -40,7 +40,7 @@
expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' IDENTIFIED BY PASSWORD '*531E182E2F72080AB0740FE2F2D689DBE0146E04' WITH GRANT OPTION",
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' REQUIRE SSL",
]
].normalize
end
end

@@ -67,7 +67,7 @@
expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' WITH GRANT OPTION",
"GRANT USAGE ON *.* TO 'scott'@'localhost' REQUIRE SSL",
]
].normalize
end
end

@@ -94,7 +94,7 @@
expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' WITH GRANT OPTION",
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
]
].normalize
end
end

@@ -121,7 +121,7 @@
expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost' REQUIRE SSL WITH GRANT OPTION",
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE X509",
]
].normalize
end
end

@@ -148,7 +148,7 @@
expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'localhost'",
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL WITH GRANT OPTION MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 MAX_USER_CONNECTIONS 4",
]
].normalize
end
end
end
@@ -76,7 +76,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end

@@ -114,7 +114,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end

@@ -158,7 +158,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end
end
@@ -61,7 +61,7 @@
expect(show_grants).to match_array [
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
]
].normalize
end
end

@@ -96,7 +96,7 @@
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
]
].normalize
end
end

@@ -132,7 +132,7 @@
"GRANT SELECT (user) ON `mysql`.`user` TO 'scott'@'localhost'",
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
]
].normalize
end
end
end
@@ -49,7 +49,7 @@

expect(show_grants).to match_array [
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
]
].normalize
end
end

@@ -64,7 +64,7 @@
"GRANT SELECT, DELETE ON *.* TO 'scott'@'%' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT SELECT, DELETE ON *.* TO 'scott'@'127.0.0.1' REQUIRE SSL",
"GRANT SELECT, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
]
].normalize
end
end

@@ -139,7 +139,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'%'",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
]
].normalize
end
end
end
@@ -80,7 +80,7 @@
"GRANT UPDATE, DELETE ON `gratan_test`.`zoo` TO 'bob'@'localhost'",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end
end
@@ -137,7 +137,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end
end
@@ -76,7 +76,7 @@
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end

@@ -113,7 +113,7 @@
"GRANT SELECT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE (host) ON `mysql`.`user` TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end

@@ -157,7 +157,7 @@
"GRANT UPDATE (host) ON `mysql`.`user` TO 'scott'@'localhost'",
"GRANT UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT USAGE ON *.* TO 'mary'@'localhost'",
]
].normalize
end
end

@@ -203,7 +203,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end
end
@@ -76,7 +76,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end

@@ -126,7 +126,7 @@
"GRANT SELECT, INSERT ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end
end
@@ -76,7 +76,7 @@
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end

@@ -125,7 +125,7 @@
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40' REQUIRE SSL",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'bob'@'localhost'",
]
].normalize
end
end
end
@@ -32,7 +32,7 @@
expect(show_grants).to match_array [
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*6F498C84277BCC2089932690304BD4EDABC74547'",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
]
].normalize
end
end

@@ -111,7 +111,7 @@
expect(show_grants).to match_array [
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*6F498C84277BCC2089932690304BD4EDABC74547'",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
]
].normalize
end
end

@@ -81,7 +81,7 @@
expect(show_grants).to match_array [
"GRANT ALL PRIVILEGES ON *.* TO 'bob'@'%' REQUIRE SSL",
"GRANT SELECT ON `test`.* TO 'bob'@'%'",
]
].normalize
end
end

@@ -30,7 +30,7 @@
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'127.0.0.1'",
"GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'scott'@'192.168.%' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'192.168.%'",
]
].normalize
end
end
end
@@ -33,7 +33,7 @@
"GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'scott'@'localhost'",
"GRANT UPDATE, DELETE ON `gratan_test`.`zoo` TO 'scott'@'localhost'",
"GRANT USAGE ON *.* TO 'scott'@'localhost' IDENTIFIED BY PASSWORD '*F2F68D0BB27A773C1D944270E5FAFED515A3FA40'",
]
].normalize
end
end
end

0 comments on commit aaa1e32

Please sign in to comment.
You can’t perform that action at this time.