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

ci: bump ubuntu version, remove mockldap #2013

Merged
merged 29 commits into from
Apr 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
97 changes: 73 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ on:

jobs:
lint:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8]
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev
sudo apt-get install -y libldap2-dev libsasl2-dev libssl-dev
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
Expand All @@ -35,10 +35,10 @@ jobs:
run: mypy flask_appbuilder

test-postgres:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9.7]
python-version: ["3.7", "3.8", "3.9"]
env:
SQLALCHEMY_DATABASE_URI:
postgresql+psycopg2://pguser:pguserpassword@127.0.0.1:15432/app
Expand All @@ -52,15 +52,27 @@ jobs:
ports:
- 15432:5432
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run openldap
run: |
docker run -d \
-v '${{ github.workspace }}/docker/openldap/ldifs:/ldifs' \
-v '${{ github.workspace }}/docker/openldap/schemas/memberof.ldif:/opt/bitnami/openldap/etc/schema/memberof.ldif' \
-e LDAP_URI=ldap://openldap:1389 \
-e LDAP_BASE=dc=example,dc=org \
-e LDAP_ADMIN_USERNAME=admin \
-e LDAP_ADMIN_PASSWORD=admin_password \
-e LDAP_EXTRA_SCHEMAS=cosine,inetorgperson,nis,memberof \
-p 1389:1389 \
bitnami/openldap:2.6.4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev
sudo apt-get install -y libldap2-dev libsasl2-dev libssl-dev
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
Expand All @@ -73,10 +85,10 @@ jobs:
bash <(curl -s https://codecov.io/bash) -cF python

test-mysql:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.7]
python-version: [3.8]
env:
SQLALCHEMY_DATABASE_URI: |
mysql+mysqldb://mysqluser:mysqluserpassword@127.0.0.1:13306/app?charset=utf8mb4&binary_prefix=true
Expand All @@ -91,15 +103,27 @@ jobs:
ports:
- 13306:3306
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run openldap
run: |
docker run -d \
-v '${{ github.workspace }}/docker/openldap/ldifs:/ldifs' \
-v '${{ github.workspace }}/docker/openldap/schemas/memberof.ldif:/opt/bitnami/openldap/etc/schema/memberof.ldif' \
-e LDAP_URI=ldap://openldap:1389 \
-e LDAP_BASE=dc=example,dc=org \
-e LDAP_ADMIN_USERNAME=admin \
-e LDAP_ADMIN_PASSWORD=admin_password \
-e LDAP_EXTRA_SCHEMAS=cosine,inetorgperson,nis,memberof \
-p 1389:1389 \
bitnami/openldap:2.6.4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev
sudo apt-get install -y libldap2-dev libsasl2-dev libssl-dev
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
Expand All @@ -112,10 +136,10 @@ jobs:
bash <(curl -s https://codecov.io/bash) -cF python

test-mssql:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.7]
python-version: [3.8]
env:
SQLALCHEMY_DATABASE_URI: |
mssql+pyodbc://sa:Password_123@localhost:11433/master?driver=FreeTDS
Expand All @@ -128,15 +152,27 @@ jobs:
ports:
- 11433:1433
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run openldap
run: |
docker run -d \
-v '${{ github.workspace }}/docker/openldap/ldifs:/ldifs' \
-v '${{ github.workspace }}/docker/openldap/schemas/memberof.ldif:/opt/bitnami/openldap/etc/schema/memberof.ldif' \
-e LDAP_URI=ldap://openldap:1389 \
-e LDAP_BASE=dc=example,dc=org \
-e LDAP_ADMIN_USERNAME=admin \
-e LDAP_ADMIN_PASSWORD=admin_password \
-e LDAP_EXTRA_SCHEMAS=cosine,inetorgperson,nis,memberof \
-p 1389:1389 \
bitnami/openldap:2.6.4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev freetds-bin unixodbc-dev tdsodbc
sudo apt-get install -y libldap2-dev libsasl2-dev libssl-dev freetds-bin unixodbc-dev tdsodbc
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
Expand All @@ -150,29 +186,42 @@ jobs:
bash <(curl -s https://codecov.io/bash) -cF python

test-mongodb:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.7]
services:
mssql:
mongo:
image: mongo:4.4.1-bionic
ports:
- 27017:27017
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run openldap
run: |
docker run -d \
-v '${{ github.workspace }}/docker/openldap/ldifs:/ldifs' \
-v '${{ github.workspace }}/docker/openldap/schemas/memberof.ldif:/opt/bitnami/openldap/etc/schema/memberof.ldif' \
-e LDAP_URI=ldap://openldap:1389 \
-e LDAP_BASE=dc=example,dc=org \
-e LDAP_ADMIN_USERNAME=admin \
-e LDAP_ADMIN_PASSWORD=admin_password \
-e LDAP_EXTRA_SCHEMAS=cosine,inetorgperson,nis,memberof \
-p 1389:1389 \
bitnami/openldap:2.6.4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev
sudo apt-get install -y libldap2-dev libsasl2-dev libssl-dev
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -r requirements-extra.txt
pip install -r requirements-mongodb.txt
- name: Run tests
run: |
nosetests --stop -v --with-coverage --cover-package=flask_appbuilder flask_appbuilder/tests/test_mongoengine.py
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ services:
MONGO_INITDB_DATABASE: app
ports:
- 27017:27017
ldap:
container_name: fab-ldap
image: bitnami/openldap:2.6.4
environment:
LDAP_URI: ldap://openldap:1389
LDAP_BASE: dc=example,dc=org
LDAP_ADMIN_USERNAME: admin
LDAP_ADMIN_PASSWORD: admin_password
LDAP_CUSTOM_LDIF_DIR: /ldifs
LDAP_EXTRA_SCHEMAS: cosine,inetorgperson,nis,memberof
volumes:
- './docker/openldap/ldifs:/ldifs'
- './docker/openldap/schemas/memberof.ldif:/opt/bitnami/openldap/etc/schema/memberof.ldif'
ports:
- 1389:1389
68 changes: 68 additions & 0 deletions docker/openldap/ldifs/users.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=org> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# example.org
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
dc: example
o: example

# users, example.org
dn: ou=users,dc=example,dc=org
objectClass: organizationalUnit
ou: users

# users, example.org
dn: ou=groups,dc=example,dc=org
objectClass: organizationalUnit
ou: groups

# alice, users, example.org
dn: cn=alice,ou=users,dc=example,dc=org
cn: alice
sn: Doe
givenName: Alice
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword: alice_password
uid: alice
uidNumber: 1000
gidNumber: 1000
mail: alice@example.org
homeDirectory: /home/alice

# natalie, users, example.org
dn: cn=natalie,ou=users,dc=example,dc=org
cn: natalie
sn: Smith
givenName: Natalie
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
userPassword: natalie_password
uid: natalie
uidNumber: 1001
gidNumber: 1001
mail: natalie@example.org
homeDirectory: /home/natalie

# readers, users, example.org
dn: cn=readers,ou=groups,dc=example,dc=org
cn: readers
objectClass: groupOfNames
objectClass: top
member: cn=alice,ou=users,dc=example,dc=org
member: cn=natalie,ou=users,dc=example,dc=org

dn: cn=staff,ou=groups,dc=example,dc=org
cn: staff
objectClass: groupOfNames
objectClass: top
member: cn=alice,ou=users,dc=example,dc=org
19 changes: 19 additions & 0 deletions docker/openldap/schemas/memberof.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
dn: cn=module,cn=config
cn: module
objectClass: olcModuleList
olcModulePath: /opt/bitnami/openldap/lib/openldap
olcModuleLoad: memberof.so
olcModuleLoad: refint.so

dn: olcOverlay=memberof,olcDatabase={2}mdb,cn=config
objectClass: olcMemberOf
objectClass: olcOverlayConfig
olcOverlay: memberof

dn: olcOverlay=refint,olcDatabase={2}mdb,cn=config
objectClass: olcConfig
objectClass: olcOverlayConfig
objectClass: olcRefintConfig
objectClass: top
olcOverlay: refint
olcRefintAttribute: memberof member manager owner
34 changes: 23 additions & 11 deletions flask_appbuilder/models/sqla/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

def get_field_setup_query(query, model, column_name):
"""
Help function for SQLA filters, checks for dot notation on column names.
If it exists, will join the query with the model
from the first part of the field name.
Help function for SQLA filters, checks for dot notation on column names.
If it exists, will join the query with the model
from the first part of the field name.

example:
Contact.created_by: if created_by is a User model,
it will be joined to the query.
example:
Contact.created_by: if created_by is a User model,
it will be joined to the query.
"""
if not hasattr(model, column_name):
# it's an inner obj attr
Expand Down Expand Up @@ -195,7 +195,11 @@
logging.warning(
"Filter exception for %s with value %s, will not apply", field, value
)
self.datamodel.session.rollback()
try:
self.datamodel.session.rollback()
except SQLAlchemyError:

Check warning on line 200 in flask_appbuilder/models/sqla/filters.py

View check run for this annotation

Codecov / codecov/patch

flask_appbuilder/models/sqla/filters.py#L200

Added line #L200 was not covered by tests
# on MSSQL a rollback would fail here
pass

Check warning on line 202 in flask_appbuilder/models/sqla/filters.py

View check run for this annotation

Codecov / codecov/patch

flask_appbuilder/models/sqla/filters.py#L202

Added line #L202 was not covered by tests
raise ApplyFilterException(exception=exc)
return query.filter(field == rel_obj)

Expand All @@ -212,7 +216,11 @@
logging.warning(
"Filter exception for %s with value %s, will not apply", field, value
)
self.datamodel.session.rollback()
try:
self.datamodel.session.rollback()
except SQLAlchemyError:

Check warning on line 221 in flask_appbuilder/models/sqla/filters.py

View check run for this annotation

Codecov / codecov/patch

flask_appbuilder/models/sqla/filters.py#L221

Added line #L221 was not covered by tests
# on MSSQL a rollback would fail here
pass

Check warning on line 223 in flask_appbuilder/models/sqla/filters.py

View check run for this annotation

Codecov / codecov/patch

flask_appbuilder/models/sqla/filters.py#L223

Added line #L223 was not covered by tests
raise ApplyFilterException(exception=exc)
return query.filter(field != rel_obj)

Expand All @@ -234,7 +242,11 @@
field,
value_item,
)
self.datamodel.session.rollback()
try:
self.datamodel.session.rollback()
except SQLAlchemyError:

Check warning on line 247 in flask_appbuilder/models/sqla/filters.py

View check run for this annotation

Codecov / codecov/patch

flask_appbuilder/models/sqla/filters.py#L247

Added line #L247 was not covered by tests
# on MSSQL a rollback would fail here
pass

Check warning on line 249 in flask_appbuilder/models/sqla/filters.py

View check run for this annotation

Codecov / codecov/patch

flask_appbuilder/models/sqla/filters.py#L249

Added line #L249 was not covered by tests
raise ApplyFilterException(exception=exc)

if rel_obj:
Expand Down Expand Up @@ -279,8 +291,8 @@

class SQLAFilterConverter(BaseFilterConverter):
"""
Class for converting columns into a supported list of filters
specific for SQLAlchemy.
Class for converting columns into a supported list of filters
specific for SQLAlchemy.

"""

Expand Down