Search code examples
scalacassandraphantom-dsl

Phantom Scala Cassandra connector: how to specify port, username, password of nodes


I'm trying to use websudos phantom

Does anyone know how to specify connection arguments to Cassandra such as username and password?

Thanks


Solution

  • Phantom doesn't yet support Kerberos authentication in the phantom-connectors framework but it is on the roadmap for the coming weeks.

    However, when using connectors it is possible to override the createCluster method and connect to the cluster in any way you want.

    object CustomCassandraManger extends DefaultCasandraManager {
    
      override protected[this] def createCluster: Cluster = {
        val inets = hosts.toSeq.map(_.getAddress)
    
        Cluster.builder()
         .addContactPoints(inets: _*)
         ...
         .withUsernameAndPassword(..)
      }
    }
    

    I may not have used the correct methods, but that's how you control the way a cluster is created. Then all you need is to inject this manager in a connector:

    trait MyConnector extends SimpleCassandraConnector {
      override val manager = CustomCassandraMananger
    }
    

    And then you mix in this connector into all your tables, just as you would normally when using phantom.

    Recent versions of phantom

    In more recent versions of phantom, the API is based on ContactPoints, where you can specify whatever ClusterBuilder options you want, using the following DSL.

    import com.datastax.driver.core.PlainTextAuthProvider
    
    lazy val local = ContactPoint.local.withClusterBuilder(
      _.withAuthProvider(new PlainTextAuthProvider("user", "pass"))
    ).keySpace("phantom")