Skip to content

Commit

Permalink
Merge pull request #132 from alexeiakimov/111-expose-astra-authentica…
Browse files Browse the repository at this point in the history
…tion

111 expose astra authentication
  • Loading branch information
kw217 committed Mar 10, 2022
2 parents f48322b + 4a2b3bc commit f8920d2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Expand Up @@ -41,13 +41,13 @@ jobs:
profile: minimal
toolchain: stable
- run: sudo apt install libcurl4-openssl-dev libelf-dev libdw-dev
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.10.0/cassandra-cpp-driver-dbg_2.10.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.10.0/cassandra-cpp-driver-dev_2.10.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.10.0/cassandra-cpp-driver_2.10.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.16.0/cassandra-cpp-driver-dbg_2.16.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.16.0/cassandra-cpp-driver-dev_2.16.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/cassandra/v2.16.0/cassandra-cpp-driver_2.16.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/dependencies/libuv/v1.23.0/libuv1-dbg_1.23.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/dependencies/libuv/v1.23.0/libuv1-dev_1.23.0-1_amd64.deb
- run: wget http://downloads.datastax.com/cpp-driver/ubuntu/18.04/dependencies/libuv/v1.23.0/libuv1_1.23.0-1_amd64.deb
- run: sudo dpkg -i libuv1-dbg_1.23.0-1_amd64.deb libuv1-dev_1.23.0-1_amd64.deb libuv1_1.23.0-1_amd64.deb cassandra-cpp-driver_2.10.0-1_amd64.deb cassandra-cpp-driver-dbg_2.10.0-1_amd64.deb cassandra-cpp-driver-dev_2.10.0-1_amd64.deb
- run: sudo dpkg -i libuv1-dbg_1.23.0-1_amd64.deb libuv1-dev_1.23.0-1_amd64.deb libuv1_1.23.0-1_amd64.deb cassandra-cpp-driver_2.16.0-1_amd64.deb cassandra-cpp-driver-dbg_2.16.0-1_amd64.deb cassandra-cpp-driver-dev_2.16.0-1_amd64.deb

# We now build all the code, then test it.
#
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,12 @@ version number is tracked in the file `VERSION`.
## [Unreleased]
### Changed
### Added
- Added new set_cloud_secure_connection_bundle and set_cloud_secure_connection_bundle_no_ssl_lib_init
functions using the functions Datastax defined in
cassandra-cpp-driver version 2.16.0.
- Added new error codes LIB_NO_TRACING_ID and SSL_CLOSED
using the codes Datastax defined in
cassandra-cpp-driver version 2.16.0.
### Fixed

## [0.17.2] - 2022-03-09
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -14,7 +14,7 @@ edition = "2018"

[dependencies]
slog = "2"
cassandra-cpp-sys = "0.12"
cassandra-cpp-sys = "1.0.0"
uuid = "0.8"
error-chain = "0.12"
parking_lot = "0.12"
Expand Down
30 changes: 30 additions & 0 deletions examples/cloud.rs
@@ -0,0 +1,30 @@
use cassandra_cpp::*;
use std::env;

fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 4 {
eprintln!(
"Usage: {} <secure connect bundle zip> <username> <password>",
args[0]
);
return;
}

let secure_connection_bundle = &args[1];
let username = &args[2];
let password = &args[3];

let mut cluster = Cluster::default();
cluster
.set_cloud_secure_connection_bundle(secure_connection_bundle)
.unwrap();
cluster.set_credentials(username, password).unwrap();

let session = cluster.connect().unwrap();
let statement = stmt!("SELECT release_version FROM system.local");
let result = session.execute(&statement).wait().unwrap();
let row = result.first_row().unwrap();
let version: String = row.get_by_name("release_version").unwrap();
println!("release_version: {}", version);
}
23 changes: 23 additions & 0 deletions src/cassandra/cluster.rs
Expand Up @@ -8,6 +8,8 @@ use crate::cassandra::util::Protected;

use crate::cassandra_sys::cass_cluster_free;
use crate::cassandra_sys::cass_cluster_new;
use crate::cassandra_sys::cass_cluster_set_cloud_secure_connection_bundle_n;
use crate::cassandra_sys::cass_cluster_set_cloud_secure_connection_bundle_no_ssl_lib_init_n;
use crate::cassandra_sys::cass_cluster_set_connect_timeout;
use crate::cassandra_sys::cass_cluster_set_connection_heartbeat_interval;
use crate::cassandra_sys::cass_cluster_set_connection_idle_timeout;
Expand Down Expand Up @@ -157,6 +159,27 @@ impl Cluster {
}
}

/// Sets the secure connection bundle path for processing DBaaS credentials.
pub fn set_cloud_secure_connection_bundle(&mut self, path: &str) -> Result<&mut Self> {
unsafe {
let path_ptr = path.as_ptr() as *const c_char;
let err = cass_cluster_set_cloud_secure_connection_bundle_n(self.0, path_ptr, path.len());
err.to_result(self)
}
}

/// Sets the secure connection bundle path for processing DBaaS credentials, but it
/// does not initialize the underlying SSL library implementation. The SSL library still
/// needs to be initialized, but it's up to the client application to handle
/// initialization.
pub fn set_cloud_secure_connection_bundle_no_ssl_lib_init(&mut self, path: &str) -> Result<&mut Self> {
unsafe {
let path_ptr = path.as_ptr() as *const c_char;
let err = cass_cluster_set_cloud_secure_connection_bundle_no_ssl_lib_init_n(self.0, path_ptr, path.len());
err.to_result(self)
}
}

/// Performs a blocking call to connect to Cassandra cluster
pub fn connect(&mut self) -> Result<Session> {
unsafe {
Expand Down
5 changes: 5 additions & 0 deletions src/cassandra/error.rs
Expand Up @@ -179,6 +179,7 @@ pub(crate) unsafe fn get_cass_future_error(rc: CassError_, inner: *mut _Future)
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
#[allow(missing_docs)] // Meanings are defined in CQL documentation.
#[allow(non_camel_case_types)] // Names are traditional.
#[non_exhaustive]
pub enum CassErrorCode {
// deliberately omits CASS_OK
LIB_BAD_PARAMS,
Expand Down Expand Up @@ -215,6 +216,7 @@ pub enum CassErrorCode {
LIB_INVALID_STATE,
LIB_NO_CUSTOM_PAYLOAD,
LIB_EXECUTION_PROFILE_INVALID,
LIB_NO_TRACING_ID,
SERVER_SERVER_ERROR,
SERVER_PROTOCOL_ERROR,
SERVER_BAD_CREDENTIALS,
Expand All @@ -239,6 +241,7 @@ pub enum CassErrorCode {
SSL_INVALID_PEER_CERT,
SSL_IDENTITY_MISMATCH,
SSL_PROTOCOL_ERROR,
SSL_CLOSED,
// deliberately omits LAST_ENTRY
}

Expand Down Expand Up @@ -277,6 +280,7 @@ enhance_nullary_enum!(CassErrorCode, CassError_, {
(LIB_INVALID_STATE, CASS_ERROR_LIB_INVALID_STATE, "LIB_INVALID_STATE"),
(LIB_NO_CUSTOM_PAYLOAD, CASS_ERROR_LIB_NO_CUSTOM_PAYLOAD, "LIB_NO_CUSTOM_PAYLOAD"),
(LIB_EXECUTION_PROFILE_INVALID, CASS_ERROR_LIB_EXECUTION_PROFILE_INVALID, "LIB_EXECUTION_PROFILE_INVALID"),
(LIB_NO_TRACING_ID, CASS_ERROR_LIB_NO_TRACING_ID, "LIB_NO_TRACING_ID"),
(SERVER_SERVER_ERROR, CASS_ERROR_SERVER_SERVER_ERROR, "SERVER_SERVER_ERROR"),
(SERVER_PROTOCOL_ERROR, CASS_ERROR_SERVER_PROTOCOL_ERROR, "SERVER_PROTOCOL_ERROR"),
(SERVER_BAD_CREDENTIALS, CASS_ERROR_SERVER_BAD_CREDENTIALS, "SERVER_BAD_CREDENTIALS"),
Expand All @@ -301,6 +305,7 @@ enhance_nullary_enum!(CassErrorCode, CassError_, {
(SSL_INVALID_PEER_CERT, CASS_ERROR_SSL_INVALID_PEER_CERT, "SSL_INVALID_PEER_CERT"),
(SSL_IDENTITY_MISMATCH, CASS_ERROR_SSL_IDENTITY_MISMATCH, "SSL_IDENTITY_MISMATCH"),
(SSL_PROTOCOL_ERROR, CASS_ERROR_SSL_PROTOCOL_ERROR, "SSL_PROTOCOL_ERROR"),
(SSL_CLOSED, CASS_ERROR_SSL_CLOSED, "SSL_CLOSED"),
}, omit { CASS_OK, CASS_ERROR_LAST_ENTRY });

/// Extract an optional C string lossily (i.e., using a replacement char for non-UTF-8 sequences).
Expand Down

0 comments on commit f8920d2

Please sign in to comment.