Rust connecting
Authentication
This example assumes that you’re running Stargate locally with the default credentials
of cassandra/cassandra
.
For more information regarding authentication please see the
Stargate authentication and authorization docs.
You’ll need to generate a token to insert into the client connection code:
curl -L -X POST 'http://$ASTRA_CLUSTER_ID-$ASTRA_REGION.apps.astra.datastax.com:8081/v1/auth' \
-H 'Content-Type: application/json' \
--data-raw '{
"username": "cassandra",
"password": "cassandra"
}'
Set up client
The main structure that provides the interface to Stargate is StargateClient
.
The simplest way to obtain an instance is to use the provided builder
:
use stargate_grpc::*;
use std::str::FromStr;
// Set the Stargate OSS configuration for a locally running docker container:
let sg_uri = "http://localhost:8090/";
let auth_token = "06251024-5aeb-4200-a132-5336e73e5b6e";
// For Stargate OSS: create a client
let mut client = StargateClient::builder()
.uri(sg_uri)?
.auth_token(AuthToken::from_str(auth_token)?)
.connect()
.await?;
println!("created client {:?}", client);