AlexPikalov / cdrs

Cassandra DB native client written in Rust language. Find 1.x versions on https://github.com/AlexPikalov/cdrs/tree/v.1.x Looking for an async version? - Check WIP https://github.com/AlexPikalov/cdrs-async

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I resolve anonymous/staticpassword dynamically?

sisso opened this issue · comments

commented

I was trying to make my credentials configurable. Like this:

    let session = if let Some((user, pass)) = pass {
        let auth = StaticPasswordAuthenticator::new(user, pass);
        let node = NodeTcpConfigBuilder::new("127.0.0.1:9042", auth).build();
        let cluster_config = ClusterTcpConfig(vec![node]);
        session::new(&cluster_config, RoundRobin::new()).expect("session should be created")
    } else {
        let auth = NoneAuthenticator {};
        let node = NodeTcpConfigBuilder::new("127.0.0.1:9042", auth).build();
        let cluster_config = ClusterTcpConfig(vec![node]);
        session::new(&cluster_config, RoundRobin::new()).expect("session should be created")
    };

That obviously fails as it will generate incompatible types. What would be the proper way?