Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of remote mongodb with config in ENV variables set by MHN install script #18

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion broker/add_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pymongo
import sys
import json
import os

def handle_list(arg):
if arg:
Expand All @@ -25,7 +27,9 @@ def handle_list(arg):
"subscribe":subscribe
}

client = pymongo.MongoClient()
client = pymongo.MongoClient(host=os.getenv("MONGO_HOST"), port=int(os.getenv("MONGO_PORT")))
if os.getenv("MONGO_AUTH") == "true":
client.hpfeeds.authenticate(os.getenv("MONGO_USER"), os.getenv("MONGO_PASSWORD"), mechanism=os.getenv("MONGO_AUTH_MECHANISM"))
res = client.hpfeeds.auth_key.update({"identifier": ident}, {"$set": rec}, upsert=True)
client.fsync()
client.close()
Expand Down
6 changes: 5 additions & 1 deletion broker/dump_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import pymongo
import sys
import json
import os

client = pymongo.MongoClient()
client = pymongo.MongoClient(host=os.getenv("MONGO_HOST"), port=int(os.getenv("MONGO_PORT")))
if os.getenv("MONGO_AUTH") == "true":
client.hpfeeds.authenticate(os.getenv("MONGO_USER"), os.getenv("MONGO_PASSWORD"), mechanism=os.getenv("MONGO_AUTH_MECHANISM"))
for doc in client.hpfeeds.auth_key.find():
print doc

Expand Down
18 changes: 18 additions & 0 deletions broker/feedbroker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import hashlib
import collections
import random
import json
import os

import logging
logging.basicConfig(level=logging.INFO)
Expand All @@ -18,6 +20,10 @@
FBNAME = '@hp2'
MONGOIP = '127.0.0.1'
MONGOPORT = 27017
MONGOAUTH = False
MONGOUSER = None
MONGOPASSWORD = None
MONGOAUTHMECHANISM = None

OP_ERROR = 0
OP_INFO = 1
Expand Down Expand Up @@ -224,6 +230,7 @@ def __init__(self):

def initdb(self):
self.db = MongoConn(MONGOIP, MONGOPORT)
self.db.auth("hpfeeds", MONGOUSER, MONGOPASSWORD)
self.db._on('ready', self._dbready)
self.db._on('close', self._dbclose)

Expand Down Expand Up @@ -281,6 +288,17 @@ def _brokerchan(self, c, chan, ident, subscribe=0):
c2.publish(ident, chan+'..broker', data)

def main():
global MONGOIP, MONGOPORT, MONGOAUTH, MONGOUSER, MONGOPASSWORD, MONGOAUTHMECHANISM
MONGOIP = os.getenv("MONGO_HOST")
MONGOPORT = int(os.getenv("MONGO_PORT"))
if os.getenv("MONGO_AUTH") == "true":
MONGOAUTH = True
else:
MONGOAUTH = False
MONGOUSER = os.getenv("MONGO_USER")
MONGOPASSWORD = os.getenv("MONGO_PASSWORD")
MONGOAUTHMECHANISM = os.getenv("MONGO_AUTH_MECHANISM")

fb = FeedBroker()

loop()
Expand Down
6 changes: 5 additions & 1 deletion broker/get_secret.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import pymongo
import sys
import json
import os

ident = sys.argv[1]
client = pymongo.MongoClient()
client = pymongo.MongoClient(host=os.getenv("MONGO_HOST"), port=int(os.getenv("MONGO_PORT")))
if os.getenv("MONGO_AUTH") == "true":
client.hpfeeds.authenticate(os.getenv("MONGO_USER"), os.getenv("MONGO_PASSWORD"), mechanism=os.getenv("MONGO_AUTH_MECHANISM"))
results = client.hpfeeds.auth_key.find({'identifier': ident})
if results.count() > 0:
print results[0]['secret']