Skip to content

Commit

Permalink
Update Regex check url AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Oct 8, 2019
1 parent 77e7d1b commit 1a5290d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gevent = "*"
packaging = "*"
django-environ = "*"
boto3 = "*"
validators = "*"

[dev-packages]
"flake8" = "*"
Expand Down
60 changes: 37 additions & 23 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions bothub/api/v2/nlp/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64
import json
import re
import requests
import validators

from django.conf import settings
from django.db import models
Expand Down Expand Up @@ -420,18 +420,7 @@ def retrieve(self, request, *args, **kwargs):
check_auth(request)
update = self.get_object()

regex = re.compile(
r"^(?:http|ftp)s?://" # http:// or https://
r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|"
r"[A-Z0-9-]{2,}\.?)|"
r"localhost|"
r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
r"(?::\d+)?"
r"(?:/?|[/?]\S+)$",
re.IGNORECASE,
)

if re.match(regex, update.bot_data) is not None:
if validators.url(str(update.bot_data).lower()):
try:
download = requests.get(update.bot_data)
bot_data = base64.b64encode(download.content)
Expand Down

0 comments on commit 1a5290d

Please sign in to comment.