Skip to content

Commit

Permalink
User expiry script added
Browse files Browse the repository at this point in the history
  • Loading branch information
IjazMoJ committed Feb 27, 2024
1 parent 604a5a9 commit 843fc57
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions cli/ldap_cmds/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,56 @@ def deactivate_crc_users(
except:
log.exception(f"Failed to update END_DATE for user {user_dn}")
connection.close()

def user_expiry():
date_str = f"{datetime.now().strftime("%Y%m%d")}000000Z"
ldap_connection_lock = ldap_connect(
env.vars.get("LDAP_HOST"),
env.vars.get("LDAP_USER"),
env.secrets.get("LDAP_BIND_PASSWORD"),
)
ldap_connection_lock.search(
",".join([
user_ou,
root_dn,
]
),
f"(&(!(pwdAccountLockedTime=*))(|(&(endDate=*)(!(endDate>=${date_str})))(&(startDate=*)(!(startDate<=${date_str})))))" )
found_users = [entry.entry_dn for entry in ldap_connection_lock.entries]
for user in found_users:
ldap_connection_lock.modify(
user,
{
"pwdAccountLockedTime": [
(
MODIFY_REPLACE,
["000001010000Z"],
)
]
},
)
ldap_connection_unlock = ldap_connect(
env.vars.get("LDAP_HOST"),
env.vars.get("LDAP_USER"),
env.secrets.get("LDAP_BIND_PASSWORD"),
)
ldap_connection_unlock.search(
",".join([
user_ou,
root_dn,
]
),
f"(&(pwdAccountLockedTime=000001010000Z)(|(!(endDate=*))(endDate>=${date_str}))(|(!(startDate=*))(startDate<=${date_str})))" )
found_users = [entry.entry_dn for entry in ldap_connection_unlock.entries]
for user in found_users:
ldap_connection_unlock.modify(
user,
{
"pwdAccountLockedTime": [
(
MODIFY_DELETE,
["000001010000Z"],
)
]
},
)

0 comments on commit 843fc57

Please sign in to comment.