diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6be222c..5caf4ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,22 +21,12 @@ jobs: - '3.11' - '3.12' - services: - ldap: - image: osixia/openldap:latest - ports: - - 389:389 - env: - LDAP_SEED_INTERNAL_SCHEMA_PATH: "${CI_PROJECT_DIR}/misc/schema" - LDAP_DOMAIN: services.sram.tld - LDAP_ADMIN_USERNAME: admin - LDAP_ADMIN_PASSWORD: secret - LDAP_CONFIG_PASSWORD: config - LDAP_BASE_DN: dc=services,dc=sram,dc=tld - LDAP_TLS: true - steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + - name: Checkout + uses: actions/checkout@v4 + + - name: Start LDAP container + run: ./run-ldapci.sh - name: Install dependencies run: sudo apt-get update && sudo apt-get install -y libsasl2-dev libldap2-dev ldap-utils @@ -60,11 +50,12 @@ jobs: run: > sleep 5; ldapwhoami -H ${LDAP_URL} -D ${LDAP_BIND_DN} -w ${LDAP_ADMIN_PASSWORD}; + ldapwhoami -H ${LDAP_URL} -D cn=admin,cn=config -w ${LDAP_CONFIG_PASSWORD}; for f in access eduPerson voPerson groupOfMembers config; do - ldapadd -H ${LDAP_URL} - -D cn=admin,cn=config - -w ${LDAP_CONFIG_PASSWORD} + ldapadd -H ${LDAP_URL} \ + -D cn=admin,cn=config \ + -w ${LDAP_CONFIG_PASSWORD} \ -f etc/ldif/$f.ldif; done; env: @@ -95,5 +86,14 @@ jobs: LDAP_URL: ldap://localhost:389 LDAP_BASE_DN: dc=services,dc=sram,dc=tld + # Setup tmate session + - name: Setup tmate session + env: + ACTIONS_STEP_DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG}} + if: ${{ failure() && env.ACTIONS_STEP_DEBUG == 'true' }} + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: true + timeout-minutes: 60 diff --git a/misc/schema/sramPerson.ldif b/misc/schema/sramPerson.ldif index af7996b..e194381 100644 --- a/misc/schema/sramPerson.ldif +++ b/misc/schema/sramPerson.ldif @@ -1,39 +1,23 @@ # Internet X.500 Schema for Ldappc -# Includes the sczGroup ObjectClass schema +# Includes the sramPerson ObjectClass schema # -# An auxiliary object class, "sczGroup," is a convenient container -# for an extensible set of attributes concerning group memberships. +# An auxiliary object class, "sramPerson," is a convenient container +# for an extensible set of attributes concerning sram persons. # At this time, the only attribute specified as belonging to the -# object class is "sczMember." -# -# It is specifically configured to support the memberOf overlay. -# +# object class is "sramInactiveDays". # dn: cn=sramPerson,cn=schema,cn=config objectClass: olcSchemaConfig cn: sramPerson -olcAttributeTypes: ( 1.3.6.1.4.1.1076.20.100.20.2.1 NAME 'sramLastActivityDate' - DESC 'Date when this entity was last active' - EQUALITY generalizedTimeMatch - ORDERING generalizedTimeOrderingMatch - SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 - ) -olcAttributeTypes: ( 1.3.6.1.4.1.1076.20.100.20.2.2 NAME 'sramAUPacceptedURI' - DESC 'URI of accepted AUP' - EQUALITY caseExactMatch - SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 - ) -olcAttributeTypes: ( 1.3.6.1.4.1.1076.20.100.20.2.3 NAME 'sramAUPacceptedDate' - DESC 'Date when the AUP was accepted' - EQUALITY generalizedTimeMatch - ORDERING generalizedTimeOrderingMatch - SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 +olcAttributeTypes: ( 1.3.6.1.4.1.1076.20.100.20.2.1 NAME 'sramInactiveDays' + DESC 'Number of days this entity was inactive' + EQUALITY IntegerMatch + ORDERING IntegerOrderingMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 ) olcObjectClasses: ( 1.3.6.1.4.1.1076.20.100.20.1.1 NAME 'sramPerson' AUXILIARY MAY ( - sramLastActivityDate $ - sramAUPacceptedURI $ - sramAUPacceptedDate + sramInactiveDays ) ) diff --git a/plsc_ordered.py b/plsc_ordered.py index ff23629..dc52b52 100755 --- a/plsc_ordered.py +++ b/plsc_ordered.py @@ -100,7 +100,7 @@ def res(days, interval): # clean up the lists, such that we return empty lists if no attribute is present, rather than [None] for key, val in record.items(): - record[key] = list(filter(None, record[key])) + record[key] = list(filter(lambda n: n is not None, val)) rdn = f"uid={username}" diff --git a/run-ldapci.sh b/run-ldapci.sh new file mode 100755 index 0000000..7719590 --- /dev/null +++ b/run-ldapci.sh @@ -0,0 +1,14 @@ +#!/bin/sh +docker rm ldap || true +docker run -d \ + -e "LDAP_SEED_INTERNAL_SCHEMA_PATH=/opt/misc/schema" \ + -e "LDAP_DOMAIN=services.sram.tld" \ + -e "LDAP_ADMIN_USERNAME=admin" \ + -e "LDAP_ADMIN_PASSWORD=secret" \ + -e "LDAP_CONFIG_PASSWORD=config" \ + -e "LDAP_BASE_DN=dc=services,dc=sram,dc=tld" \ + -e "LDAP_TLS=true" \ + -v "./misc/schema:/opt/misc/schema" \ + -p 389:389 \ + --name ldap \ + osixia/openldap:latest