add auth to scylla migration
This commit is contained in:
parent
4b6a436753
commit
24a6d0ed08
3 changed files with 28 additions and 8 deletions
|
@ -13,6 +13,14 @@ pub struct ScyllaConfig {
|
||||||
pub nodes: Vec<String>,
|
pub nodes: Vec<String>,
|
||||||
pub keyspace: String,
|
pub keyspace: String,
|
||||||
pub replication_factor: i32,
|
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)]
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
|
|
@ -39,10 +39,14 @@ impl Migrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn new(dir: PathBuf, config: &ScyllaConfig) -> Result<Self, Error> {
|
pub(crate) async fn new(dir: PathBuf, config: &ScyllaConfig) -> Result<Self, Error> {
|
||||||
let session = SessionBuilder::new()
|
let mut builder = SessionBuilder::new()
|
||||||
.known_nodes(&config.nodes)
|
.known_nodes(&config.nodes);
|
||||||
.build()
|
|
||||||
.await?;
|
if let Some(credentials) = &config.credentials {
|
||||||
|
builder = builder.user(&credentials.username, &credentials.password);
|
||||||
|
}
|
||||||
|
|
||||||
|
let session = builder.build().await?;
|
||||||
|
|
||||||
session
|
session
|
||||||
.query(
|
.query(
|
||||||
|
|
|
@ -32,10 +32,18 @@ impl Initializer {
|
||||||
scylla_conf: &ScyllaConfig,
|
scylla_conf: &ScyllaConfig,
|
||||||
postgres_conf: &DbConfig,
|
postgres_conf: &DbConfig,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let session = SessionBuilder::new()
|
|
||||||
.known_nodes(&scylla_conf.nodes)
|
let mut builder = SessionBuilder::new()
|
||||||
.build()
|
.known_nodes(&scylla_conf.nodes);
|
||||||
.await?;
|
|
||||||
|
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?;
|
session.use_keyspace(&scylla_conf.keyspace, true).await?;
|
||||||
|
|
||||||
let conn_url = format!(
|
let conn_url = format!(
|
||||||
|
|
Loading…
Reference in a new issue