Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Added an option to grant privileges to the created user with grant op… #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ protected EmbeddedMysql(
try {
executable.start();
getClient(SCHEMA, mysqldConfig.getCharset()).executeCommands(
format("CREATE USER '%s'@'%%' IDENTIFIED BY '%s';", mysqldConfig.getUsername(), mysqldConfig.getPassword()));
format("CREATE USER '%s'@'%%' IDENTIFIED BY '%s';", mysqldConfig.getUsername(), mysqldConfig.getPassword())
);
if (mysqldConfig.isGrantOption()) {
getClient(SCHEMA, mysqldConfig.getCharset()).executeCommands(
format("GRANT ALL PRIVILEGES ON *.* TO '%s'@'%%' WITH GRANT OPTION", mysqldConfig.getUsername()));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public String getPassword() {
return user.password;
}

public boolean isGrantOption() {
return user.grant;
}

public TimeZone getTimeZone() {
return timeZone;
}
Expand Down Expand Up @@ -148,6 +152,11 @@ public Builder withUser(String username, String password) {
return this;
}

public Builder withUser(String username, String password, boolean grant) {
this.user = new User(username, password, grant);
return this;
}

public Builder withTimeZone(TimeZone timeZone) {
this.timeZone = timeZone;
return this;
Expand Down Expand Up @@ -201,10 +210,18 @@ public MysqldConfig build() {
private static class User {
private final String name;
private final String password;
private final boolean grant;

User(String name, String password) {
this.name = name;
this.password = password;
this.grant = false;
}

User(String name, String password, boolean grant) {
this.name = name;
this.password = password;
this.grant = grant;
}

@Override
Expand Down