pyc-website

main website for pyc inc.

git clone https://9o.is/git/pyc-website.git

MongoConfig.scala

(1333B)


      1 package inc.pyc
      2 package config
      3 
      4 import net.liftweb._
      5 import common._
      6 import util._
      7 import http._
      8 import json._
      9 import mongodb._
     10 import util.Props
     11 import scala.collection.JavaConversions._
     12 
     13 import com.mongodb.{DBAddress, MongoClient, ServerAddress}
     14 
     15 object MongoConfig extends Factory with Loggable {
     16 
     17   // configure your MongoMetaRecords to use this. See lib/RogueMetaRecord.scala.
     18   val defaultId = new FactoryMaker[ConnectionIdentifier](DefaultConnectionIdentifier) {}
     19 
     20   def init() {
     21     /**
     22       * First checks for existence of mongo.default.url. If not found, then
     23       * checks for mongo.default.host, port, and name. Uses defaults if those
     24       * are not found.
     25       */
     26     val replicas: List[ServerAddress] = (Props.get("mongo.default.replicas", "").split(",") map {
     27       server =>
     28         val s = server.split(":")
     29         new ServerAddress(s(0), s(1).toInt)
     30     }) toList
     31     
     32     val database = Props.get("mongo.default.database", "")
     33     val username = Props.get("mongo.default.username", "")
     34     val password = Props.get("mongo.default.password", "")
     35 
     36     MongoDB.defineDbAuth(
     37         DefaultConnectionIdentifier, 
     38         new MongoClient(replicas), 
     39         database, 
     40         username, 
     41         password
     42     )
     43     
     44     logger.info("MongoDB inited using authentication: %s".format(replicas.toString))
     45     
     46   }
     47 }
     48