SAR: add the FMN script
This commit is contained in:
parent
ea755f5a7c
commit
d564aba27e
4 changed files with 85 additions and 0 deletions
|
@ -12,3 +12,8 @@ volgroup: /dev/vg_guests
|
|||
vmhost: virthost02.phx2.fedoraproject.org
|
||||
|
||||
datacenter: phx2
|
||||
|
||||
# GDPR SAR variables
|
||||
sar_script: /usr/local/bin/fmn-sar.py
|
||||
sar_script_user: apache
|
||||
sar_output_file: fmn.json
|
||||
|
|
|
@ -52,6 +52,7 @@ pagure01.fedoraproject.org
|
|||
value01.phx2.fedoraproject.org
|
||||
fas03.phx2.fedoraproject.org
|
||||
pkgs02.phx2.fedoraproject.org
|
||||
notifs-web01.phx2.fedoraproject.org
|
||||
|
||||
[certgetter]
|
||||
certgetter01.phx2.fedoraproject.org
|
||||
|
|
68
roles/notifs/frontend/files/fmn-sar.py
Normal file
68
roles/notifs/frontend/files/fmn-sar.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
GDPR SAR script for FMN.
|
||||
|
||||
Extract all preferences from a selected username and prints them in JSON to the
|
||||
standard output.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import requests
|
||||
from six.moves.urllib.parse import urljoin
|
||||
|
||||
|
||||
ENV_USERNAME = "SAR_USERNAME"
|
||||
FMN_INSTANCE = "http://localhost/notifications/"
|
||||
FMN_CONTEXTS = ["email", "irc"]
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
|
||||
def get_prefs(username, context):
|
||||
url = urljoin(
|
||||
FMN_INSTANCE,
|
||||
"api/{username}.id.fedoraproject.org/{context}/".format(
|
||||
username=username, context=context
|
||||
)
|
||||
)
|
||||
response = requests.get(url)
|
||||
if response.status_code >= 300:
|
||||
log.error("Could not get URL %s: %d %s",
|
||||
url, response.status_code, response.reason)
|
||||
return {}
|
||||
result = response.json()
|
||||
return result
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--debug", action="store_true")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
try:
|
||||
username = os.environ[ENV_USERNAME]
|
||||
except KeyError as e:
|
||||
print("Missing environment variable. {}".format(e), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG if args.debug else logging.WARNING,
|
||||
stream=sys.stderr,
|
||||
)
|
||||
result = {}
|
||||
for context in FMN_CONTEXTS:
|
||||
result[context] = get_prefs(username, context)
|
||||
print(json.dumps(result, indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -129,3 +129,14 @@
|
|||
- notifs
|
||||
- notifs/frontend
|
||||
- selinux
|
||||
|
||||
- name: Install SAR script
|
||||
copy:
|
||||
src: fmn-sar.py
|
||||
dest: /usr/local/bin/fmn-sar.py
|
||||
mode: 0755
|
||||
owner: apache
|
||||
group: apache
|
||||
when: inventory_hostname.startswith('notifs-web01')
|
||||
tags:
|
||||
- notifs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue