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 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)]
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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!(
|
||||
|
|
Loading…
Reference in a new issue