add userfile support to cql and cqld3 drivers

This commit is contained in:
Jonathan Shook 2022-01-28 13:01:58 -06:00
parent 639a1173bf
commit 46c19ff41c
2 changed files with 31 additions and 4 deletions

View File

@ -104,11 +104,17 @@ public class CQLSessionCache implements Shutdownable {
builder.withCompression(ProtocolOptions.Compression.NONE); builder.withCompression(ProtocolOptions.Compression.NONE);
Optional<String> usernameOpt = activityDef.getParams().getOptionalString("username"); Optional<String> usernameOpt = activityDef.getParams().getOptionalString("username");
Optional<String> userfileOpt = activityDef.getParams().getOptionalString("userfile");
Optional<String> passwordOpt = activityDef.getParams().getOptionalString("password"); Optional<String> passwordOpt = activityDef.getParams().getOptionalString("password");
Optional<String> passfileOpt = activityDef.getParams().getOptionalString("passfile"); Optional<String> passfileOpt = activityDef.getParams().getOptionalString("passfile");
if (usernameOpt.isPresent()) {
String username = usernameOpt.get(); if (usernameOpt.isPresent() || userfileOpt.isPresent()) {
String username = usernameOpt.orElse(null);
if (userfileOpt.isPresent()) {
username = readfile(userfileOpt.get());
}
String password; String password;
if (passwordOpt.isPresent()) { if (passwordOpt.isPresent()) {
password = passwordOpt.get(); password = passwordOpt.get();
@ -332,6 +338,14 @@ public class CQLSessionCache implements Shutdownable {
return session; return session;
} }
private String readfile(String path) {
try {
return Files.readAllLines(Path.of(path)).get(0);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public void shutdown() { public void shutdown() {
for (Session session : sessionCache.values()) { for (Session session : sessionCache.values()) {

View File

@ -106,11 +106,16 @@ public class CQLSessionCache implements Shutdownable {
builder.withCompression(ProtocolOptions.Compression.NONE); builder.withCompression(ProtocolOptions.Compression.NONE);
Optional<String> usernameOpt = activityDef.getParams().getOptionalString("username"); Optional<String> usernameOpt = activityDef.getParams().getOptionalString("username");
Optional<String> userfileOpt = activityDef.getParams().getOptionalString("userfile");
Optional<String> passwordOpt = activityDef.getParams().getOptionalString("password"); Optional<String> passwordOpt = activityDef.getParams().getOptionalString("password");
Optional<String> passfileOpt = activityDef.getParams().getOptionalString("passfile"); Optional<String> passfileOpt = activityDef.getParams().getOptionalString("passfile");
if (usernameOpt.isPresent()) { if (usernameOpt.isPresent() || userfileOpt.isPresent()) {
String username = usernameOpt.get(); String username = usernameOpt.orElse(null);
if (userfileOpt.isPresent()) {
username = readfile(userfileOpt.get());
}
String password; String password;
if (passwordOpt.isPresent()) { if (passwordOpt.isPresent()) {
password = passwordOpt.get(); password = passwordOpt.get();
@ -326,6 +331,14 @@ public class CQLSessionCache implements Shutdownable {
return session; return session;
} }
private String readfile(String path) {
try {
return Files.readAllLines(Path.of(path)).get(0);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public void shutdown() { public void shutdown() {
for (Session session : sessionCache.values()) { for (Session session : sessionCache.values()) {