Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove /cname endpoint #4731

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions readthedocs/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ def broadcast(type, task, args, kwargs=None, callback=None): # pylint: disable=
return task_promise


def clean_url(url):
parsed = urlparse(url)
if parsed.scheme or parsed.netloc:
return parsed.netloc
return parsed.path


def cname_to_slug(host):
# TODO: remove
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this after #4730

from dns import resolver
answer = [ans for ans in resolver.query(host, 'CNAME')][0]
domain = answer.target.to_unicode()
Expand Down
1 change: 0 additions & 1 deletion readthedocs/restapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
function_urls = [
url(r'embed/', core_views.embed, name='embed'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one isn't used either, and it doesn't work

Copy link
Member

@ericholscher ericholscher Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, we should kill this. We have the embed in our ext repo that actually does work:

https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/urls.py#L117

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #4768

url(r'docurl/', core_views.docurl, name='docurl'),
url(r'cname/', core_views.cname, name='cname'),
url(r'footer_html/', footer_views.footer_html, name='footer_html'),
]

Expand Down
28 changes: 0 additions & 28 deletions readthedocs/restapi/views/core_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,12 @@
from django.core.cache import cache
from django.shortcuts import get_object_or_404

from readthedocs.core.utils import clean_url, cname_to_slug
from readthedocs.builds.constants import LATEST
from readthedocs.builds.models import Version
from readthedocs.projects.models import Project
from readthedocs.core.templatetags.core_tags import make_document_url


@decorators.api_view(['GET'])
@decorators.permission_classes((permissions.AllowAny,))
@decorators.renderer_classes((JSONRenderer,))
def cname(request):
"""
Get the slug that a particular hostname resolves to.

This is useful for debugging your DNS settings,
or for getting the backing project name on Read the Docs for a URL.

Example::

GET https://readthedocs.org/api/v2/cname/?host=docs.python-requests.org

This will return information about ``docs.python-requests.org``
"""
host = request.GET.get('host')
if not host:
return Response({'error': 'host GET arg required'}, status=status.HTTP_400_BAD_REQUEST)
host = clean_url(host)
slug = cname_to_slug(host)
return Response({
'host': host,
'slug': slug,
})


@decorators.api_view(['GET'])
@decorators.permission_classes((permissions.AllowAny,))
@decorators.renderer_classes((JSONRenderer,))
Expand Down