-
Notifications
You must be signed in to change notification settings - Fork 26
/
owner_actions_from_auditlog
executable file
·55 lines (41 loc) · 1.42 KB
/
owner_actions_from_auditlog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
"""Print all owner activity from an audit log."""
import argparse
import logging
import subprocess # nosec
from client import get_github3_client
import github3
logger = logging.getLogger(__name__)
def get_org_access(login, json_file):
cmd = [
"jq",
"-rc",
""" .[] | select(.actor == "{}") | select(.action|test("org.")) | [(.created_at/1000 | todate), .actor, .action] | @csv """.format(
login
),
]
with open(json_file) as json:
csv_output = subprocess.check_output( # nosec
cmd, shell=False, stderr=subprocess.STDOUT, stdin=json
)
return csv_output
def process_org(gh, args):
"""Get owners for specified org, then output actions done by them that
required org owner permissions."""
org = gh.organization(args.org)
for l in org.members(role="admin"):
csv = get_org_access(l.login, args.audit_file)
print(csv)
def parse_args():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--org", default="mozilla", help="GitHub org to process")
parser.add_argument("audit_file", help="JSON audit log to process")
args = parser.parse_args()
return args
def main():
args = parse_args()
gh = get_github3_client()
process_org(gh, args)
if __name__ == "__main__":
logging.basicConfig(level=logging.WARN, format="%(asctime)s %(message)s")
main()