pyc-website

main website for pyc inc.

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

commit 45f6ffb05b45ca84edc6db3f1142c1f749a409c2
parent c5da84246f0c37ccbe26117cde3206a256b477cc
Author: Jul <jul@9o.is>
Date:   Mon, 21 Jul 2014 16:32:35 -0400

application uses authenticated replica set

Diffstat:
Msrc/main/resources/props/production.default.props | 9++++-----
Msrc/main/scala/inc/pyc/config/MongoConfig.scala | 50+++++++++++++++++++++-----------------------------
2 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/src/main/resources/props/production.default.props b/src/main/resources/props/production.default.props @@ -5,11 +5,10 @@ mail.smtp.pass= mail.smtp.port=587 mail.smtp.auth=true -mongo.default.host= -mongo.default.port= -mongo.default.name= -mongo.default.user= -mongo.default.pwd= +mongo.default.replicas= +mongo.default.database= +mongo.default.username= +mongo.default.password= google.analytics.id= diff --git a/src/main/scala/inc/pyc/config/MongoConfig.scala b/src/main/scala/inc/pyc/config/MongoConfig.scala @@ -8,8 +8,9 @@ import http._ import json._ import mongodb._ import util.Props +import scala.collection.JavaConversions._ -import com.mongodb.{DBAddress, MongoClient} +import com.mongodb.{DBAddress, MongoClient, ServerAddress} object MongoConfig extends Factory with Loggable { @@ -22,35 +23,26 @@ object MongoConfig extends Factory with Loggable { * checks for mongo.default.host, port, and name. Uses defaults if those * are not found. */ - val defaultDbAddress = Props.get("mongo.default.url") - .map(url => new DBAddress(url)) - .openOr(new DBAddress( - Props.get("mongo.default.host", "127.0.0.1"), - Props.getInt("mongo.default.port", 27017), - Props.get("mongo.default.name", "pyc") - )) + val replicas: List[ServerAddress] = (Props.get("mongo.default.replicas", "").split(",") map { + server => + val s = server.split(":") + new ServerAddress(s(0), s(1).toInt) + }) toList + + val database = Props.get("mongo.default.database", "") + val username = Props.get("mongo.default.username", "") + val password = Props.get("mongo.default.password", "") - /* - * If mongo.default.user, and pwd are defined, configure Mongo using authentication. - */ - (Props.get("mongo.default.user"), Props.get("mongo.default.pwd")) match { - case (Full(user), Full(pwd)) => - MongoDB.defineDbAuth( - DefaultConnectionIdentifier, - new MongoClient(defaultDbAddress), - defaultDbAddress.getDBName, - user, - pwd - ) - logger.info("MongoDB inited using authentication: %s".format(defaultDbAddress.toString)) - case _ => - MongoDB.defineDb( - DefaultConnectionIdentifier, - new MongoClient(defaultDbAddress), - defaultDbAddress.getDBName - ) - logger.info("MongoDB inited: %s".format(defaultDbAddress.toString)) - } + MongoDB.defineDbAuth( + DefaultConnectionIdentifier, + new MongoClient(replicas), + database, + username, + password + ) + + logger.info("MongoDB inited using authentication: %s".format(replicas.toString)) + } }