From 61c689f6aad04cb4bd95699a5543ed8c73d34a88 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 18:52:59 -0500 Subject: [PATCH 01/10] delete unused circleci files --- .circle/circlerc.sh | 21 -------------------- .circle/env | 3 --- .circle/helpers.sh | 48 --------------------------------------------- 3 files changed, 72 deletions(-) delete mode 100755 .circle/circlerc.sh delete mode 100644 .circle/env delete mode 100644 .circle/helpers.sh diff --git a/.circle/circlerc.sh b/.circle/circlerc.sh deleted file mode 100755 index 0a0eb44..0000000 --- a/.circle/circlerc.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -## Circle CI command exection extension script. -# We inject can inject additional logic such as env and - -## Source our extentions into ~/.circlerc, if we -# haven't done so yet. -if [ -z "$extCIRCLE_DIR" ]; then - path=$(readlink -f $0) - dir=$(dirname $path) - echo "export extCIRCLE_DIR=${dir}" >> ~/.circlerc - echo ". ${dir}/circlerc.sh" >> ~/.circlerc - exit 0 -fi - -pushd $extCIRCLE_DIR >/dev/null - -# Source our extensions during a command invocation - . ./env - . ./helpers.sh - -popd >/dev/null diff --git a/.circle/env b/.circle/env deleted file mode 100644 index 47b503c..0000000 --- a/.circle/env +++ /dev/null @@ -1,3 +0,0 @@ -# Environment settings if required, also circle.yml can be used for this. -# This file will be sourced when invocation is handled by run wrapper. -#VAR=value diff --git a/.circle/helpers.sh b/.circle/helpers.sh deleted file mode 100644 index 181c5fe..0000000 --- a/.circle/helpers.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -## Execute command on a circle node -# 1) On the node when circle node == current step -# 2) On the given node when the first argument is number. -# -step() { - if [ $1 -ge 0 ] 2>/dev/null; then - # execute step only on the given node - node_num=$1; shift - else - # execute step on the current node - node_num=${extCIRCLE_STEPNUM:=0} - export extCIRCLE_STEPNUM - fi - - # Early step fail, because step is a part of composed command, - # further execution doesn't make sense. - set -e - - if [ $node_num = $CIRCLE_NODE_INDEX ]; then - # Execute command (which is all args passed to the function) - echo -e "\nExecuting command: \`$@' ==>" - $@ - fi -} - -## Switch command execution to the next circle node. -# We can switch to the next node or directly to the specific node -# if the first argument is number. -next() { - if [ -z "$1" ]; then - step_num=${extCIRCLE_STEPNUM:-0} - step_num=$((step_num+1)) - else - step_num=$1 - fi - export extCIRCLE_STEPNUM=$step_num -} - -## Make an export line for the given variables in ~/.circlerc -# -circlerc_env() { - for e in $@; do - eval "value=\$$e" - echo "export ${e}=${value}" >> ~/.circlerc - done -} From 8dbeea0091cd3173d1581cbccb5705c008fe65d5 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 19:47:51 -0500 Subject: [PATCH 02/10] sync test reqs w/ st2.git --- lint-configs/python/.pylintrc | 7 +------ test-requirements.txt | 5 ++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lint-configs/python/.pylintrc b/lint-configs/python/.pylintrc index e25a0f7..566c03d 100644 --- a/lint-configs/python/.pylintrc +++ b/lint-configs/python/.pylintrc @@ -1,14 +1,9 @@ [MESSAGES CONTROL] # C0111 Missing docstring # I0011 Warning locally suppressed using disable-msg -# I0012 Warning locally suppressed using disable-msg -# W0704 Except doesn't do anything Used when an except clause does nothing but "pass" and there is no "else" clause -# W0142 Used * or * magic* Used when a function or method is called using *args or **kwargs to dispatch arguments. # W0212 Access to a protected member %s of a client class -# W0232 Class has no __init__ method Used when a class has no __init__ method, neither its parent classes. # W0613 Unused argument %r Used when a function or method argument is not used. # W0702 No exception's type specified Used when an except clause doesn't specify exceptions type to catch. -# R0201 Method could be a function # W0614 Unused import XYZ from wildcard import # R0914 Too many local variables # R0912 Too many branches @@ -18,7 +13,7 @@ # E0211: Method has no argument # E1128: Assigning to function call which only returns None Used when an assignment is done on a function call but the inferred function returns nothing but None. # E1129: Context manager ‘%s’ doesn’t implement __enter__ and __exit__. Used when an instance in a with statement doesn’t implement the context manager protocol(__enter__/__exit__). -disable=C0103,C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201,W0614,R0914,R0912,R0915,R0913,R0904,R0801,not-context-manager,assignment-from-none +disable=C0103,C0111,I0011,W0212,W0613,W0702,W0614,R0914,R0912,R0915,R0913,R0904,R0801,not-context-manager,assignment-from-none [TYPECHECK] # Note: This modules are manipulated during the runtime so we can't detect all the properties during diff --git a/test-requirements.txt b/test-requirements.txt index de935ce..beb43e5 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,11 +1,10 @@ unittest2 tox -mock>=1.0 +mock==5.1.0 flake8 st2flake8==0.1.0 nose>=1.3.7 -isort>=4.2.5,<5 -pylint==2.6.0 +pylint~=3.1.0 pylint-plugin-utils>=0.4 coverage -e git+https://github.com/StackStorm/st2-auth-backend-flat-file.git@master#egg=st2-auth-backend-flat-file From efacef8164701a09e92e8310d28cf616bad632f0 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 19:53:35 -0500 Subject: [PATCH 03/10] unpin st2flake8 test dep and pin flake8 and start sorting reqs --- test-requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index beb43e5..fd38024 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,10 +1,10 @@ unittest2 -tox +coverage +flake8==7.0.0 mock==5.1.0 -flake8 -st2flake8==0.1.0 nose>=1.3.7 pylint~=3.1.0 pylint-plugin-utils>=0.4 -coverage -e git+https://github.com/StackStorm/st2-auth-backend-flat-file.git@master#egg=st2-auth-backend-flat-file +st2flake8 +tox From ee2cd78eb9ea482038b70e330897cdedc921f2c1 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 19:56:49 -0500 Subject: [PATCH 04/10] test dep on released st2-auth-backend-flat-file not git --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index fd38024..b8ef192 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,6 +5,6 @@ mock==5.1.0 nose>=1.3.7 pylint~=3.1.0 pylint-plugin-utils>=0.4 --e git+https://github.com/StackStorm/st2-auth-backend-flat-file.git@master#egg=st2-auth-backend-flat-file +st2-auth-backend-flat-file st2flake8 tox From 2778c6d15a71642bff6593fd195743d07e97f53c Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 19:59:11 -0500 Subject: [PATCH 05/10] drop unittest2 backport lib --- test-requirements.txt | 1 - tests/integration/test_active_directory.py | 4 ++-- tests/integration/test_openldap.py | 4 ++-- tests/unit/test_backend.py | 4 ++-- tests/unit/test_config.py | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index b8ef192..a17d4a2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,3 @@ -unittest2 coverage flake8==7.0.0 mock==5.1.0 diff --git a/tests/integration/test_active_directory.py b/tests/integration/test_active_directory.py index 85c4cc7..3fe1a49 100644 --- a/tests/integration/test_active_directory.py +++ b/tests/integration/test_active_directory.py @@ -14,12 +14,12 @@ # limitations under the License. import os -import unittest2 +import unittest from st2auth_ldap import ldap_backend -class ActiveDirectoryAuthenticationTest(unittest2.TestCase): +class ActiveDirectoryAuthenticationTest(unittest.TestCase): @classmethod def setUpClass(cls): diff --git a/tests/integration/test_openldap.py b/tests/integration/test_openldap.py index b79408e..5f45d61 100644 --- a/tests/integration/test_openldap.py +++ b/tests/integration/test_openldap.py @@ -14,12 +14,12 @@ # limitations under the License. import os -import unittest2 +import unittest from st2auth_ldap import ldap_backend -class OpenLDAPAuthenticationTest(unittest2.TestCase): +class OpenLDAPAuthenticationTest(unittest.TestCase): @classmethod def setUpClass(cls): diff --git a/tests/unit/test_backend.py b/tests/unit/test_backend.py index 9a3be49..e0e997d 100644 --- a/tests/unit/test_backend.py +++ b/tests/unit/test_backend.py @@ -19,7 +19,7 @@ import ldap import mock -import unittest2 +import unittest from st2auth_ldap import ldap_backend @@ -82,7 +82,7 @@ ] -class LDAPBackendTest(unittest2.TestCase): +class LDAPBackendTest(unittest.TestCase): def test_instantaite_no_group_dns_provided(self): # User is member of two of the groups, but none of them are required diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 920489c..597d088 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -16,7 +16,7 @@ import ldap import os import mock -import unittest2 +import unittest import uuid from st2auth_ldap import ldap_backend @@ -36,7 +36,7 @@ LDAP_USER_BAD_PASSWD = 'snow1234' -class LDAPBackendConfigurationTest(unittest2.TestCase): +class LDAPBackendConfigurationTest(unittest.TestCase): def test_null_bind_dn(self): self.assertRaises( From 0c0174c480d6e1c9e49835c7fcd07268d7904e8f Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 20:00:40 -0500 Subject: [PATCH 06/10] add description for pypi --- setup.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.py b/setup.py index 6319f82..d78f856 100644 --- a/setup.py +++ b/setup.py @@ -27,10 +27,15 @@ version = parse_version_string(INIT_FILE) install_reqs, dep_links = fetch_requirements(REQUIREMENTS_FILE) +with open("README.md", "r") as fh: + long_description = fh.read() + setup( name='st2-auth-ldap', version=version, description='StackStorm authentication backend for LDAP.', + long_description=long_description, + long_description_content_type="text/markdown", author='StackStorm, Inc.', author_email='info@stackstorm.com', url='https://stackstorm.com/', From ef8c891835c464ab68f01b665ede44c75258de60 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 20:02:49 -0500 Subject: [PATCH 07/10] switch from nose to pytest --- Makefile | 2 +- setup.py | 1 - test-requirements.txt | 2 +- tox.ini | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index cec59fb..d760ea1 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ unit-tests: requirements .clone_st2_repo .unit-tests echo "==========================================================="; \ echo "Running unit tests"; \ echo "==========================================================="; \ - . $(VIRTUALENV_DIR)/bin/activate; nosetests $(NOSE_OPTS) -s -v tests/unit || exit 1; \ + . $(VIRTUALENV_DIR)/bin/activate; pytest tests/unit || exit 1; \ .PHONY: .clone_st2_repo .clone_st2_repo: diff --git a/setup.py b/setup.py index d78f856..91bc1bd 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,6 @@ include_package_data=True, install_requires=install_reqs, dependency_links=dep_links, - test_suite='tests', entry_points={ 'st2auth.backends.backend': [ 'ldap = st2auth_ldap.ldap_backend:LDAPAuthenticationBackend', diff --git a/test-requirements.txt b/test-requirements.txt index a17d4a2..c097936 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,9 +1,9 @@ coverage flake8==7.0.0 mock==5.1.0 -nose>=1.3.7 pylint~=3.1.0 pylint-plugin-utils>=0.4 +pytest st2-auth-backend-flat-file st2flake8 tox diff --git a/tox.ini b/tox.ini index 8cb7d31..3731163 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = py38,py39,py310,py311,lint [testenv] deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt -commands = nosetests -sv tests/unit +commands = pytest tests/unit [testenv:lint] commands = flake8 --config ./lint-configs/python/.flake8 st2auth_ldap/ From f94031cf4a387ac34265f02f6629b7ef8e62ce4d Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 20:04:00 -0500 Subject: [PATCH 08/10] GHA: add merge_ok bits from other st2-auth repos --- .github/workflows/lint-and-unit-tests.yml | 40 ++++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint-and-unit-tests.yml b/.github/workflows/lint-and-unit-tests.yml index ab64d41..99f3a45 100644 --- a/.github/workflows/lint-and-unit-tests.yml +++ b/.github/workflows/lint-and-unit-tests.yml @@ -16,17 +16,19 @@ jobs: strategy: fail-fast: false matrix: - version: + python-version: - "3.8" - "3.9" - "3.10" - "3.11" steps: - - uses: actions/checkout@v3 + - name: Checkout repo + uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - name: Setup Python + uses: actions/setup-python@v5 with: - python-version: ${{ matrix.version }} + python-version: ${{ matrix.python-version }} - name: Clone StackStorm/st2 repo run: | @@ -39,8 +41,36 @@ jobs: sudo apt-get -y install python3-virtualenv make requirements - - name: Run lint and tests (Python ${{ matrix.version }}) + - name: Run lint and tests (Python ${{ matrix.python-version }}) run: | make .lint make .unit-tests + set_merge_ok: + name: Set Merge OK + if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') + needs: + - build-and-test-python + outputs: + merge_ok: ${{ steps.set_merge_ok.outputs.merge_ok }} + runs-on: ubuntu-latest + steps: + - id: set_merge_ok + run: echo 'merge_ok=true' >> ${GITHUB_OUTPUT} + + merge_ok: + name: Merge OK + if: always() + needs: + - set_merge_ok + runs-on: ubuntu-latest + steps: + - run: | + merge_ok="${{ needs.set_merge_ok.outputs.merge_ok }}" + if [[ "${merge_ok}" == "true" ]]; then + echo "Merge OK" + exit 0 + else + echo "Merge NOT OK" + exit 1 + fi From bb933d5728f4b3f82938d8698bdfa2f37cb4ad0c Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 20:04:37 -0500 Subject: [PATCH 09/10] add python_requires to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 91bc1bd..3cee0a2 100644 --- a/setup.py +++ b/setup.py @@ -51,6 +51,7 @@ "Programming Language :: Python :: 3.11", 'Environment :: Console', ], + python_requires='>=3.8', platforms=['Any'], scripts=[], provides=['st2auth_ldap'], From 3467a4fed1b35c066cc96091b71ef8c7efe4612f Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 20 Oct 2024 21:00:35 -0500 Subject: [PATCH 10/10] force using newer st2flake8 It was using the one from st2.git which has not been updated yet. --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index c097936..a37080f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,5 +5,5 @@ pylint~=3.1.0 pylint-plugin-utils>=0.4 pytest st2-auth-backend-flat-file -st2flake8 +st2flake8>0.1 tox