import re

content = open('app/__init__.py').read()

new_csp = (
    "default-src 'self'; "
    "script-src 'self' https://www.google.com/ https://www.gstatic.com/ https://recaptcha.google.com/ https://static.cloudflareinsights.com/; "
    "frame-src 'self' https://www.google.com/ https://recaptcha.google.com/; "
    "connect-src 'self' https://www.google.com/ https://recaptcha.google.com/ https://www.gstatic.com/; "
    "img-src 'self' data: https://www.gstatic.com/; "
    "style-src 'self' 'unsafe-inline';"
)

content = re.sub(
    r"response\.headers\['Content-Security-Policy'\] = .*",
    "response.headers['Content-Security-Policy'] = \"" + new_csp + "\"",
    content
)

open('app/__init__.py', 'w').write(content)
print('Done - CSP updated')
