add auth to scylla migration

This commit is contained in:
ThatOneCalculator 2023-09-24 19:58:21 -07:00
parent 4b6a436753
commit 24a6d0ed08
No known key found for this signature in database
GPG key ID: 8703CACD01000000
3 changed files with 28 additions and 8 deletions

View file

@ -13,6 +13,14 @@ pub struct ScyllaConfig {
pub nodes: Vec<String>,
pub keyspace: String,
pub replication_factor: i32,
pub credentials: Option<Credentials>,
}
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Credentials {
pub username: String,
pub password: String,
}
#[derive(Debug, PartialEq, Deserialize)]

View file

@ -39,10 +39,14 @@ impl Migrator {
}
pub(crate) async fn new(dir: PathBuf, config: &ScyllaConfig) -> Result<Self, Error> {
let session = SessionBuilder::new()
.known_nodes(&config.nodes)
.build()
.await?;
let mut builder = SessionBuilder::new()
.known_nodes(&config.nodes);
if let Some(credentials) = &config.credentials {
builder = builder.user(&credentials.username, &credentials.password);
}
let session = builder.build().await?;
session
.query(

View file

@ -32,10 +32,18 @@ impl Initializer {
scylla_conf: &ScyllaConfig,
postgres_conf: &DbConfig,
) -> Result<Self, Error> {
let session = SessionBuilder::new()
.known_nodes(&scylla_conf.nodes)
.build()
.await?;
let mut builder = SessionBuilder::new()
.known_nodes(&scylla_conf.nodes);
match &scylla_conf.credentials {
Some(credentials) => {
builder = builder.user(&credentials.username, &credentials.password);
},
None => {}
}
let session = builder.build().await?;
session.use_keyspace(&scylla_conf.keyspace, true).await?;
let conn_url = format!(