Skip to content

Commit

Permalink
Add cassandra authentication credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinUS2 authored and dain committed Jun 27, 2014
1 parent c66fc6d commit 4cb98f3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions presto-cassandra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ cassandra.split-size=1024
# (advanced)
cassandra.thrift-port=9160
# Authentication with Cassandra
# These will be used for all connections
# (optional)
#cassandra.username=my_username
#cassandra.password=my_password
```

## Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class CassandraClientConfig
private String thriftConnectionFactoryClassName = "org.apache.cassandra.thrift.TFramedTransportFactory";
private Map<String, String> transportFactoryOptions = new HashMap<>();
private boolean allowDropTable;
private String username;
private String password;

@Min(0)
public int getLimitForPartitionKeySelect()
Expand Down Expand Up @@ -264,4 +266,28 @@ public CassandraClientConfig setAllowDropTable(boolean allowDropTable)
this.allowDropTable = allowDropTable;
return this;
}

public String getUsername()
{
return username;
}

@Config("cassandra.username")
public CassandraClientConfig setUsername(String username)
{
this.username = username;
return this;
}

public String getPassword()
{
return password;
}

@Config("cassandra.password")
public CassandraClientConfig setPassword(String password)
{
this.password = password;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public static CassandraSession createCassandraSession(
clusterBuilder.withPort(config.getNativeProtocolPort());
clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));

if (config.getUsername() != null && config.getPassword() != null) {
clusterBuilder.withCredentials(config.getUsername(), config.getPassword());
}

QueryOptions options = new QueryOptions();
options.setFetchSize(config.getFetchSize());
options.setConsistencyLevel(config.getConsistencyLevel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public void testDefaults()
.setThriftPort(9160)
.setTransportFactoryOptions("")
.setThriftConnectionFactoryClassName("org.apache.cassandra.thrift.TFramedTransportFactory")
.setAllowDropTable(false));
.setAllowDropTable(false)
.setUsername(null)
.setPassword(null));
}

@Test
Expand All @@ -66,6 +68,8 @@ public void testExplicitPropertyMappings()
.put("cassandra.transport-factory-options", "a=b")
.put("cassandra.thrift-connection-factory-class", "org.apache.cassandra.thrift.TFramedTransportFactory1")
.put("cassandra.allow-drop-table", "true")
.put("cassandra.username", "my_username")
.put("cassandra.password", "my_password")
.build();

CassandraClientConfig expected = new CassandraClientConfig()
Expand All @@ -84,7 +88,9 @@ public void testExplicitPropertyMappings()
.setPartitioner("RandomPartitioner")
.setTransportFactoryOptions("a=b")
.setThriftConnectionFactoryClassName("org.apache.cassandra.thrift.TFramedTransportFactory1")
.setAllowDropTable(true);
.setAllowDropTable(true)
.setUsername("my_username")
.setPassword("my_password");

ConfigAssertions.assertFullMapping(properties, expected);
}
Expand Down

0 comments on commit 4cb98f3

Please sign in to comment.