Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ACL SAVE/LOAD commands #2418

Merged
merged 5 commits into from
Mar 11, 2021
Merged
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
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,14 @@ public void aclDelUser(final byte[] name) {
sendCommand(ACL, Keyword.DELUSER.getRaw(), name);
}

public void aclLoad() {
sendCommand(ACL, Keyword.LOAD.getRaw());
}

public void aclSave() {
sendCommand(ACL, Keyword.SAVE.getRaw());
}

private List<byte[]> convertGeoCoordinateMapToByteArrays(
final Map<byte[], GeoCoordinate> memberCoordinateMap) {
List<byte[]> args = new ArrayList<>(memberCoordinateMap.size() * 3);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3947,6 +3947,20 @@ public byte[] aclLog(byte[] options) {
return client.getBinaryBulkReply();
}

@Override
public String aclLoad() {
checkIsInMultiOrPipeline();
client.aclLoad();
return client.getStatusCodeReply();
}

@Override
public String aclSave() {
checkIsInMultiOrPipeline();
client.aclSave();
return client.getStatusCodeReply();
}

@Override
public String clientKill(final byte[] ipPort) {
checkIsInMultiOrPipeline();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3908,6 +3908,20 @@ public String aclGenPass() {
return client.getStatusCodeReply();
}

@Override
public String aclLoad() {
checkIsInMultiOrPipeline();
client.aclLoad();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
return client.getStatusCodeReply();
}

@Override
public String aclSave() {
checkIsInMultiOrPipeline();
client.aclSave();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
return client.getStatusCodeReply();
}

@Override
public List<Long> bitfield(final String key, final String... arguments) {
checkIsInMultiOrPipeline();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static enum Keyword {
GETNAME, SETNAME, LIST, MATCH, COUNT, PING, PONG, UNLOAD, REPLACE, KEYS, PAUSE, DOCTOR, BLOCK,
NOACK, STREAMS, KEY, CREATE, MKSTREAM, SETID, DESTROY, DELCONSUMER, MAXLEN, GROUP, ID, IDLE,
TIME, RETRYCOUNT, FORCE, USAGE, SAMPLES, STREAM, GROUPS, CONSUMERS, HELP, FREQ, SETUSER,
GETUSER, DELUSER, WHOAMI, CAT, GENPASS, USERS, LOG, INCR;
GETUSER, DELUSER, WHOAMI, CAT, GENPASS, USERS, LOG, INCR, SAVE;

/**
* @deprecated This will be private in future. Use {@link #getRaw()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,7 @@ String migrate(String host, int port, int destinationDB, int timeout, MigratePar

byte[] aclLog(byte[] options);

// TODO: Implements ACL LOAD/SAVE commands
String aclLoad();

String aclSave();
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ String migrate(String host, int port, int destinationDB, int timeout, MigratePar

String aclLog(String options);

// TODO: Implements ACL LOAD/SAVE commands
String aclLoad();

String aclSave();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.exceptions.JedisAccessControlException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.tests.utils.RedisVersionUtil;
import redis.clients.jedis.util.SafeEncoder;

Expand Down Expand Up @@ -458,4 +459,27 @@ public void aclBinaryCommandsTest() {
jedis.aclDelUser(USER_ZZZ.getBytes());
}

@Test
public void aclLoadTest() {
try {
jedis.aclLoad();
fail("Should throw a JedisDataException: ERR This Redis instance is not configured to use an ACL file...");
} catch (JedisDataException e) {
assertTrue(e.getMessage().contains("ERR This Redis instance is not configured to use an ACL file."));
}

// TODO test with ACL file
}

@Test
public void aclSaveTest() {
try {
jedis.aclSave();
fail("Should throw a JedisDataException: ERR This Redis instance is not configured to use an ACL file...");
} catch (JedisDataException e) {
assertTrue(e.getMessage().contains("ERR This Redis instance is not configured to use an ACL file."));
}

// TODO test with ACL file
}
}