def download_settings_local()

in django_airavata/apps/auth/views.py [0:0]


def download_settings_local(request):

    if not (request.is_gateway_admin or request.is_read_only_gateway_admin):
        raise PermissionDenied()

    if settings.DEBUG:
        raise Exception("Downloading a settings_local.py file isn't allowed in DEBUG mode.")

    development_client_id = f"local-django-{request.user.username}"
    access_token = utils.get_service_account_authz_token().accessToken
    clients_endpoint = get_clients_endpoint()
    development_client = get_client(access_token, clients_endpoint, development_client_id)
    if development_client is None:
        development_client_endpoint = create_client(access_token, clients_endpoint, development_client_id)
    else:
        development_client_endpoint = get_client_endpoint(development_client)
    development_client_secret = get_client_secret(access_token, development_client_endpoint)

    context = {}
    context['AUTHENTICATION_OPTIONS'] = settings.AUTHENTICATION_OPTIONS
    context['keycloak_client_id'] = development_client_id
    context['keycloak_client_secret'] = development_client_secret
    context['KEYCLOAK_AUTHORIZE_URL'] = settings.KEYCLOAK_AUTHORIZE_URL
    context['KEYCLOAK_TOKEN_URL'] = settings.KEYCLOAK_TOKEN_URL
    context['KEYCLOAK_USERINFO_URL'] = settings.KEYCLOAK_USERINFO_URL
    context['KEYCLOAK_LOGOUT_URL'] = settings.KEYCLOAK_LOGOUT_URL
    context['GATEWAY_ID'] = settings.GATEWAY_ID
    context['AIRAVATA_API_HOST'] = settings.AIRAVATA_API_HOST
    context['AIRAVATA_API_PORT'] = settings.AIRAVATA_API_PORT
    context['AIRAVATA_API_SECURE'] = settings.AIRAVATA_API_SECURE
    if hasattr(settings, 'GATEWAY_DATA_STORE_REMOTE_API'):
        context['GATEWAY_DATA_STORE_REMOTE_API'] = settings.GATEWAY_DATA_STORE_REMOTE_API
    else:
        context['GATEWAY_DATA_STORE_REMOTE_API'] = request.build_absolute_uri("/")
    context['PROFILE_SERVICE_HOST'] = settings.PROFILE_SERVICE_HOST
    context['PROFILE_SERVICE_PORT'] = settings.PROFILE_SERVICE_PORT
    context['PROFILE_SERVICE_SECURE'] = settings.PROFILE_SERVICE_SECURE
    context['PORTAL_TITLE'] = settings.PORTAL_TITLE
    settings_local_str = render_to_string("django_airavata_auth/settings_local.py.template", context)
    settings_local_bytesio = io.BytesIO(settings_local_str.encode())
    return FileResponse(settings_local_bytesio, as_attachment=True, filename="settings_local.py")