Skip to content

Commit

Permalink
Add sramInactiveDays logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvanes committed Mar 21, 2024
1 parent bb3fc8c commit 4d6c294
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions plsc_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))

WEEK = 7
MONTH = 30
YEAR = 365

SBSPerson = Dict[str, str]
LDAPEntry = Dict[str, List[Union[str, int]]]

Expand Down Expand Up @@ -73,9 +77,26 @@ def sbs2ldap_record(sbs_uid: str, sbs_user: SBSPerson) -> Tuple[str, LDAPEntry]:
record['voPersonStatus'] = [sbs_user.get('status', 'undefined')]

# sramPerson attributes
record['sramLastActivityDate'] = ['20240229155838Z']
record['sramAUPacceptedDate'] = ['20240229155838Z']
record['sramAUPacceptedURI'] = ['https://example.com/']
lld = sbs_user.get('last_login_date')
if not lld or lld == "None":
lld = "1970-01-01 00:00:00"

last_login_date = datetime.datetime.strptime(lld + "+0000", '%Y-%m-%d %H:%M:%S%z')
now = datetime.datetime.now().astimezone()
inactive_days = (now - last_login_date).days

def res(days, interval):
(div, mod) = divmod(days, interval)
return div * interval

if inactive_days >= YEAR:
inactive_days = res(inactive_days, YEAR)
elif inactive_days >= MONTH:
inactive_days = res(inactive_days, MONTH)
elif inactive_days >= WEEK:
inactive_days = res(inactive_days, WEEK)

record['sramInactiveDays'] = [inactive_days]

# clean up the lists, such that we return empty lists if no attribute is present, rather than [None]
for key, val in record.items():
Expand Down Expand Up @@ -257,9 +278,6 @@ def create(src, dst):
dst.rdelete(co_dn)
continue

users = src.users(co)
# logging.debug(f"users: {users}")

logging.debug(" - All groups")
groups = src.groups(co)
#logging.debug(f"groups: {groups}")
Expand Down Expand Up @@ -309,7 +327,8 @@ def create(src, dst):
logging.debug(" - store: {}".format(ldif))

logging.debug(" - People")

users = src.users(co)
# logging.debug(f"users: {users}")
for src_id, src_detail in users.items():
# logging.debug(f"user: {src_detail}")
src_user = src_detail['user']
Expand Down

0 comments on commit 4d6c294

Please sign in to comment.