diff --git a/async_tests/test_async_ldap_client.py b/async_tests/test_async_ldap_client.py index 33615fe..b97c9b8 100644 --- a/async_tests/test_async_ldap_client.py +++ b/async_tests/test_async_ldap_client.py @@ -13,7 +13,6 @@ from phi.async_ldap.client import ( AsyncClient, ) - BASE_DN = "dc=unit,dc=macaomilano,dc=org" diff --git a/src/phi/api/utils.py b/src/phi/api/utils.py index a71bfca..43ee8e4 100644 --- a/src/phi/api/utils.py +++ b/src/phi/api/utils.py @@ -1,6 +1,8 @@ from datetime import datetime -def serialize(d): - return {k: (v.isoformat() if isinstance(v, datetime) else v) - for k, v in d.items()} +def serialize(obj): + return { + k: (v.isoformat() if isinstance(v, datetime) else v) + for k, v in dict(obj).items() + } diff --git a/src/phi/app.py b/src/phi/app.py index ac4241f..f26ff27 100644 --- a/src/phi/app.py +++ b/src/phi/app.py @@ -125,11 +125,7 @@ def _validate_port(ctx, param, value): help="Path to a yaml configuration for the logger.", ) @click.option( - "--debug", - "debug", - is_flag=True, - default=False, - help="Set the log level to debug.", + "--debug", "debug", is_flag=True, default=False, help="Set the log level to debug.", ) def cli( host, @@ -204,8 +200,8 @@ def prepare_config_from_cli( } _logging = {} if log_conf: - with open(log_conf) as l: - _logging = yaml.safe_load(l) + with open(log_conf) as log_conf_fd: + _logging = yaml.safe_load(log_conf_fd) return {"core": _core, "ldap": _ldap, "logging": _logging} diff --git a/src/phi/async_ldap/model.py b/src/phi/async_ldap/model.py index 33b2388..68c350b 100644 --- a/src/phi/async_ldap/model.py +++ b/src/phi/async_ldap/model.py @@ -309,9 +309,7 @@ class User(Hackers): try: await self.modify("userPassword", hash_pass(new_pass)) except PhiAttributeMissing: - raise PhiUnauthorized( - user=self.client.username, - ) + raise PhiUnauthorized(user=self.client.username,) alog.info("User(%s): password modified", self.name) async def verify_password(self, given_pass): @@ -322,9 +320,7 @@ class User(Hackers): try: match_pass = res[0]["userPassword"][0] == hash_pass(given_pass) except KeyError: - raise PhiUnauthorized( - user=self.client.username, - ) + raise PhiUnauthorized(user=self.client.username,) return match_pass diff --git a/src/phi/config.py b/src/phi/config.py index b1d1acb..5d939ae 100644 --- a/src/phi/config.py +++ b/src/phi/config.py @@ -2,16 +2,10 @@ import os.path import pkg_resources import yaml - -NAME = 'phi' +NAME = "phi" DEFAULT_CONFIG = { - "core": { - "listen": { - "host": "localhost", - "port": 8080, - } - }, + "core": {"listen": {"host": "localhost", "port": 8080}}, "ldap": { "host": "localhost", "port": 389, @@ -27,9 +21,7 @@ DEFAULT_CONFIG = { }, "logging": { "version": 1, - "formatters": { - "default": {"format": "[%(name)s %(levelname)s] %(message)s"} - }, + "formatters": {"default": {"format": "[%(name)s %(levelname)s] %(message)s"}}, "handlers": { "console": { "class": "logging.StreamHandler", @@ -40,34 +32,26 @@ DEFAULT_CONFIG = { "class": "logging.FileHandler", "formatter": "default", "filename": "phi.log", - } + }, }, "loggers": { - "phi": { - "level": "INFO", - "handlers": ["console", "file"], - }, - "aiohttp": { - "level": "INFO", - "handlers": ["console", "file"], - }, - "ldap3": { - "level": "WARNING", - "handlers": ["console", "file"], - } - } - } + "phi": {"level": "INFO", "handlers": ["console", "file"],}, + "aiohttp": {"level": "INFO", "handlers": ["console", "file"],}, + "ldap3": {"level": "WARNING", "handlers": ["console", "file"],}, + }, + }, } DUMMY_CONFIG = {"core": {}, "ldap": {}, "logging": {}} -CONFIG_FILE = 'config.yml' -CONFIG_PATHS = ['./', - '~/.config/' + NAME + '/', - '/usr/local/etc/' + NAME + '/', - '/etc/' + NAME + '/'] -CONFIG_FILES = [os.path.join(p, CONFIG_FILE) - for p in CONFIG_PATHS] +CONFIG_FILE = "config.yml" +CONFIG_PATHS = [ + "./", + "~/.config/" + NAME + "/", + "/usr/local/etc/" + NAME + "/", + "/etc/" + NAME + "/", +] +CONFIG_FILES = [os.path.join(p, CONFIG_FILE) for p in CONFIG_PATHS] def get_config(config_path=None): @@ -84,7 +68,7 @@ def get_config(config_path=None): return config_path, config for f in CONFIG_FILES: try: - with open(f, 'r') as c: + with open(f, "r") as c: config = yaml.safe_load(c) return (f, config) except FileNotFoundError: diff --git a/src/phi/ldap/user.py b/src/phi/ldap/user.py index 29e2e5a..247a1bf 100644 --- a/src/phi/ldap/user.py +++ b/src/phi/ldap/user.py @@ -4,10 +4,10 @@ from phi.ldap.utils import flatten_attributes def user_attributes_mapping(client): return { - client.attribute_id: 'uid', - client.attribute_mail: 'mail', - 'createTimestamp': 'created_at', - 'modifyTimestamp': 'modified_at' + client.attribute_id: "uid", + client.attribute_mail: "mail", + "createTimestamp": "created_at", + "modifyTimestamp": "modified_at", } @@ -19,8 +19,8 @@ def get_user_by_uid(client, uid): mapping = user_attributes_mapping(client) - user = {mapping[k]: v - for k, v in entry['attributes'].items() - if k in mapping.keys()} + user = { + mapping[k]: v for k, v in entry["attributes"].items() if k in mapping.keys() + } return flatten_attributes(user)