@@ -0,0 +1,1411 @@
+import json%0Aimport logging%0A%0Afrom django.contrib.auth import get_user_model%0Afrom django.core.management.base import BaseCommand, CommandError%0Afrom rest_framework import status%0Afrom rest_framework.test import APIClient%0A%0AUser = get_user_model()%0A%0A%0Aclass Command(BaseCommand):%0A    help = %22Exports Waldur API Documentation in JSON format%22%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument(%0A            '-o', '--output',%0A            dest='output', default=None,%0A            help='Specifies file to which the output is written.',%0A        )%0A%0A    def handle(self, *args, **options):%0A        # Rise logging level to prevent redundant log messages%0A        logging.disable(logging.CRITICAL)%0A%0A        client = APIClient(HTTP_HOST='localhost')%0A        user, _ = User.objects.get_or_create(username='waldur_docs_exporter', is_staff=True)%0A        client.force_authenticate(user=user)%0A        response = client.get('/docs/?format=openapi')%0A        user.delete()%0A%0A        if response.status_code != status.HTTP_200_OK:%0A            raise CommandError('Failed to get response from the server')%0A%0A        data = json.loads(response.content)%0A        if options%5B'output'%5D is None:%0A            self.stdout.write(str(data))%0A        else:%0A            with open(options%5B'output'%5D, 'w') as output_file:%0A                json.dump(data, output_file)%0A%0A        # return logging level back%0A        logging.disable(logging.NOTSET)%0A

Add export_api_docs management command