Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Lint
if: ${{ matrix.lint == 'true' }}
run: |
#pylint msal_extensions
pylint msal_extensions
# stop the build if there are Python syntax errors or undefined names
#flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
Expand Down
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
good-names=
logger
disable=
super-with-arguments, # For Python 2.x
raise-missing-from, # For Python 2.x
trailing-newlines,
useless-object-inheritance
18 changes: 13 additions & 5 deletions msal_extensions/cache_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import errno
import time
import logging

logger = logging.getLogger(__name__)
from distutils.version import LooseVersion
import warnings

import portalocker
from distutils.version import LooseVersion


logger = logging.getLogger(__name__)


class CrossPlatLock(object):
Expand All @@ -19,7 +21,8 @@ class CrossPlatLock(object):
def __init__(self, lockfile_path):
self._lockpath = lockfile_path
# Support for passing through arguments to the open syscall was added in v1.4.0
open_kwargs = {'buffering': 0} if LooseVersion(portalocker.__version__) >= LooseVersion("1.4.0") else {}
open_kwargs = ({'buffering': 0}
if LooseVersion(portalocker.__version__) >= LooseVersion("1.4.0") else {})
self._lock = portalocker.Lock(
lockfile_path,
mode='wb+',
Expand All @@ -31,6 +34,11 @@ def __init__(self, lockfile_path):
**open_kwargs)

def try_to_create_lock_file(self):
"""Do not call this. It will be removed in next release"""
warnings.warn("try_to_create_lock_file() will be removed", DeprecationWarning)
return self._try_to_create_lock_file()

def _try_to_create_lock_file(self):
timeout = 5
check_interval = 0.25
current_time = getattr(time, "monotonic", time.time)
Expand All @@ -48,7 +56,7 @@ def try_to_create_lock_file(self):
return False

def __enter__(self):
if not self.try_to_create_lock_file():
if not self._try_to_create_lock_file():
logger.warning("Failed to create lock file")
file_handle = self._lock.__enter__()
file_handle.write('{} {}'.format(os.getpid(), sys.argv[0]).encode('utf-8'))
Expand Down
7 changes: 4 additions & 3 deletions msal_extensions/libsecret.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
logger = logging.getLogger(__name__)

try:
import gi # https://github.com/AzureAD/microsoft-authentication-extensions-for-python/wiki/Encryption-on-Linux
import gi # https://github.com/AzureAD/microsoft-authentication-extensions-for-python/wiki/Encryption-on-Linux # pylint: disable=line-too-long
except ImportError:
logger.exception(
"""Runtime dependency of PyGObject is missing.
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__( # pylint: disable=too-many-arguments
label="", # Helpful when visualizing secrets by other viewers
attribute_types=None, # {name: SchemaAttributeType, ...}
collection=None, # None means default collection
): # pylint: disable=bad-continuation
):
"""This agent is built on top of lower level libsecret API.

Content stored via libsecret is associated with a bunch of attributes.
Expand Down Expand Up @@ -126,7 +126,8 @@ def trial_run():
agent.save(payload) # It would fail when running inside an SSH session
assert agent.load() == payload # This line is probably not reachable
agent.clear()
except (gi.repository.GLib.Error, AssertionError):
except (gi.repository.GLib.Error, AssertionError): # pylint: disable=no-member
# https://pygobject.readthedocs.io/en/latest/guide/api/error_handling.html#examples
message = """libsecret did not perform properly.
* If you encountered error "Remote error from secret service:
org.freedesktop.DBus.Error.ServiceUnknown",
Expand Down
2 changes: 1 addition & 1 deletion msal_extensions/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import ctypes as _ctypes

OS_RESULT = _ctypes.c_int32
OS_RESULT = _ctypes.c_int32 # pylint: disable=invalid-name


class KeychainError(OSError):
Expand Down
14 changes: 8 additions & 6 deletions msal_extensions/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys
try:
from pathlib import Path # Built-in in Python 3
except:
except ImportError:
from pathlib2 import Path # An extra lib for Python 2


Expand Down Expand Up @@ -59,10 +59,12 @@ class PersistenceNotFound(IOError): # Use IOError rather than OSError as base,
# https://github.com/AzureAD/microsoft-authentication-extensions-for-python/blob/0.2.2/msal_extensions/token_cache.py#L38
# Now we want to maintain backward compatibility even when using Python 2.x
# It makes no difference in Python 3.3+ where IOError is an alias of OSError.
def __init__(
self,
err_no=errno.ENOENT, message="Persistence not found", location=None):
super(PersistenceNotFound, self).__init__(err_no, message, location)
"""This happens when attempting BasePersistence.load() on a non-existent persistence instance"""
def __init__(self, err_no=None, message=None, location=None):
super(PersistenceNotFound, self).__init__(
err_no or errno.ENOENT,
message or "Persistence not found",
location)


class BasePersistence(ABC):
Expand Down Expand Up @@ -220,7 +222,7 @@ def load(self):
try:
return locker.get_generic_password(
self._service_name, self._account_name)
except self._KeychainError as ex:
except self._KeychainError as ex: # pylint: disable=invalid-name
if ex.exit_status == self._KeychainError.ITEM_NOT_FOUND:
# This happens when a load() is called before a save().
# We map it into cross-platform error for unified catching.
Expand Down