bug559 some modifications 36/6736/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 23 Oct 2018 09:41:49 +0000 (11:41 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 23 Oct 2018 11:48:44 +0000 (13:48 +0200)
Change-Id: I9ab949b8cf1aea0899f0374e4b2e05c334160009
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
devops-stages/stage-test.sh
osm_common/__init__.py
osm_common/dbbase.py
osm_common/dbmemory.py
osm_common/dbmongo.py
osm_common/msgbase.py
osm_common/tests/test_dbbase.py

index 5dcbd36..4de3cc4 100755 (executable)
@@ -13,6 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-tox -e flake8
-tox -e unittest
+tox -e flake8     && \
+tox -e unittest   && \
 tox -e pytest
index eb221c0..1c60968 100644 (file)
@@ -15,7 +15,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-version = '0.1.10'
+version = '0.1.11'
 # TODO add package version filling commit id with 0's; e.g.:  '5.0.0.post11+00000000.dirty-1'
-date_version = '2018-10-22'
-
+date_version = '2018-10-23'
index 3959383..5fef9ee 100644 (file)
@@ -34,20 +34,25 @@ class DbException(Exception):
 
 class DbBase(object):
 
-    def __init__(self, logger_name='db', master_password=None):
+    def __init__(self, logger_name='db'):
         """
         Constructor od dbBase
         :param logger_name: logging name
-        :param master_password: master password used for encrypt decrypt methods
         """
         self.logger = logging.getLogger(logger_name)
-        self.master_password = master_password
+        self.master_password = None
         self.secret_key = None
 
     def db_connect(self, config, target_version=None):
         """
         Connect to database
-        :param config: Configuration of database
+        :param config: Configuration of database. Contains among others:
+            host:   database hosst (mandatory)
+            port:   database port (mandatory)
+            name:   database name (mandatory)
+            user:   database username
+            password:   database password
+            masterpassword: database password used for sensible information encryption
         :param target_version: if provided it checks if database contains required version, raising exception otherwise.
         :return: None or raises DbException on error
         """
index 0e0c42c..bae68e2 100644 (file)
@@ -26,8 +26,8 @@ __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
 
 class DbMemory(DbBase):
 
-    def __init__(self, logger_name='db', master_password=None):
-        super().__init__(logger_name, master_password)
+    def __init__(self, logger_name='db'):
+        super().__init__(logger_name)
         self.db = {}
 
     def db_connect(self, config):
@@ -38,6 +38,7 @@ class DbMemory(DbBase):
         """
         if "logger_name" in config:
             self.logger = logging.getLogger(config["logger_name"])
+        self.master_password = config.get("masterpassword")
 
     @staticmethod
     def _format_filter(q_filter):
index af63d5b..2e94a5a 100644 (file)
@@ -62,8 +62,8 @@ class DbMongo(DbBase):
     conn_initial_timout = 120
     conn_timout = 10
 
-    def __init__(self, logger_name='db', master_password=None):
-        super().__init__(logger_name, master_password)
+    def __init__(self, logger_name='db'):
+        super().__init__(logger_name)
         self.client = None
         self.db = None
 
@@ -77,7 +77,10 @@ class DbMongo(DbBase):
         try:
             if "logger_name" in config:
                 self.logger = logging.getLogger(config["logger_name"])
+            self.master_password = config.get("masterpassword")
             self.client = MongoClient(config["host"], config["port"])
+            # TODO add as parameters also username=config.get("user"), password=config.get("password"))
+            # when all modules are ready
             self.db = self.client[config["name"]]
             if "loglevel" in config:
                 self.logger.setLevel(getattr(logging, config['loglevel']))
index 5ba8f71..0a15dae 100644 (file)
@@ -60,4 +60,3 @@ class MsgBase(object):
 
     async def aioread(self, topic, loop=None, callback=None, aiocallback=None, **kwargs):
         raise MsgException("Method 'aioread' not implemented", http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
-
index 64bfb3e..918ced7 100644 (file)
@@ -68,11 +68,11 @@ def test_del_one(db_base):
 class TestEncryption(unittest.TestCase):
     def setUp(self):
         master_password = "Setting a long master password with numbers 123 and capitals AGHBNHD and symbols %&8)!'"
-        db_base1 = DbBase(master_password=master_password)
+        db_base1 = DbBase()
         db_base2 = DbBase()
         # set self.secret_key obtained when connect
-        db_base1.secret_key = DbBase._join_passwords(urandom(32), db_base1.master_password)
-        db_base2.secret_key = DbBase._join_passwords(urandom(32), db_base2.master_password)
+        db_base1.secret_key = DbBase._join_passwords(urandom(32), master_password)
+        db_base2.secret_key = DbBase._join_passwords(urandom(32), None)
         self.db_base = [db_base1, db_base2]
 
     def test_encrypt_decrypt(self):