Skip to content

Commit ad94840

Browse files
committed
Adicionado suporte a mongoDB com auth habilitada
1 parent c4df343 commit ad94840

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,23 @@ ou
4040
>> _standalone()
4141

4242
Caso queira rodar em outra porta, basta passá-la como parametro no chamado do _standalone
43+
44+
45+
MongoDB com autenticação
46+
------------------------
47+
48+
Se o seu MongoDB possui autenticação habilitada você deverá configurar o banco do postmon
49+
e também exportar duas variavéis de ambiente.
50+
51+
```javascript
52+
mongo
53+
> use postmon
54+
> db.addUser('admin', '123456')
55+
```
56+
57+
Agora que seu Mongo está com password exporte as variaveis de ambiente.
58+
59+
```bash
60+
export POSTMON_DB_USER=admin
61+
export POSTMON_DB_PASSWORD=123456
62+
```

database.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
import os
34
import pymongo
45

56

@@ -15,6 +16,10 @@ class MongoDb(object):
1516

1617
def __init__(self, address='localhost'):
1718
self._client = pymongo.MongoClient(address)
19+
USERNAME = os.environ.get('POSTMON_DB_USER')
20+
PASSWORD = os.environ.get('POSTMON_DB_PASSWORD')
21+
if all((USERNAME, PASSWORD)):
22+
self._client.postmon.authenticate(USERNAME, PASSWORD)
1823
self._db = self._client.postmon
1924

2025
def get_one(self, cep, **kwargs):

0 commit comments

Comments
 (0)