cdrs icon indicating copy to clipboard operation
cdrs copied to clipboard

How can I resolve anonymous/staticpassword dynamically?

Open sisso opened this issue 4 years ago • 0 comments

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?

sisso avatar Dec 25 '20 15:12 sisso