Skip to content

Commit

Permalink
Add support for ACL SAVE/LOAD commands (#2418)
Browse files Browse the repository at this point in the history
* Add support for ACL SAVE/LOAD commands

* review

* Apply suggestions from code review

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
  • Loading branch information
dengliming and sazzad16 authored Mar 11, 2021
1 parent c60fd53 commit 50e03eb
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
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();
return client.getStatusCodeReply();
}

@Override
public String aclSave() {
checkIsInMultiOrPipeline();
client.aclSave();
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
}
}

0 comments on commit 50e03eb

Please sign in to comment.