aboutsummaryrefslogtreecommitdiffstats
path: root/python_moondb
diff options
context:
space:
mode:
authorThomas Duval <thomas.duval@orange.com>2017-12-28 16:21:28 +0100
committerThomas Duval <thomas.duval@orange.com>2017-12-28 16:26:06 +0100
commitb4903464ad8185985e1801de497f2755dfd80df8 (patch)
treee33aea822b23f5ed320237d61a67afc0ffadb36a /python_moondb
parent6b0d5c0bad36bf6879d6c9abebf7a3ee79b9e154 (diff)
Clean the code
Change-Id: Ifba24bb030db84db27970ca66d069c03a3f4af14
Diffstat (limited to 'python_moondb')
-rw-r--r--python_moondb/Changelog4
-rw-r--r--python_moondb/build.sh38
-rw-r--r--python_moondb/python_moondb/__init__.py2
-rw-r--r--python_moondb/python_moondb/api/keystone.py10
-rw-r--r--python_moondb/python_moondb/api/managers.py4
-rw-r--r--python_moondb/python_moondb/api/model.py6
-rw-r--r--python_moondb/python_moondb/api/pdp.py6
-rw-r--r--python_moondb/python_moondb/api/policy.py4
-rw-r--r--python_moondb/python_moondb/backends/flat.py89
-rw-r--r--python_moondb/python_moondb/backends/sql.py8
-rw-r--r--python_moondb/python_moondb/core.py8
-rw-r--r--python_moondb/requirements.txt2
-rw-r--r--python_moondb/setup.py1
13 files changed, 27 insertions, 155 deletions
diff --git a/python_moondb/Changelog b/python_moondb/Changelog
index ff244af5..a7d10b17 100644
--- a/python_moondb/Changelog
+++ b/python_moondb/Changelog
@@ -53,3 +53,7 @@ CHANGES
-----
- Update the name of the library (from moon_db)
+1.2.5
+-----
+- Code cleaning
+
diff --git a/python_moondb/build.sh b/python_moondb/build.sh
deleted file mode 100644
index f109e9b8..00000000
--- a/python_moondb/build.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env bash
-
-VERSION=moon_db-$(grep __version__ moon_db/__init__.py | cut -d "\"" -f 2)
-
-python3 setup.py sdist bdist_wheel
-
-rm dist/*.asc 2>/dev/null
-
-gpg --detach-sign -u "A0A96E75" -a dist/${VERSION}-py3-none-any.whl
-gpg --detach-sign -u "A0A96E75" -a dist/${VERSION}.tar.gz
-
-if [ "$1" = "upload" ]; then
- twine upload dist/${VERSION}-py3-none-any.whl dist/${VERSION}-py3-none-any.whl.asc
- twine upload dist/${VERSION}.tar.gz dist/${VERSION}.tar.gz.asc
- rm -f ../moon_orchestrator/dist/moon_db*
- rm -f ../moon_interface/dist/moon_db*
- rm -f ../moon_manager/dist/moon_db*
- rm -f ../moon_authz/dist/moon_db*
- rm -f ../moon_wrapper/dist/moon_db*
-fi
-
-if [ "$1" = "copy" ]; then
- mkdir -p ../moon_orchestrator/dist/ 2>/dev/null
- rm -f ../moon_orchestrator/dist/moon_db*
- cp -v dist/${VERSION}-py3-none-any.whl ../moon_orchestrator/dist/
- mkdir -p ../moon_interface/dist/ 2>/dev/null
- rm -f ../moon_interface/dist/moon_db*
- cp -v dist/${VERSION}-py3-none-any.whl ../moon_interface/dist/
- mkdir -p ../moon_manager/dist/ 2>/dev/null
- rm -f ../moon_manager/dist/moon_db*
- cp -v dist/${VERSION}-py3-none-any.whl ../moon_manager/dist/
- mkdir -p ../moon_authz/dist/ 2>/dev/null
- rm -f ../moon_authz/dist/moon_db*
- cp -v dist/${VERSION}-py3-none-any.whl ../moon_authz/dist/
- mkdir -p ../moon_wrapper/dist/ 2>/dev/null
- rm -f ../moon_wrapper/dist/moon_db*
- cp -v dist/${VERSION}-py3-none-any.whl ../moon_wrapper/dist/
-fi
diff --git a/python_moondb/python_moondb/__init__.py b/python_moondb/python_moondb/__init__.py
index 73faf752..de7c772e 100644
--- a/python_moondb/python_moondb/__init__.py
+++ b/python_moondb/python_moondb/__init__.py
@@ -3,5 +3,5 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-__version__ = "1.2.4"
+__version__ = "1.2.5"
diff --git a/python_moondb/python_moondb/api/keystone.py b/python_moondb/python_moondb/api/keystone.py
index f5410190..582ae710 100644
--- a/python_moondb/python_moondb/api/keystone.py
+++ b/python_moondb/python_moondb/api/keystone.py
@@ -7,12 +7,12 @@ import os
import requests
import json
from uuid import uuid4
-from oslo_log import log as logging
+import logging
from python_moonutilities import exceptions, configuration
from python_moonutilities.security_functions import filter_input, login, logout
from python_moondb.api.managers import Managers
-LOG = logging.getLogger("moon.db.api.keystone")
+logger = logging.getLogger("moon.db.api.keystone")
class KeystoneManager(Managers):
@@ -37,7 +37,7 @@ class KeystoneManager(Managers):
_headers = login()
req = requests.get("{}{}".format(self.__url, endpoint), headers=_headers, verify=False)
if req.status_code not in (200, 201):
- LOG.error(req.text)
+ logger.error(req.text)
raise _exception
data = req.json()
logout(_headers)
@@ -49,10 +49,10 @@ class KeystoneManager(Managers):
data=json.dumps(data),
headers=_headers, verify=False)
if req.status_code == 409:
- LOG.warning(req.text)
+ logger.warning(req.text)
raise exceptions.KeystoneUserConflict
if req.status_code not in (200, 201):
- LOG.error(req.text)
+ logger.error(req.text)
raise _exception
data = req.json()
logout(_headers)
diff --git a/python_moondb/python_moondb/api/managers.py b/python_moondb/python_moondb/api/managers.py
index 602e0f11..f500d02e 100644
--- a/python_moondb/python_moondb/api/managers.py
+++ b/python_moondb/python_moondb/api/managers.py
@@ -3,8 +3,8 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-from oslo_log import log as logging
-LOG = logging.getLogger("moon.db.api.managers")
+import logging
+logger = logging.getLogger("moon.db.api.managers")
class Managers(object):
diff --git a/python_moondb/python_moondb/api/model.py b/python_moondb/python_moondb/api/model.py
index fbfbb680..bd475365 100644
--- a/python_moondb/python_moondb/api/model.py
+++ b/python_moondb/python_moondb/api/model.py
@@ -4,13 +4,13 @@
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
from uuid import uuid4
-from oslo_log import log as logging
+import logging
from python_moonutilities import exceptions
from python_moonutilities.security_functions import filter_input, enforce
from python_moondb.api.managers import Managers
-LOG = logging.getLogger("moon.db.api.model")
+logger = logging.getLogger("moon.db.api.model")
class ModelManager(Managers):
@@ -60,7 +60,7 @@ class ModelManager(Managers):
raise exceptions.MetaRuleExisting
if not meta_rule_id:
meta_rule_id = uuid4().hex
- LOG.info("add_meta_rule {}".format(value))
+ logger.info("add_meta_rule {}".format(value))
return self.driver.set_meta_rule(meta_rule_id=meta_rule_id, value=value)
@enforce(("read", "write"), "meta_rules")
diff --git a/python_moondb/python_moondb/api/pdp.py b/python_moondb/python_moondb/api/pdp.py
index 5fb7aa78..c75040ae 100644
--- a/python_moondb/python_moondb/api/pdp.py
+++ b/python_moondb/python_moondb/api/pdp.py
@@ -4,12 +4,12 @@
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
from uuid import uuid4
-from oslo_log import log as logging
-from python_moonutilities.security_functions import filter_input, enforce
+import logging
+from python_moonutilities.security_functions import enforce
from python_moondb.api.managers import Managers
-LOG = logging.getLogger("moon.db.api.pdp")
+logger = logging.getLogger("moon.db.api.pdp")
class PDPManager(Managers):
diff --git a/python_moondb/python_moondb/api/policy.py b/python_moondb/python_moondb/api/policy.py
index 81689826..9781fda8 100644
--- a/python_moondb/python_moondb/api/policy.py
+++ b/python_moondb/python_moondb/api/policy.py
@@ -8,7 +8,7 @@ import logging
from python_moonutilities.security_functions import enforce
from python_moondb.api.managers import Managers
-LOG = logging.getLogger("moon.db.api.policy")
+logger = logging.getLogger("moon.db.api.policy")
class PolicyManager(Managers):
@@ -56,7 +56,7 @@ class PolicyManager(Managers):
k_user = Managers.KeystoneManager.create_user(value)
if not perimeter_id:
try:
- LOG.info("k_user={}".format(k_user))
+ logger.info("k_user={}".format(k_user))
perimeter_id = k_user['users'][0].get('id', uuid4().hex)
except IndexError:
k_user = Managers.KeystoneManager.get_user_by_name(
diff --git a/python_moondb/python_moondb/backends/flat.py b/python_moondb/python_moondb/backends/flat.py
deleted file mode 100644
index 0fe2f00b..00000000
--- a/python_moondb/python_moondb/backends/flat.py
+++ /dev/null
@@ -1,89 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-import logging
-import time
-from python_moondb.core import LogDriver
-
-
-class LogConnector(LogDriver):
-
- AUTHZ_FILE = '/var/log/moon/authz.log'
- SYS_FILE = '/var/log/moon/system.log'
- TIME_FORMAT = '%Y-%m-%d-%H:%M:%S'
-
- def __init__(self):
- # Fixme (dthom): when logging from an other class, the %appname% in the event
- # is always keystone.contrib.moon.backends.flat
- super(LogConnector, self).__init__()
-
- self.SYS_LOG = logging.getLogger(__name__)
- if not len(self.SYS_LOG.handlers):
- fh = logging.FileHandler(self.SYS_FILE)
- fh.setLevel(logging.DEBUG)
- formatter = logging.Formatter('%(asctime)s ------ %(message)s', self.TIME_FORMAT)
- fh.setFormatter(formatter)
- self.SYS_LOG.addHandler(fh)
-
- self.AUTHZ_LOG = logging.getLogger("authz")
- if not len(self.AUTHZ_LOG.handlers):
- fh = logging.FileHandler(self.AUTHZ_FILE)
- fh.setLevel(logging.WARNING)
- formatter = logging.Formatter('%(asctime)s ------ %(message)s', self.TIME_FORMAT)
- fh.setFormatter(formatter)
- self.AUTHZ_LOG.addHandler(fh)
-
- def authz(self, message):
- self.AUTHZ_LOG.warn(message)
-
- def debug(self, message):
- self.SYS_LOG.debug(message)
-
- def info(self, message):
- self.SYS_LOG.info(message)
-
- def warning(self, message):
- self.SYS_LOG.warning(message)
-
- def error(self, message):
- self.SYS_LOG.error(message)
-
- def critical(self, message):
- self.SYS_LOG.critical(message)
-
- def get_logs(self, logger="authz", event_number=None, time_from=None, time_to=None, filter_str=None):
- if logger == "authz":
- _logs = open(self.AUTHZ_FILE).readlines()
- else:
- _logs = open(self.SYS_FILE).readlines()
- if filter_str:
- _logs = filter(lambda x: filter_str in x, _logs)
- if time_from:
- if isinstance(time_from, str):
- time_from = time.strptime(time_from.split(" ")[0], self.TIME_FORMAT)
- try:
- __logs = []
- for log in _logs:
- _log = time.strptime(log.split(" ")[0], self.TIME_FORMAT)
- if time_from <= _log:
- __logs.append(log)
- _logs = __logs
- except ValueError:
- self.error("Time format error")
- if time_to:
- try:
- if isinstance(time_to, str):
- time_to = time.strptime(time_to.split(" ")[0], self.TIME_FORMAT)
- __logs = []
- for log in _logs:
- _log = time.strptime(log.split(" ")[0], self.TIME_FORMAT)
- if time_to >= _log:
- __logs.append(log)
- _logs = __logs
- except ValueError:
- self.error("Time format error")
- if event_number:
- _logs = _logs[-event_number:]
- return list(_logs)
diff --git a/python_moondb/python_moondb/backends/sql.py b/python_moondb/python_moondb/backends/sql.py
index b4a8531f..1ce8d016 100644
--- a/python_moondb/python_moondb/backends/sql.py
+++ b/python_moondb/python_moondb/backends/sql.py
@@ -17,7 +17,7 @@ from python_moonutilities import configuration
from python_moonutilities.exceptions import *
from python_moondb.core import PDPDriver, PolicyDriver, ModelDriver
-LOG = logging.getLogger("moon.db.driver.sql")
+logger = logging.getLogger("moon.db.driver.sql")
Base = declarative_base()
DEBUG = True if configuration.get_configuration("logging")['logging']['loggers']['moon']['level'] == "DEBUG" else False
@@ -648,7 +648,7 @@ class PolicyConnector(BaseConnector, PolicyDriver):
session.delete(_action)
def get_subject_data(self, policy_id, data_id=None, category_id=None):
- LOG.info("driver {} {} {}".format(policy_id, data_id, category_id))
+ logger.info("driver {} {} {}".format(policy_id, data_id, category_id))
with self.get_session_for_read() as session:
query = session.query(SubjectData)
if data_id:
@@ -656,7 +656,7 @@ class PolicyConnector(BaseConnector, PolicyDriver):
else:
query = query.filter_by(policy_id=policy_id, category_id=category_id)
ref_list = query.all()
- LOG.info("ref_list={}".format(ref_list))
+ logger.info("ref_list={}".format(ref_list))
return {
"policy_id": policy_id,
"category_id": category_id,
@@ -982,7 +982,7 @@ class PolicyConnector(BaseConnector, PolicyDriver):
ref_list = query.all()
rules = list(map(lambda x: x.rule, ref_list))
if not rules or value not in rules:
- LOG.info("add_rule IN IF")
+ logger.info("add_rule IN IF")
ref = Rule.from_dict(
{
"id": uuid4().hex,
diff --git a/python_moondb/python_moondb/core.py b/python_moondb/python_moondb/core.py
index 49b3c7dd..984b81a7 100644
--- a/python_moondb/python_moondb/core.py
+++ b/python_moondb/python_moondb/core.py
@@ -3,20 +3,18 @@
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-from oslo_log import log as logging
-from oslo_config import cfg
+import logging
from stevedore.driver import DriverManager
from python_moonutilities import configuration
from python_moondb.api import model, policy, pdp, keystone
-CONF = cfg.CONF
-LOG = logging.getLogger("moon.db")
+logger = logging.getLogger("moon.db")
class Driver(DriverManager):
def __init__(self, driver_name, engine_name):
- LOG.info("initialization of Driver {}".format(driver_name))
+ logger.info("initialization of Driver {}".format(driver_name))
super(Driver, self).__init__(
namespace='moon_db.driver',
name=driver_name,
diff --git a/python_moondb/requirements.txt b/python_moondb/requirements.txt
index 03afc879..a205666f 100644
--- a/python_moondb/requirements.txt
+++ b/python_moondb/requirements.txt
@@ -2,5 +2,3 @@ stevedore
sqlalchemy
pymysql
requests
-oslo.log
-oslo.config
diff --git a/python_moondb/setup.py b/python_moondb/setup.py
index 65687c3f..e34369d4 100644
--- a/python_moondb/setup.py
+++ b/python_moondb/setup.py
@@ -45,7 +45,6 @@ setup(
"moon_db.driver":
[
"sql = python_moondb.backends.sql:SQLConnector",
- "flat = python_moondb.backends.flat:LogConnector",
],
'console_scripts': [
'moon_db_manager = python_moondb.db_manager:run',