From 9e63d3de3fae53b28f7c5a8fc05216e3bae98eb1 Mon Sep 17 00:00:00 2001 From: jruaux Date: Wed, 25 Sep 2024 17:17:09 -0700 Subject: [PATCH] fix: Added missing `--source-client` option --- .../com/redis/riot/AbstractRedisCommand.java | 9 +- .../riot/AbstractRedisExportCommand.java | 9 +- .../riot/AbstractRedisImportCommand.java | 9 +- .../redis/riot/AbstractReplicateCommand.java | 6 +- .../main/java/com/redis/riot/RedisArgs.java | 228 ++++++++++++------ .../java/com/redis/riot/RedisContext.java | 17 ++ .../java/com/redis/riot/SimpleRedisArgs.java | 190 --------------- .../java/com/redis/riot/SourceRedisArgs.java | 48 +++- .../java/com/redis/riot/TargetRedisArgs.java | 41 ++-- .../riot/AbstractRiotApplicationTestBase.java | 2 +- .../test/java/com/redis/riot/FileTests.java | 2 +- .../java/com/redis/riot/RedisArgsTests.java | 2 +- 12 files changed, 249 insertions(+), 314 deletions(-) delete mode 100644 plugins/riot/src/main/java/com/redis/riot/SimpleRedisArgs.java diff --git a/plugins/riot/src/main/java/com/redis/riot/AbstractRedisCommand.java b/plugins/riot/src/main/java/com/redis/riot/AbstractRedisCommand.java index 6c7f1b8a5..6ca88b9f2 100644 --- a/plugins/riot/src/main/java/com/redis/riot/AbstractRedisCommand.java +++ b/plugins/riot/src/main/java/com/redis/riot/AbstractRedisCommand.java @@ -9,13 +9,14 @@ public abstract class AbstractRedisCommand extends AbstractJobCommand { @ArgGroup(exclusive = false) - private SimpleRedisArgs redisArgs = new SimpleRedisArgs(); + private RedisArgs redisArgs = new RedisArgs(); private RedisContext redisContext; @Override protected void execute() throws Exception { - redisContext = redisArgs.redisContext(); + redisContext = RedisContext.create(redisArgs.redisURI(), redisArgs.isCluster(), redisArgs.getProtocolVersion(), + redisArgs.getSslArgs()); try { super.execute(); } finally { @@ -31,11 +32,11 @@ protected void configure(RedisItemWriter writer) { redisContext.configure(writer); } - public SimpleRedisArgs getRedisArgs() { + public RedisArgs getRedisArgs() { return redisArgs; } - public void setRedisArgs(SimpleRedisArgs clientArgs) { + public void setRedisArgs(RedisArgs clientArgs) { this.redisArgs = clientArgs; } diff --git a/plugins/riot/src/main/java/com/redis/riot/AbstractRedisExportCommand.java b/plugins/riot/src/main/java/com/redis/riot/AbstractRedisExportCommand.java index d6c742a26..43d475198 100644 --- a/plugins/riot/src/main/java/com/redis/riot/AbstractRedisExportCommand.java +++ b/plugins/riot/src/main/java/com/redis/riot/AbstractRedisExportCommand.java @@ -18,7 +18,7 @@ public abstract class AbstractRedisExportCommand extends AbstractExportCommand { @ArgGroup(exclusive = false) - private SimpleRedisArgs redisArgs = new SimpleRedisArgs(); + private RedisArgs redisArgs = new RedisArgs(); @Option(names = "--pool", description = "Max number of Redis connections in pool (default: ${DEFAULT-VALUE}).", paramLabel = "") private int poolSize = RedisItemWriter.DEFAULT_POOL_SIZE; @@ -28,7 +28,8 @@ public abstract class AbstractRedisExportCommand extends AbstractExportCommand { @Override protected RedisContext sourceRedisContext() { - return redisArgs.redisContext(); + return RedisContext.create(redisArgs.redisURI(), redisArgs.isCluster(), redisArgs.getProtocolVersion(), + redisArgs.getSslArgs()); } @Override @@ -46,11 +47,11 @@ protected ItemProcessor, Map> mapProces return new FunctionItemProcessor<>(mapFunction); } - public SimpleRedisArgs getRedisArgs() { + public RedisArgs getRedisArgs() { return redisArgs; } - public void setRedisArgs(SimpleRedisArgs clientArgs) { + public void setRedisArgs(RedisArgs clientArgs) { this.redisArgs = clientArgs; } diff --git a/plugins/riot/src/main/java/com/redis/riot/AbstractRedisImportCommand.java b/plugins/riot/src/main/java/com/redis/riot/AbstractRedisImportCommand.java index dc0308419..ce9922742 100644 --- a/plugins/riot/src/main/java/com/redis/riot/AbstractRedisImportCommand.java +++ b/plugins/riot/src/main/java/com/redis/riot/AbstractRedisImportCommand.java @@ -8,7 +8,7 @@ public abstract class AbstractRedisImportCommand extends AbstractImportCommand { @ArgGroup(exclusive = false) - private SimpleRedisArgs redisArgs = new SimpleRedisArgs(); + private RedisArgs redisArgs = new RedisArgs(); @Option(names = "--pool", description = "Max number of Redis connections in pool (default: ${DEFAULT-VALUE}).", paramLabel = "") private int poolSize = RedisItemWriter.DEFAULT_POOL_SIZE; @@ -22,14 +22,15 @@ protected void configureTargetRedisWriter(RedisItemWriter writer) { @Override protected RedisContext targetRedisContext() { - return redisArgs.redisContext(); + return RedisContext.create(redisArgs.redisURI(), redisArgs.isCluster(), redisArgs.getProtocolVersion(), + redisArgs.getSslArgs()); } - public SimpleRedisArgs getRedisArgs() { + public RedisArgs getRedisArgs() { return redisArgs; } - public void setRedisArgs(SimpleRedisArgs clientArgs) { + public void setRedisArgs(RedisArgs clientArgs) { this.redisArgs = clientArgs; } diff --git a/plugins/riot/src/main/java/com/redis/riot/AbstractReplicateCommand.java b/plugins/riot/src/main/java/com/redis/riot/AbstractReplicateCommand.java index 571fe6bf5..39c730438 100644 --- a/plugins/riot/src/main/java/com/redis/riot/AbstractReplicateCommand.java +++ b/plugins/riot/src/main/java/com/redis/riot/AbstractReplicateCommand.java @@ -44,12 +44,14 @@ protected void execute() throws Exception { @Override protected RedisContext sourceRedisContext() { log.info("Creating source Redis context with {} {} {}", sourceRedisUri, sourceRedisArgs, sslArgs); - return sourceRedisArgs.redisContext(sourceRedisUri, sslArgs); + return RedisContext.create(sourceRedisArgs.redisURI(sourceRedisUri), sourceRedisArgs.isCluster(), + sourceRedisArgs.getProtocolVersion(), sslArgs); } private RedisContext targetRedisContext() { log.info("Creating target Redis context with {} {} {}", targetRedisUri, targetRedisArgs, sslArgs); - return targetRedisArgs.redisContext(targetRedisUri, sslArgs); + return RedisContext.create(targetRedisArgs.redisURI(targetRedisUri), targetRedisArgs.isCluster(), + targetRedisArgs.getProtocolVersion(), sslArgs); } @Override diff --git a/plugins/riot/src/main/java/com/redis/riot/RedisArgs.java b/plugins/riot/src/main/java/com/redis/riot/RedisArgs.java index 8bfbb2546..3c53bc7ee 100644 --- a/plugins/riot/src/main/java/com/redis/riot/RedisArgs.java +++ b/plugins/riot/src/main/java/com/redis/riot/RedisArgs.java @@ -2,131 +2,199 @@ import java.time.Duration; -import com.redis.lettucemod.RedisModulesClientBuilder; import com.redis.lettucemod.RedisURIBuilder; +import com.redis.riot.core.RiotUtils; import com.redis.riot.core.RiotVersion; -import io.lettuce.core.ClientOptions; -import io.lettuce.core.ClientOptions.Builder; import io.lettuce.core.RedisURI; import io.lettuce.core.SslVerifyMode; -import io.lettuce.core.cluster.ClusterClientOptions; import io.lettuce.core.protocol.ProtocolVersion; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Option; -public interface RedisArgs { +public class RedisArgs { - boolean DEFAULT_CLUSTER = false; - String DEFAULT_HOST = RedisURIBuilder.DEFAULT_HOST; - int DEFAULT_PORT = RedisURIBuilder.DEFAULT_PORT; - long DEFAULT_TIMEOUT = RedisURIBuilder.DEFAULT_TIMEOUT; - String DEFAULT_CLIENT_NAME = RiotVersion.riotVersion(); - ProtocolVersion DEFAULT_PROTOCOL_VERSION = ProtocolVersion.RESP2; - int DEFAULT_DATABASE = 0; - boolean DEFAULT_INSECURE = false; - boolean DEFAULT_TLS = false; + @Option(names = { "-u", "--uri" }, description = "Server URI.", paramLabel = "") + private RedisURI uri; - default RedisURI getUri() { - return null; + @Option(names = { "-h", + "--host" }, description = "Server hostname (default: ${DEFAULT-VALUE}).", paramLabel = "") + private String host = RedisURIBuilder.DEFAULT_HOST; + + @Option(names = { "-p", "--port" }, description = "Server port (default: ${DEFAULT-VALUE}).", paramLabel = "") + private int port = RedisURIBuilder.DEFAULT_PORT; + + @Option(names = { "-s", + "--socket" }, description = "Server socket (overrides hostname and port).", paramLabel = "") + private String socket; + + @Option(names = "--user", description = "ACL style 'AUTH username pass'. Needs password.", paramLabel = "") + private String username; + + @Option(names = { "-a", + "--pass" }, arity = "0..1", interactive = true, description = "Password to use when connecting to the server.", paramLabel = "") + private char[] password; + + @Option(names = "--timeout", description = "Redis command timeout in seconds (default: ${DEFAULT-VALUE}).", paramLabel = "") + private long timeout = RedisURIBuilder.DEFAULT_TIMEOUT; + + @Option(names = { "-n", "--db" }, description = "Database number.", paramLabel = "") + private int database; + + @Option(names = "--tls", description = "Establish a secure TLS connection.") + private boolean tls; + + @Option(names = "--insecure", description = "Allow insecure TLS connection by skipping cert validation.") + private boolean insecure; + + @Option(names = "--client", description = "Client name used to connect to Redis (default: ${DEFAULT-VALUE}).", paramLabel = "") + private String clientName = RiotVersion.riotVersion(); + + @Option(names = { "-c", "--cluster" }, description = "Enable cluster mode.") + private boolean cluster; + + @Option(names = "--resp", description = "Redis protocol version used to connect to Redis: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE}).", paramLabel = "") + private ProtocolVersion protocolVersion = ProtocolVersion.RESP2; + + @ArgGroup(exclusive = false, heading = "TLS options%n") + private SslArgs sslArgs = new SslArgs(); + + public RedisURI redisURI() { + RedisURIBuilder builder = new RedisURIBuilder(); + builder.clientName(clientName); + builder.database(database); + builder.host(host); + builder.password(password); + builder.port(port); + builder.socket(socket); + builder.timeout(Duration.ofSeconds(timeout)); + builder.tls(tls); + builder.uri(uri); + builder.username(username); + if (insecure) { + builder.verifyMode(SslVerifyMode.NONE); + } + return builder.build(); } - default boolean isCluster() { - return DEFAULT_CLUSTER; + public boolean isCluster() { + return cluster; } - default ProtocolVersion getProtocolVersion() { - return DEFAULT_PROTOCOL_VERSION; + public void setCluster(boolean cluster) { + this.cluster = cluster; } - default SslArgs getSslArgs() { - return null; + public ProtocolVersion getProtocolVersion() { + return protocolVersion; } - default String getHost() { - return DEFAULT_HOST; + public void setProtocolVersion(ProtocolVersion version) { + this.protocolVersion = version; } - default int getPort() { - return DEFAULT_PORT; + public SslArgs getSslArgs() { + return sslArgs; } - default String getSocket() { - return null; + public void setSslArgs(SslArgs sslArgs) { + this.sslArgs = sslArgs; } - default String getUsername() { - return null; + public RedisURI getUri() { + return uri; } - default char[] getPassword() { - return null; + public void setUri(RedisURI uri) { + this.uri = uri; } - /** - * - * @return timeout duration in seconds - */ - default long getTimeout() { - return DEFAULT_TIMEOUT; + public String getHost() { + return host; } - default int getDatabase() { - return DEFAULT_DATABASE; + public void setHost(String host) { + this.host = host; } - default boolean isTls() { - return DEFAULT_TLS; + public int getPort() { + return port; } - default boolean isInsecure() { - return DEFAULT_INSECURE; + public void setPort(int port) { + this.port = port; } - default String getClientName() { - return DEFAULT_CLIENT_NAME; + public String getSocket() { + return socket; } - default RedisURI redisURI() { - return redisURI(getUri()); + public void setSocket(String socket) { + this.socket = socket; } - default RedisURI redisURI(RedisURI uri) { - RedisURIBuilder builder = new RedisURIBuilder(); - builder.clientName(getClientName()); - builder.database(getDatabase()); - builder.host(getHost()); - builder.password(getPassword()); - builder.port(getPort()); - builder.socket(getSocket()); - builder.timeout(Duration.ofSeconds(getTimeout())); - builder.tls(isTls()); - builder.uri(uri); - builder.username(getUsername()); - if (isInsecure()) { - builder.verifyMode(SslVerifyMode.NONE); - } - return builder.build(); + public String getUsername() { + return username; } - default RedisContext redisContext() { - return redisContext(getUri()); + public void setUsername(String username) { + this.username = username; } - default RedisContext redisContext(RedisURI uri) { - return redisContext(uri, getSslArgs()); + public char[] getPassword() { + return password; } - default RedisContext redisContext(RedisURI uri, SslArgs sslArgs) { - RedisURI finalUri = redisURI(uri); - RedisModulesClientBuilder clientBuilder = new RedisModulesClientBuilder(); - clientBuilder.cluster(isCluster()); - Builder options = isCluster() ? ClusterClientOptions.builder() : ClientOptions.builder(); - options.protocolVersion(getProtocolVersion()); - if (sslArgs != null) { - options.sslOptions(sslArgs.sslOptions()); - } - clientBuilder.clientOptions(options.build()); - clientBuilder.uri(finalUri); - return new RedisContext(finalUri, clientBuilder.build()); + public void setPassword(char[] password) { + this.password = password; + } + + public long getTimeout() { + return timeout; + } + + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + public int getDatabase() { + return database; + } + + public void setDatabase(int database) { + this.database = database; + } + + public boolean isTls() { + return tls; + } + + public void setTls(boolean tls) { + this.tls = tls; + } + + public boolean isInsecure() { + return insecure; + } + + public void setInsecure(boolean insecure) { + this.insecure = insecure; + } + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + @Override + public String toString() { + return "SimpleRedisArgs [uri=" + uri + ", host=" + host + ", port=" + port + ", socket=" + socket + + ", username=" + username + ", password=" + RiotUtils.mask(password) + ", timeout=" + timeout + + ", database=" + database + ", tls=" + tls + ", insecure=" + insecure + ", clientName=" + clientName + + ", cluster=" + cluster + ", protocolVersion=" + protocolVersion + ", sslArgs=" + sslArgs + "]"; } } diff --git a/plugins/riot/src/main/java/com/redis/riot/RedisContext.java b/plugins/riot/src/main/java/com/redis/riot/RedisContext.java index bfb6104a3..93eaaeb33 100644 --- a/plugins/riot/src/main/java/com/redis/riot/RedisContext.java +++ b/plugins/riot/src/main/java/com/redis/riot/RedisContext.java @@ -1,12 +1,16 @@ package com.redis.riot; +import com.redis.lettucemod.RedisModulesClientBuilder; import com.redis.lettucemod.RedisModulesUtils; import com.redis.lettucemod.api.StatefulRedisModulesConnection; import com.redis.spring.batch.item.redis.RedisItemReader; import com.redis.spring.batch.item.redis.RedisItemWriter; import io.lettuce.core.AbstractRedisClient; +import io.lettuce.core.ClientOptions; import io.lettuce.core.RedisURI; +import io.lettuce.core.cluster.ClusterClientOptions; +import io.lettuce.core.protocol.ProtocolVersion; public class RedisContext implements AutoCloseable { @@ -52,4 +56,17 @@ public void close() { } } + public static RedisContext create(RedisURI uri, boolean cluster, ProtocolVersion protocolVersion, SslArgs sslArgs) { + RedisModulesClientBuilder clientBuilder = new RedisModulesClientBuilder(); + clientBuilder.cluster(cluster); + ClientOptions.Builder options = cluster ? ClusterClientOptions.builder() : ClientOptions.builder(); + options.protocolVersion(protocolVersion); + if (sslArgs != null) { + options.sslOptions(sslArgs.sslOptions()); + } + clientBuilder.clientOptions(options.build()); + clientBuilder.uri(uri); + return new RedisContext(uri, clientBuilder.build()); + } + } diff --git a/plugins/riot/src/main/java/com/redis/riot/SimpleRedisArgs.java b/plugins/riot/src/main/java/com/redis/riot/SimpleRedisArgs.java deleted file mode 100644 index b1afd567a..000000000 --- a/plugins/riot/src/main/java/com/redis/riot/SimpleRedisArgs.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.redis.riot; - -import com.redis.riot.core.RiotUtils; - -import io.lettuce.core.RedisURI; -import io.lettuce.core.protocol.ProtocolVersion; -import picocli.CommandLine.ArgGroup; -import picocli.CommandLine.Option; - -public class SimpleRedisArgs implements RedisArgs { - - @Option(names = { "-u", "--uri" }, description = "Server URI.", paramLabel = "") - private RedisURI uri; - - @Option(names = { "-h", - "--host" }, description = "Server hostname (default: ${DEFAULT-VALUE}).", paramLabel = "") - private String host = DEFAULT_HOST; - - @Option(names = { "-p", "--port" }, description = "Server port (default: ${DEFAULT-VALUE}).", paramLabel = "") - private int port = DEFAULT_PORT; - - @Option(names = { "-s", - "--socket" }, description = "Server socket (overrides hostname and port).", paramLabel = "") - private String socket; - - @Option(names = "--user", description = "ACL style 'AUTH username pass'. Needs password.", paramLabel = "") - private String username; - - @Option(names = { "-a", - "--pass" }, arity = "0..1", interactive = true, description = "Password to use when connecting to the server.", paramLabel = "") - private char[] password; - - @Option(names = "--timeout", description = "Redis command timeout in seconds (default: ${DEFAULT-VALUE}).", paramLabel = "") - private long timeout = DEFAULT_TIMEOUT; - - @Option(names = { "-n", "--db" }, description = "Database number.", paramLabel = "") - private int database; - - @Option(names = "--tls", description = "Establish a secure TLS connection.") - private boolean tls; - - @Option(names = "--insecure", description = "Allow insecure TLS connection by skipping cert validation.") - private boolean insecure; - - @Option(names = "--client", description = "Client name used to connect to Redis (default: ${DEFAULT-VALUE}).", paramLabel = "") - private String clientName = DEFAULT_CLIENT_NAME; - - @Option(names = { "-c", "--cluster" }, description = "Enable cluster mode.") - private boolean cluster; - - @Option(names = "--resp", description = "Redis protocol version used to connect to Redis: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE}).", paramLabel = "") - private ProtocolVersion protocolVersion = DEFAULT_PROTOCOL_VERSION; - - @ArgGroup(exclusive = false, heading = "TLS options%n") - private SslArgs sslArgs = new SslArgs(); - - @Override - public boolean isCluster() { - return cluster; - } - - public void setCluster(boolean cluster) { - this.cluster = cluster; - } - - @Override - public ProtocolVersion getProtocolVersion() { - return protocolVersion; - } - - public void setProtocolVersion(ProtocolVersion version) { - this.protocolVersion = version; - } - - @Override - public SslArgs getSslArgs() { - return sslArgs; - } - - public void setSslArgs(SslArgs sslArgs) { - this.sslArgs = sslArgs; - } - - public RedisURI getUri() { - return uri; - } - - public void setUri(RedisURI uri) { - this.uri = uri; - } - - @Override - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - @Override - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - @Override - public String getSocket() { - return socket; - } - - public void setSocket(String socket) { - this.socket = socket; - } - - @Override - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - @Override - public char[] getPassword() { - return password; - } - - public void setPassword(char[] password) { - this.password = password; - } - - @Override - public long getTimeout() { - return timeout; - } - - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - @Override - public int getDatabase() { - return database; - } - - public void setDatabase(int database) { - this.database = database; - } - - @Override - public boolean isTls() { - return tls; - } - - public void setTls(boolean tls) { - this.tls = tls; - } - - @Override - public boolean isInsecure() { - return insecure; - } - - public void setInsecure(boolean insecure) { - this.insecure = insecure; - } - - @Override - public String getClientName() { - return clientName; - } - - public void setClientName(String clientName) { - this.clientName = clientName; - } - - @Override - public String toString() { - return "SimpleRedisArgs [uri=" + uri + ", host=" + host + ", port=" + port + ", socket=" + socket - + ", username=" + username + ", password=" + RiotUtils.mask(password) + ", timeout=" + timeout - + ", database=" + database + ", tls=" + tls + ", insecure=" + insecure + ", clientName=" + clientName - + ", cluster=" + cluster + ", protocolVersion=" + protocolVersion + ", sslArgs=" + sslArgs + "]"; - } - -} diff --git a/plugins/riot/src/main/java/com/redis/riot/SourceRedisArgs.java b/plugins/riot/src/main/java/com/redis/riot/SourceRedisArgs.java index b61191473..e95b0fb07 100644 --- a/plugins/riot/src/main/java/com/redis/riot/SourceRedisArgs.java +++ b/plugins/riot/src/main/java/com/redis/riot/SourceRedisArgs.java @@ -1,12 +1,18 @@ package com.redis.riot; +import java.time.Duration; + +import com.redis.lettucemod.RedisURIBuilder; import com.redis.riot.core.RiotUtils; +import com.redis.riot.core.RiotVersion; import com.redis.spring.batch.item.redis.RedisItemReader; +import io.lettuce.core.RedisURI; +import io.lettuce.core.SslVerifyMode; import io.lettuce.core.protocol.ProtocolVersion; import picocli.CommandLine.Option; -public class SourceRedisArgs implements RedisArgs { +public class SourceRedisArgs { @Option(names = "--source-user", description = "Source ACL style 'AUTH username pass'. Needs password.", paramLabel = "") private String username; @@ -15,7 +21,7 @@ public class SourceRedisArgs implements RedisArgs { private char[] password; @Option(names = "--source-timeout", description = "Source Redis command timeout in seconds (default: ${DEFAULT-VALUE}).", paramLabel = "") - private long timeout = DEFAULT_TIMEOUT; + private long timeout = RedisURIBuilder.DEFAULT_TIMEOUT; @Option(names = "--source-tls", description = "Establish a secure TLS connection to source.") private boolean tls; @@ -23,16 +29,32 @@ public class SourceRedisArgs implements RedisArgs { @Option(names = "--source-insecure", description = "Allow insecure TLS connection to source by skipping cert validation.") private boolean insecure; + @Option(names = "--source-client", description = "Client name used to connect to source Redis (default: ${DEFAULT-VALUE}).", paramLabel = "") + private String clientName = RiotVersion.riotVersion(); + @Option(names = "--source-cluster", description = "Enable source cluster mode.") private boolean cluster; @Option(names = "--source-resp", description = "Redis protocol version used to connect to source: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE}).", paramLabel = "") - private ProtocolVersion protocolVersion = DEFAULT_PROTOCOL_VERSION; + private ProtocolVersion protocolVersion = ProtocolVersion.RESP2; @Option(names = "--source-pool", description = "Max pool connections used for source Redis (default: ${DEFAULT-VALUE}).", paramLabel = "") private int poolSize = RedisItemReader.DEFAULT_POOL_SIZE; - @Override + public RedisURI redisURI(RedisURI uri) { + RedisURIBuilder builder = new RedisURIBuilder(); + builder.uri(uri); + builder.clientName(clientName); + builder.password(password); + builder.timeout(Duration.ofSeconds(timeout)); + builder.tls(tls); + builder.username(username); + if (insecure) { + builder.verifyMode(SslVerifyMode.NONE); + } + return builder.build(); + } + public String getUsername() { return username; } @@ -41,7 +63,6 @@ public void setUsername(String username) { this.username = username; } - @Override public char[] getPassword() { return password; } @@ -50,7 +71,6 @@ public void setPassword(char[] password) { this.password = password; } - @Override public boolean isInsecure() { return insecure; } @@ -59,7 +79,6 @@ public void setInsecure(boolean insecure) { this.insecure = insecure; } - @Override public boolean isCluster() { return cluster; } @@ -68,7 +87,6 @@ public void setCluster(boolean cluster) { this.cluster = cluster; } - @Override public ProtocolVersion getProtocolVersion() { return protocolVersion; } @@ -85,7 +103,6 @@ public void setPoolSize(int poolSize) { this.poolSize = poolSize; } - @Override public long getTimeout() { return timeout; } @@ -94,7 +111,6 @@ public void setTimeout(long timeout) { this.timeout = timeout; } - @Override public boolean isTls() { return tls; } @@ -103,11 +119,19 @@ public void setTls(boolean tls) { this.tls = tls; } + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + @Override public String toString() { return "SourceRedisArgs [username=" + username + ", password=" + RiotUtils.mask(password) + ", timeout=" - + timeout + ", tls=" + tls + ", insecure=" + insecure + ", cluster=" + cluster + ", protocolVersion=" - + protocolVersion + ", poolSize=" + poolSize + "]"; + + timeout + ", tls=" + tls + ", insecure=" + insecure + ", clientName=" + clientName + ", cluster=" + + cluster + ", protocolVersion=" + protocolVersion + ", poolSize=" + poolSize + "]"; } } diff --git a/plugins/riot/src/main/java/com/redis/riot/TargetRedisArgs.java b/plugins/riot/src/main/java/com/redis/riot/TargetRedisArgs.java index e0d7fff46..0516285ed 100644 --- a/plugins/riot/src/main/java/com/redis/riot/TargetRedisArgs.java +++ b/plugins/riot/src/main/java/com/redis/riot/TargetRedisArgs.java @@ -1,13 +1,18 @@ package com.redis.riot; -import java.util.Arrays; +import java.time.Duration; +import com.redis.lettucemod.RedisURIBuilder; +import com.redis.riot.core.RiotUtils; +import com.redis.riot.core.RiotVersion; import com.redis.spring.batch.item.redis.RedisItemWriter; +import io.lettuce.core.RedisURI; +import io.lettuce.core.SslVerifyMode; import io.lettuce.core.protocol.ProtocolVersion; import picocli.CommandLine.Option; -public class TargetRedisArgs implements RedisArgs { +public class TargetRedisArgs { @Option(names = "--target-user", description = "Target ACL style 'AUTH username pass'. Needs password.", paramLabel = "") private String username; @@ -16,7 +21,7 @@ public class TargetRedisArgs implements RedisArgs { private char[] password; @Option(names = "--target-timeout", description = "Target Redis command timeout in seconds (default: ${DEFAULT-VALUE}).", paramLabel = "") - private long timeout = DEFAULT_TIMEOUT; + private long timeout = RedisURIBuilder.DEFAULT_TIMEOUT; @Option(names = "--target-tls", description = "Establish a secure TLS connection to target.") private boolean tls; @@ -24,19 +29,32 @@ public class TargetRedisArgs implements RedisArgs { @Option(names = "--target-insecure", description = "Allow insecure TLS connection to target by skipping cert validation.") private boolean insecure; - @Option(names = "--target-client", description = "Client name used to connect to Redis (default: ${DEFAULT-VALUE}).", paramLabel = "") - private String clientName = DEFAULT_CLIENT_NAME; + @Option(names = "--target-client", description = "Client name used to connect to target Redis (default: ${DEFAULT-VALUE}).", paramLabel = "") + private String clientName = RiotVersion.riotVersion(); @Option(names = "--target-cluster", description = "Enable target cluster mode.") private boolean cluster; @Option(names = "--target-resp", description = "Redis protocol version used to connect to target: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE}).", paramLabel = "") - private ProtocolVersion protocolVersion = DEFAULT_PROTOCOL_VERSION; + private ProtocolVersion protocolVersion = ProtocolVersion.RESP2; @Option(names = "--target-pool", description = "Max pool connections used for target Redis (default: ${DEFAULT-VALUE}).", paramLabel = "") private int poolSize = RedisItemWriter.DEFAULT_POOL_SIZE; - @Override + public RedisURI redisURI(RedisURI uri) { + RedisURIBuilder builder = new RedisURIBuilder(); + builder.uri(uri); + builder.clientName(clientName); + builder.password(password); + builder.timeout(Duration.ofSeconds(timeout)); + builder.tls(tls); + builder.username(username); + if (insecure) { + builder.verifyMode(SslVerifyMode.NONE); + } + return builder.build(); + } + public String getUsername() { return username; } @@ -45,7 +63,6 @@ public void setUsername(String username) { this.username = username; } - @Override public char[] getPassword() { return password; } @@ -54,7 +71,6 @@ public void setPassword(char[] password) { this.password = password; } - @Override public boolean isInsecure() { return insecure; } @@ -63,7 +79,6 @@ public void setInsecure(boolean insecure) { this.insecure = insecure; } - @Override public boolean isCluster() { return cluster; } @@ -72,7 +87,6 @@ public void setCluster(boolean cluster) { this.cluster = cluster; } - @Override public ProtocolVersion getProtocolVersion() { return protocolVersion; } @@ -89,7 +103,6 @@ public void setPoolSize(int poolSize) { this.poolSize = poolSize; } - @Override public long getTimeout() { return timeout; } @@ -98,7 +111,6 @@ public void setTimeout(long timeout) { this.timeout = timeout; } - @Override public boolean isTls() { return tls; } @@ -107,7 +119,6 @@ public void setTls(boolean tls) { this.tls = tls; } - @Override public String getClientName() { return clientName; } @@ -118,7 +129,7 @@ public void setClientName(String clientName) { @Override public String toString() { - return "TargetRedisArgs [username=" + username + ", password=" + Arrays.toString(password) + ", timeout=" + return "TargetRedisArgs [username=" + username + ", password=" + RiotUtils.mask(password) + ", timeout=" + timeout + ", tls=" + tls + ", insecure=" + insecure + ", clientName=" + clientName + ", cluster=" + cluster + ", protocolVersion=" + protocolVersion + ", poolSize=" + poolSize + "]"; } diff --git a/plugins/riot/src/test/java/com/redis/riot/AbstractRiotApplicationTestBase.java b/plugins/riot/src/test/java/com/redis/riot/AbstractRiotApplicationTestBase.java index a030a676a..cc1230335 100644 --- a/plugins/riot/src/test/java/com/redis/riot/AbstractRiotApplicationTestBase.java +++ b/plugins/riot/src/test/java/com/redis/riot/AbstractRiotApplicationTestBase.java @@ -41,7 +41,7 @@ public TestRiot(TestInfo info, IExecutionStrategy... configs) { this.configs = configs; } - private void configure(SimpleRedisArgs redisArgs) { + private void configure(RedisArgs redisArgs) { redisArgs.setUri(redisURI); redisArgs.setCluster(getRedisServer().isRedisCluster()); } diff --git a/plugins/riot/src/test/java/com/redis/riot/FileTests.java b/plugins/riot/src/test/java/com/redis/riot/FileTests.java index eb9b4b62f..9d051f568 100644 --- a/plugins/riot/src/test/java/com/redis/riot/FileTests.java +++ b/plugins/riot/src/test/java/com/redis/riot/FileTests.java @@ -92,7 +92,7 @@ private void configureJobCommand(TestInfo info, AbstractJobCommand callable) { callable.getJobArgs().getProgressArgs().setStyle(ProgressStyle.NONE); } - private void configure(SimpleRedisArgs redisArgs) { + private void configure(RedisArgs redisArgs) { redisArgs.setUri(RedisURI.create(getRedisServer().getRedisURI())); redisArgs.setCluster(getRedisServer().isRedisCluster()); } diff --git a/plugins/riot/src/test/java/com/redis/riot/RedisArgsTests.java b/plugins/riot/src/test/java/com/redis/riot/RedisArgsTests.java index 962cd29c9..6970a899b 100644 --- a/plugins/riot/src/test/java/com/redis/riot/RedisArgsTests.java +++ b/plugins/riot/src/test/java/com/redis/riot/RedisArgsTests.java @@ -11,7 +11,7 @@ class RedisArgsTests { @Test void simpleRedisArgsURI() { - SimpleRedisArgs args = new SimpleRedisArgs(); + RedisArgs args = new RedisArgs(); RedisURI baseUri = RedisURI.create("redis://localhost"); args.setUri(baseUri); args.setClientName("ansdf");