Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSAL Extensions for Python, Release 1.1.0 #124

Merged
merged 8 commits into from
Dec 12, 2023
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
38 changes: 27 additions & 11 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ jobs:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, 2.7]
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, 3.12]
os: [ubuntu-latest, windows-latest, macos-latest]
include:
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-environment-variables-in-a-matrix
Expand All @@ -26,15 +27,19 @@ jobs:
toxenv: "py38"
- python-version: 3.9
toxenv: "py39"
- python-version: 2.7
toxenv: "py27"
- python-version: "3.10"
toxenv: "py310"
- python-version: 3.11
toxenv: "py311"
- python-version: 3.12
toxenv: "py312"
- python-version: 3.9
os: ubuntu-latest
lint: "true"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Linux dependencies for Python 2
Expand Down Expand Up @@ -81,26 +86,37 @@ jobs:

cd:
needs: ci
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || github.ref == 'refs/heads/master')
# Note: github.event.pull_request.draft == false WON'T WORK in "if" statement,
# because the triggered event is a push, not a pull_request.
# This means each commit will trigger a release on TestPyPI.
# Those releases will only succeed when each push has a new version number: a1, a2, a3, etc.
if: |
github.event_name == 'push' &&
(
startsWith(github.ref, 'refs/tags') ||
startsWith(github.ref, 'refs/heads/release-')
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Build a package for release
run: |
python -m pip install build --user
python -m build --sdist --wheel --outdir dist/ .
- name: Publish to TestPyPI
- name: |
Publish to TestPyPI when pushing to release-* branch.
You better test with a1, a2, b1, b2 releases first.
uses: pypa/[email protected]
if: github.ref == 'refs/heads/master'
if: startsWith(github.ref, 'refs/heads/release-')
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish to PyPI
- name: Publish to PyPI when tagged
if: startsWith(github.ref, 'refs/tags')
uses: pypa/[email protected]
with:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO: Can this Dockerfile use multi-stage build?
# Final size 690MB. (It would be 1.16 GB if started with python:3 as base)
FROM python:3-slim
FROM python:3.12-slim

# Install Generic PyGObject (sans GTK)
#The following somehow won't work:
Expand All @@ -22,7 +22,7 @@ RUN apt-get install -y \
RUN pip install "pytest>=6,<7"

# Install MSAL Extensions. Upgrade the pinned version number to trigger a new image build.
RUN pip install "msal-extensions==0.3"
RUN pip install "msal-extensions==1.1"

# This setup is inspired from https://github.com/jaraco/keyring#using-keyring-on-headless-linux-systems-in-a-docker-container
ENTRYPOINT ["dbus-run-session", "--"]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ persistence.save(json.dumps(data))
assert json.loads(persistence.load()) == data
```

## Python version support policy

Python versions which are 6 months older than their
[end-of-life cycle defined by Python Software Foundation (PSF)](https://devguide.python.org/versions/#versions)
will not receive new feature updates from this library.


## Community Help and Support

Expand Down
2 changes: 1 addition & 1 deletion msal_extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Provides auxiliary functionality to the `msal` package."""
__version__ = "1.0.0"
__version__ = "1.1.0"

from .persistence import (
FilePersistence,
Expand Down
4 changes: 2 additions & 2 deletions msal_extensions/cache_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import errno
import time
import logging
from distutils.version import LooseVersion

import portalocker
from packaging.version import Version


logger = logging.getLogger(__name__)
Expand All @@ -21,7 +21,7 @@ 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 {})
if Version(portalocker.__version__) >= Version("1.4.0") else {})
self._lock = portalocker.Lock(
lockfile_path,
mode='wb+',
Expand Down
5 changes: 2 additions & 3 deletions msal_extensions/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def save(self, content):
except OSError as exception:
raise PersistenceEncryptionError(
err_no=getattr(exception, "winerror", None), # Exists in Python 3 on Windows
message="Encryption failed: {}. Consider disable encryption.".format(exception),
message="Encryption failed: {} Consider disable encryption.".format(exception),
)
with os.fdopen(_open(self._location), 'wb+') as handle:
handle.write(data)
Expand All @@ -237,7 +237,7 @@ def load(self):
except OSError as exception:
raise PersistenceDecryptionError(
err_no=getattr(exception, "winerror", None), # Exists in Python 3 on Windows
message="Decryption failed: {}. "
message="Decryption failed: {} "
"App developer may consider this guidance: "
"https://github.com/AzureAD/microsoft-authentication-extensions-for-python/wiki/PersistenceDecryptionError" # pylint: disable=line-too-long
.format(exception),
Expand Down Expand Up @@ -342,4 +342,3 @@ def get_location(self):
# with a FilePersistence to achieve
# https://github.com/AzureAD/microsoft-authentication-extensions-for-python/issues/12
# But this idea is not pursued at this time.

6 changes: 3 additions & 3 deletions msal_extensions/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def raw(self):
"The computer must be trusted for delegation and "
"the current user account must be configured to allow delegation. "
"See also https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/enable-computer-and-user-accounts-to-be-trusted-for-delegation",
13: "The data is invalid",
13: "The data is invalid.",
}

# This code is modeled from a StackOverflow question, which can be found here:
Expand Down Expand Up @@ -91,7 +91,7 @@ def protect(self, message):
_LOCAL_FREE(result.pbData)

err_code = _GET_LAST_ERROR()
raise OSError(None, _err_description.get(err_code), None, err_code)
raise OSError(None, _err_description.get(err_code, ''), None, err_code)

def unprotect(self, cipher_text):
# type: (bytes) -> str
Expand Down Expand Up @@ -120,4 +120,4 @@ def unprotect(self, cipher_text):
finally:
_LOCAL_FREE(result.pbData)
err_code = _GET_LAST_ERROR()
raise OSError(None, _err_description.get(err_code), None, err_code)
raise OSError(None, _err_description.get(err_code, ''), None, err_code)
13 changes: 11 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# https://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files

[bdist_wheel]
universal=1
universal=0

[metadata]
license = MIT
license = MIT License
project_urls = Changelog = https://github.com/AzureAD/microsoft-authentication-extensions-for-python/releases
classifiers =
License :: OSI Approved :: MIT License
Development Status :: 5 - Production/Stable
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12

description = Microsoft Authentication Library extensions (MSAL EX) provides a persistence API that can save your data on disk, encrypted on Windows, macOS and Linux. Concurrent data access will be coordinated by a file lock mechanism.
18 changes: 8 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@
long_description=long_description,
long_description_content_type="text/markdown",
package_data={'': ['LICENSE']},
python_requires=">=3.7",
install_requires=[
'msal>=0.4.1,<2.0.0',

# In order to implement these requirements:
# Lowerbound = (1.6 if playform_system == 'Windows' else 1.0)
# Upperbound < (3 if python_version >= '3.5' else 2)
# The following 4 lines use the `and` syntax defined here:
# https://www.python.org/dev/peps/pep-0508/#grammar
"portalocker<3,>=1.0;python_version>='3.5' and platform_system!='Windows'",
"portalocker<2,>=1.0;python_version=='2.7' and platform_system!='Windows'",
"portalocker<3,>=1.6;python_version>='3.5' and platform_system=='Windows'",
"portalocker<2,>=1.6;python_version=='2.7' and platform_system=='Windows'",
"portalocker<3,>=1.0;platform_system!='Windows'",
"portalocker<3,>=1.6;platform_system=='Windows'",

"pathlib2;python_version<'3.0'",
## We choose to NOT define a hard dependency on this.
# "pygobject>=3,<4;platform_system=='Linux'",

# Packaging package uses YY.N versioning so we have no upperbound to pin.
# Neither do we need lowerbound because its `Version` API existed since its first release
# https://github.com/pypa/packaging/blame/14.0/packaging/version.py
'packaging',
],
tests_require=['pytest'],
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py35,py36,py37,py38
envlist = py27,py35,py36,py37,py38,py39,py310,py311,py312

[testenv]
deps = pytest
Expand Down