Files
edx-platform/common/djangoapps/third_party_auth/management/commands/saml.py
Feanil Patel 9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00

50 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
"""
Management commands for third_party_auth
"""
import logging
from django.core.management.base import BaseCommand, CommandError
from third_party_auth.tasks import fetch_saml_metadata
class Command(BaseCommand):
""" manage.py commands to manage SAML/Shibboleth SSO """
help = '''Configure/maintain/update SAML-based SSO'''
def add_arguments(self, parser):
parser.add_argument('--pull', action='store_true', help="Pull updated metadata from external IDPs")
def handle(self, *args, **options):
should_pull_saml_metadata = options.get('pull', False)
if not should_pull_saml_metadata:
raise CommandError("Command can only be used with '--pull' option.")
log_handler = logging.StreamHandler(self.stdout)
log_handler.setLevel(logging.DEBUG)
log = logging.getLogger('third_party_auth.tasks')
log.propagate = False
log.addHandler(log_handler)
total, skipped, attempted, updated, failed, failure_messages = fetch_saml_metadata()
self.stdout.write(
u"\nDone."
u"\n{total} provider(s) found in database."
u"\n{skipped} skipped and {attempted} attempted."
u"\n{updated} updated and {failed} failed.\n".format(
total=total,
skipped=skipped, attempted=attempted,
updated=updated, failed=failed,
)
)
if failed > 0:
raise CommandError(
u"Command finished with the following exceptions:\n\n{failures}".format(
failures="\n\n".join(failure_messages)
)
)