Skip to content

Commit 60a5b13

Browse files
Updates to installation handling and AWS logs searching
Signed-off-by: Lukasz Gryglicki <[email protected]> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent 0f2b189 commit 60a5b13

File tree

2 files changed

+49
-27
lines changed

2 files changed

+49
-27
lines changed

cla-backend/cla/controllers/github.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
import os
1010
import uuid
11+
import traceback
1112
from datetime import datetime
1213
from pprint import pprint
1314
from typing import Optional, List
@@ -319,23 +320,34 @@ def handle_installation_event(action: str, body: dict):
319320
return {'status': f'GitHub installation {action} event malformed.'}
320321

321322
cla.log.debug(f'Locating organization using name: {org_name}')
322-
existing = get_organization(org_name)
323-
if 'errors' in existing:
324-
cla.log.warning(f'{func_name} - Received github installation created event for organization: {org_name}, '
325-
'but the organization is not configured in EasyCLA')
326-
# TODO: Need a way of keeping track of new organizations that don't have projects yet.
327-
return {'status': 'Github Organization must be created through the Project Management Console.'}
328-
elif not existing.get('organization_installation_id'):
329-
cla.log.info(f'{func_name} - Setting installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
330-
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
331-
cla.log.info(f'{func_name} - Organization enrollment completed: {existing.get("organization_name")}')
332-
return {'status': 'Organization Enrollment Completed. CLA System is operational'}
333-
else:
334-
cla.log.info(f'{func_name} - Organization already enrolled: {existing.get("organization_name")}')
335-
cla.log.info(f'{func_name} - installation ID: {existing.get("organization_installation_id")}')
336-
cla.log.info(f'{func_name} - Updating installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
337-
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
338-
return {'status': 'Already Enrolled Organization Updated. CLA System is operational'}
323+
try:
324+
existing = get_organization(org_name)
325+
cla.log.debug(
326+
f"{func_name} - post-get_organization type={type(existing)} "
327+
f"keys={list(existing.keys()) if isinstance(existing, dict) else '(n/a)'} "
328+
f"values={list(existing.values()) if isinstance(existing, dict) else '(n/a)'}"
329+
)
330+
if 'errors' in existing:
331+
cla.log.warning(f'{func_name} - Received github installation created event for organization: {org_name}, '
332+
'but the organization is not configured in EasyCLA')
333+
# TODO: Need a way of keeping track of new organizations that don't have projects yet.
334+
return {'status': 'Github Organization must be created through the Project Management Console.'}
335+
elif not existing.get('organization_installation_id'):
336+
cla.log.info(f'{func_name} - Setting installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
337+
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
338+
cla.log.info(f'{func_name} - Organization enrollment completed: {existing.get("organization_name")}')
339+
return {'status': 'Organization Enrollment Completed. CLA System is operational'}
340+
else:
341+
cla.log.info(f'{func_name} - Organization already enrolled: {existing.get("organization_name")}')
342+
cla.log.info(f'{func_name} - installation ID: {existing.get("organization_installation_id")}')
343+
cla.log.info(f'{func_name} - Updating installation ID for github organization: {existing.get("organization_name")} to {installation_id}')
344+
update_organization(existing.get('organization_name'), existing.get('organization_sfid'), installation_id)
345+
return {'status': 'Already Enrolled Organization Updated. CLA System is operational'}
346+
except Exception as e:
347+
cla.log.error(f"{func_name} - exception entering/enforcing enrollment branches: {type(e).__name__}: {e}\n"
348+
f"{traceback.format_exc()}"
349+
)
350+
raise
339351

340352
elif action == 'deleted':
341353
cla.log.debug(f'{func_name} - processing github installation activity for action: {action}')

utils/search_aws_log_group.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,34 @@ then
3535
exit 2
3636
fi
3737

38+
to_epoch_ms () {
39+
local v="$1"
40+
if [[ "$v" =~ ^[0-9]{13}$ ]]
41+
then
42+
echo "$v"; return
43+
fi
44+
if [[ "$v" =~ ^[0-9]{10}$ ]]
45+
then
46+
echo "${v}000"; return
47+
fi
48+
v="${v/T/ }"
49+
v="${v/Z/ UTC}"
50+
echo "$(date -d "$v" +%s)000"
51+
}
52+
3853
if [ -z "${DTFROM}" ]
3954
then
40-
export DTFROM="$(date -d '3 days ago' +%s)000"
55+
export DTFROM="$(to_epoch_ms '3 days ago')"
4156
else
42-
if [[ ! "$DTFROM" =~ ^[0-9]+$ ]]
43-
then
44-
export DTFROM="$(date -d "${DTFROM}" +%s)000"
45-
fi
57+
export DTFROM="$(to_epoch_ms "${DTFROM}")"
4658
fi
4759

60+
# DTTO
4861
if [ -z "${DTTO}" ]
4962
then
50-
export DTTO="$(date +%s)000"
63+
export DTTO="$(to_epoch_ms 'now')"
5164
else
52-
if [[ ! "$DTTO" =~ ^[0-9]+$ ]]
53-
then
54-
export DTTO="$(date -d "${DTTO}" +%s)000"
55-
fi
65+
export DTTO="$(to_epoch_ms "${DTTO}")"
5666
fi
5767

5868
if [ ! -z "${DEBUG}" ]

0 commit comments

Comments
 (0)