From: tierno Date: Tue, 23 Oct 2018 09:41:49 +0000 (+0200) Subject: bug559 some modifications X-Git-Tag: v5.0.0~8 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F6736%2F3;p=osm%2Fcommon.git bug559 some modifications Change-Id: I9ab949b8cf1aea0899f0374e4b2e05c334160009 Signed-off-by: tierno --- diff --git a/devops-stages/stage-test.sh b/devops-stages/stage-test.sh index 5dcbd36..4de3cc4 100755 --- a/devops-stages/stage-test.sh +++ b/devops-stages/stage-test.sh @@ -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 diff --git a/osm_common/__init__.py b/osm_common/__init__.py index eb221c0..1c60968 100644 --- a/osm_common/__init__.py +++ b/osm_common/__init__.py @@ -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' diff --git a/osm_common/dbbase.py b/osm_common/dbbase.py index 3959383..5fef9ee 100644 --- a/osm_common/dbbase.py +++ b/osm_common/dbbase.py @@ -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 """ diff --git a/osm_common/dbmemory.py b/osm_common/dbmemory.py index 0e0c42c..bae68e2 100644 --- a/osm_common/dbmemory.py +++ b/osm_common/dbmemory.py @@ -26,8 +26,8 @@ __author__ = "Alfonso Tierno " 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): diff --git a/osm_common/dbmongo.py b/osm_common/dbmongo.py index af63d5b..2e94a5a 100644 --- a/osm_common/dbmongo.py +++ b/osm_common/dbmongo.py @@ -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'])) diff --git a/osm_common/msgbase.py b/osm_common/msgbase.py index 5ba8f71..0a15dae 100644 --- a/osm_common/msgbase.py +++ b/osm_common/msgbase.py @@ -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) - diff --git a/osm_common/tests/test_dbbase.py b/osm_common/tests/test_dbbase.py index 64bfb3e..918ced7 100644 --- a/osm_common/tests/test_dbbase.py +++ b/osm_common/tests/test_dbbase.py @@ -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):