From 64b94acd97b294dffde865edd0eaabe244be7eb9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Thu, 17 May 2018 12:24:40 +0200 Subject: [PATCH] Add meetbot SAR script Signed-off-by: Pierre-Yves Chibon --- roles/supybot/files/meetbot_sar.py | 59 ++++++++++++++++++++++++++++++ roles/supybot/tasks/main.yml | 10 +++++ 2 files changed, 69 insertions(+) create mode 100644 roles/supybot/files/meetbot_sar.py diff --git a/roles/supybot/files/meetbot_sar.py b/roles/supybot/files/meetbot_sar.py new file mode 100644 index 0000000000..42275db107 --- /dev/null +++ b/roles/supybot/files/meetbot_sar.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +from __future__ import unicode_literals, print_function + +import json +import os +import subprocess +import sys + + +_logs_folder = '/srv/web/meetbot' +_base_url = 'https://meetbot-raw.fedoraproject.org/' + + +def main(): + ''' Prints out links to all the meeting where the specified username or + email are prsent. + The username must be specified via the SAR_USERNAME environment variable. + The email must be specified via the SAR_EMAIL environment variable. + ''' + + username = os.getenv('SAR_USERNAME') + email = os.getenv('SAR_EMAIL') + + if not username and not email: + print('An username or an email must be specified to query meetbot logs') + return 1 + + output = {} + output['meetings'] = set() + + os.chdir(_logs_folder) + + def _grep_and_process(command): + cli_out = subprocess.check_output(command).decode('utf-8') + lines = cli_out.split('\n') + for line in lines: + if line.startswith('./'): + line = line[2:] + url = '%s/%s' % (_base_url.rstrip('/'), line) + output['meetings'].add(url) + + if username: + command = ['grep', '-iR', '-l', username, '.'] + _grep_and_process(command) + + if email: + command = ['grep', '-iR', '-l', email, '.'] + _grep_and_process(command) + + output['meetings'] = list(output['meetings']) + + print(json.dumps( + output, sort_keys=True, indent=4, separators=(',', ': ') + ).encode('utf-8')) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/roles/supybot/tasks/main.yml b/roles/supybot/tasks/main.yml index 843bf667e5..205bda8d30 100644 --- a/roles/supybot/tasks/main.yml +++ b/roles/supybot/tasks/main.yml @@ -103,3 +103,13 @@ tags: - config - supybot + +- name: setup the SAR script for the meetbot logs + copy: src=meetbot_sar.py dest=/usr/local/bin/meetbot_sar.py + owner:root group:root mode:0700 + tags: + - config + - supybot + - SAR + - GDPR +