def kumascript_revision_hash(request):
    """
    Return the kumascript revision hash. Requests the value directly
    from the kumascript service.
    """
    response = kumascript.request_revision_hash()
    return HttpResponse(response.text,
                        status=response.status_code,
                        content_type=response.headers.get('content-type'))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: Elchi3/kuma
def kumascript_revision_hash(request):
    """
    Return the kumascript revision hash. Requests the value directly
    from the kumascript service.
    """
    response = kumascript.request_revision_hash()
    return HttpResponse(
        response.text,
        status=response.status_code,
        content_type=response.headers.get('content-type')
    )
Ejemplo n.º 3
0
def status(request):
    """
    Return summary information about this Kuma instance.

    Functional tests can use this to customize the test process.
    """
    data = {
        'version': 1,
        'request': {
            'url': request.build_absolute_uri(''),
            'host': request.get_host(),
            'is_secure': request.is_secure(),
            'scheme': request.scheme,
        },
        'services': {
            'database': {},
            'kumascript': {},
            'search': {},
            'test_accounts': {},
        },
        'settings': {
            'ALLOWED_HOSTS': settings.ALLOWED_HOSTS,
            'ATTACHMENT_HOST': settings.ATTACHMENT_HOST,
            'ATTACHMENT_ORIGIN': settings.ATTACHMENT_ORIGIN,
            'DEBUG': settings.DEBUG,
            'INTERACTIVE_EXAMPLES_BASE': settings.INTERACTIVE_EXAMPLES_BASE,
            'LEGACY_HOSTS': settings.LEGACY_HOSTS,
            'MAINTENANCE_MODE': settings.MAINTENANCE_MODE,
            'PROTOCOL': settings.PROTOCOL,
            'REVISION_HASH': settings.REVISION_HASH,
            'SITE_URL': settings.SITE_URL,
            'STATIC_URL': settings.STATIC_URL,
        },
    }

    # Check that database is reachable, populated
    doc_data = {'available': True, 'populated': False, 'document_count': 0}
    try:
        doc_count = Document.objects.count()
    except DatabaseError:
        doc_data['available'] = False
    else:
        if doc_count:
            doc_data['populated'] = True
            doc_data['document_count'] = doc_count
    data['services']['database'] = doc_data

    # Check that KumaScript is reachable
    ks_data = {
        'available': True,
        'revision': None,
    }
    try:
        ks_response = request_revision_hash()
    except Requests_ConnectionError:
        ks_response = None
    if not ks_response or ks_response.status_code != 200:
        ks_data['available'] = False
    else:
        ks_data['revision'] = ks_response.text
    data['services']['kumascript'] = ks_data

    # Check that ElasticSearch is reachable, populated
    search_data = {'available': True, 'populated': False, 'count': 0}
    try:
        search_count = WikiDocumentType.search().count()
    except ES_ConnectionError:
        search_data['available'] = False
    except NotFoundError:
        pass  # available but unpopulated (and maybe uncreated)
    else:
        if search_count:
            search_data['populated'] = True
            search_data['count'] = search_count
    data['services']['search'] = search_data

    # Check if the testing accounts are available
    test_account_data = {'available': False}
    test_account_names = [
        'test-super', 'test-moderator', 'test-new', 'test-banned',
        'viagra-test-123'
    ]
    try:
        users = list(
            User.objects.only(
                'id', 'username',
                'password').filter(username__in=test_account_names))
    except DatabaseError:
        users = []
    if len(users) == len(test_account_names):
        for user in users:
            if not user.check_password('test-password'):
                break
        else:
            # All users have the testing password
            test_account_data['available'] = True
    data['services']['test_accounts'] = test_account_data

    return JsonResponse(data)
Ejemplo n.º 4
0
def status(request):
    """
    Return summary information about this Kuma instance.

    Functional tests can use this to customize the test process.
    """
    data = {
        'version': 1,
        'request': {
            'url': request.build_absolute_uri(''),
            'host': request.get_host(),
            'is_secure': request.is_secure(),
            'scheme': request.scheme,
        },
        'services': {
            'database': {},
            'kumascript': {},
            'search': {},
            'test_accounts': {},
        },
        'settings': {
            'ALLOWED_HOSTS': settings.ALLOWED_HOSTS,
            'ATTACHMENT_HOST': settings.ATTACHMENT_HOST,
            'ATTACHMENT_ORIGIN': settings.ATTACHMENT_ORIGIN,
            'DEBUG': settings.DEBUG,
            'INTERACTIVE_EXAMPLES_BASE': settings.INTERACTIVE_EXAMPLES_BASE,
            'LEGACY_HOSTS': settings.LEGACY_HOSTS,
            'MAINTENANCE_MODE': settings.MAINTENANCE_MODE,
            'PROTOCOL': settings.PROTOCOL,
            'REVISION_HASH': settings.REVISION_HASH,
            'SITE_URL': settings.SITE_URL,
            'STATIC_URL': settings.STATIC_URL,
        },
    }

    # Check that database is reachable, populated
    doc_data = {
        'available': True,
        'populated': False,
        'document_count': 0
    }
    try:
        doc_count = Document.objects.count()
    except DatabaseError:
        doc_data['available'] = False
    else:
        if doc_count:
            doc_data['populated'] = True
            doc_data['document_count'] = doc_count
    data['services']['database'] = doc_data

    # Check that KumaScript is reachable
    ks_data = {
        'available': True,
        'revision': None,
    }
    try:
        ks_response = request_revision_hash()
    except Requests_ConnectionError:
        ks_response = None
    if not ks_response or ks_response.status_code != 200:
        ks_data['available'] = False
    else:
        ks_data['revision'] = ks_response.text
    data['services']['kumascript'] = ks_data

    # Check that ElasticSearch is reachable, populated
    search_data = {
        'available': True,
        'populated': False,
        'count': 0
    }
    try:
        search_count = WikiDocumentType.search().count()
    except ES_ConnectionError:
        search_data['available'] = False
    except NotFoundError:
        pass  # available but unpopulated (and maybe uncreated)
    else:
        if search_count:
            search_data['populated'] = True
            search_data['count'] = search_count
    data['services']['search'] = search_data

    # Check if the testing accounts are available
    test_account_data = {
        'available': False
    }
    test_account_names = ['test-super', 'test-moderator', 'test-new',
                          'test-banned', 'viagra-test-123']
    try:
        users = list(User.objects.only('id', 'username', 'password')
                                 .filter(username__in=test_account_names))
    except DatabaseError:
        users = []
    if len(users) == len(test_account_names):
        for user in users:
            if not user.check_password('test-password'):
                break
        else:
            # All users have the testing password
            test_account_data['available'] = True
    data['services']['test_accounts'] = test_account_data

    return JsonResponse(data)
Ejemplo n.º 5
0
def status(request):
    """
    Return summary information about this Kuma instance.

    Functional tests can use this to customize the test process.
    """
    data = {
        "version": 1,
        "request": {
            "url": request.build_absolute_uri(""),
            "host": request.get_host(),
            "is_secure": request.is_secure(),
            "scheme": request.scheme,
        },
        "services": {
            "database": {},
            "kumascript": {},
            "search": {},
            "test_accounts": {},
        },
        "settings": {
            "ALLOWED_HOSTS": settings.ALLOWED_HOSTS,
            "ATTACHMENT_HOST": settings.ATTACHMENT_HOST,
            "ATTACHMENT_ORIGIN": settings.ATTACHMENT_ORIGIN,
            "ATTACHMENTS_AWS_S3_CUSTOM_URL":
            settings.ATTACHMENTS_AWS_S3_CUSTOM_URL,
            "DEBUG": settings.DEBUG,
            "INTERACTIVE_EXAMPLES_BASE": settings.INTERACTIVE_EXAMPLES_BASE,
            "MAINTENANCE_MODE": settings.MAINTENANCE_MODE,
            "PROTOCOL": settings.PROTOCOL,
            "REVISION_HASH": settings.REVISION_HASH,
            "SITE_URL": settings.SITE_URL,
            "STATIC_URL": settings.STATIC_URL,
            "WIKI_SITE_URL": settings.WIKI_SITE_URL,
        },
    }

    # Check that database is reachable, populated
    doc_data = {"available": True, "populated": False, "document_count": 0}
    try:
        doc_count = Document.objects.count()
    except DatabaseError:
        doc_data["available"] = False
    else:
        if doc_count:
            doc_data["populated"] = True
            doc_data["document_count"] = doc_count
    data["services"]["database"] = doc_data

    # Check that KumaScript is reachable
    ks_data = {
        "available": True,
        "revision": None,
    }
    try:
        ks_response = request_revision_hash()
    except (Requests_ConnectionError, ReadTimeout):
        ks_response = None
    if not ks_response or ks_response.status_code != 200:
        ks_data["available"] = False
    else:
        ks_data["revision"] = ks_response.text
    data["services"]["kumascript"] = ks_data

    # Check that ElasticSearch is reachable, populated
    search_data = {"available": True, "populated": False, "count": 0}
    try:
        search_count = WikiDocumentType.search().count()
    except ES_ConnectionError:
        search_data["available"] = False
    except NotFoundError:
        pass  # available but unpopulated (and maybe uncreated)
    else:
        if search_count:
            search_data["populated"] = True
            search_data["count"] = search_count
    data["services"]["search"] = search_data

    # Check if the testing accounts are available
    test_account_data = {"available": False}
    test_account_names = [
        "test-super",
        "test-moderator",
        "test-new",
        "test-banned",
        "viagra-test-123",
    ]
    try:
        users = list(
            User.objects.only(
                "id", "username",
                "password").filter(username__in=test_account_names))
    except DatabaseError:
        users = []
    if len(users) == len(test_account_names):
        for user in users:
            if not user.check_password("test-password"):
                break
        else:
            # All users have the testing password
            test_account_data["available"] = True
    data["services"]["test_accounts"] = test_account_data

    return JsonResponse(data)