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

Upgrade versions of dependencies and fix errors #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
FROM python:3.6
FROM python:3.8
ENV PYTHONUNBUFFERED 1

RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 && chmod +x /usr/local/bin/dumb-init

RUN mkdir /code
WORKDIR /code

Expand Down
2 changes: 1 addition & 1 deletion ac_mediator/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
app.autodiscover_tasks('api', related_name='requests_distributor')
app.autodiscover_tasks(['api'], related_name='requests_distributor')


@app.task(bind=True)
Expand Down
2 changes: 1 addition & 1 deletion ac_mediator/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': ('rest_framework.renderers.JSONRenderer',),
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated' if not DEBUG or not ALLOW_UNAUTHENTICATED_API_REQUESTS_ON_DEBUG
Expand Down
36 changes: 18 additions & 18 deletions ac_mediator/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.conf.urls import include, url
from django.urls import re_path, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
from accounts.views import registration, activate_account, resend_activation_emmil
Expand All @@ -13,43 +13,43 @@
domainPrefix = ""

urlpatterns = [
url(r'^%scrash/$' % domainPrefix, crash_me, name='crash_me'),
url(r'^%sregister/$' % domainPrefix, registration, name='registration'),
url(r'^%sactivate/(?P<username>[^\/]+)/(?P<uid_hash>[^\/]+)/.*$' % domainPrefix, activate_account, name="accounts-activate"),
url(r'^%sreactivate/$' % domainPrefix, resend_activation_emmil, name="accounts-resend-activation"),
url(r'^%slogin/$' % domainPrefix, auth_views.login, {'template_name': 'accounts/login.html'}, name='login'),
url(r'^%slogout/$' % domainPrefix, auth_views.logout, {'next_page': settings.LOGOUT_URL}, name='logout'),
url(r'^%spassword_reset/$' % domainPrefix, auth_views.password_reset, dict(
re_path(r'^%scrash/$' % domainPrefix, crash_me, name='crash_me'),
re_path(r'^%sregister/$' % domainPrefix, registration, name='registration'),
re_path(r'^%sactivate/(?P<username>[^\/]+)/(?P<uid_hash>[^\/]+)/.*$' % domainPrefix, activate_account, name="accounts-activate"),
re_path(r'^%sreactivate/$' % domainPrefix, resend_activation_emmil, name="accounts-resend-activation"),
re_path(r'^%slogin/$' % domainPrefix, auth_views.LoginView.as_view(template_name='accounts/login.html'), name='login'),
re_path(r'^%slogout/$' % domainPrefix, auth_views.LogoutView.as_view(next_page=settings.LOGOUT_URL), name='logout'),
re_path(r'^%spassword_reset/$' % domainPrefix, auth_views.PasswordResetView.as_view(
template_name='accounts/password_reset_form.html',
subject_template_name='emails/password_reset_subject.txt',
email_template_name='emails/password_reset.txt',
), name='password_reset'),
url(r'^%spassword_reset/done/$' % domainPrefix, auth_views.password_reset_done, dict(
re_path(r'^%spassword_reset/done/$' % domainPrefix, auth_views.PasswordResetDoneView.as_view(
template_name='accounts/password_reset_done.html'
), name='password_reset_done'),
url(r'^%sreset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$' % domainPrefix,
auth_views.password_reset_confirm, dict(
re_path(r'^%sreset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$' % domainPrefix,
auth_views.PasswordResetConfirmView.as_view(
template_name='accounts/password_reset_confirm.html'
), name='password_reset_confirm'),
url(r'^%sreset/done/$' % domainPrefix, auth_views.password_reset_complete, dict(
re_path(r'^%sreset/done/$' % domainPrefix, auth_views.PasswordResetCompleteView.as_view(
template_name='accounts/password_reset_complete.html'
), name='password_reset_complete'),

# Accounts
url(r'^%s' % domainPrefix, include('accounts.urls')),
re_path(r'^%s' % domainPrefix, include('accounts.urls')),

# Developers
url(r'^developers/', include('developers.urls')),
re_path(r'^developers/', include('developers.urls')),

# Api
url(r'^%sapi/' % domainPrefix, include('api.urls')),
re_path(r'^%sapi/' % domainPrefix, include('api.urls')),

# Admin
url(r'^admin/monitor/$', monitor, name="admin-monitor"),
url(r'^admin/', admin.site.urls),
re_path(r'^admin/monitor/$', monitor, name="admin-monitor"),
re_path(r'^admin/', admin.site.urls),

# Documentation
url(r'^docs/', include('docs.urls')),
re_path(r'^docs/', include('docs.urls')),
]

if settings.DEBUG:
Expand Down
24 changes: 24 additions & 0 deletions accounts/migrations/0010_auto_20200206_1610.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.2.10 on 2020-02-06 15:10

import django.contrib.postgres.fields.jsonb
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0009_auto_20161027_1651'),
]

operations = [
migrations.AlterField(
model_name='account',
name='last_name',
field=models.CharField(blank=True, max_length=150, verbose_name='last name'),
),
migrations.AlterField(
model_name='servicecredentials',
name='credentials',
field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
),
]
4 changes: 2 additions & 2 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class ServiceCredentials(models.Model):
interpreting the contests of the 'credentials' field.
"""

account = models.ForeignKey(Account, related_name='service_credentials')
account = models.ForeignKey(Account, related_name='service_credentials', on_delete=models.deletion.CASCADE)
service_id = models.CharField(max_length=64)
credentials = JSONField(null=False, default={})
credentials = JSONField(null=False, default=dict)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)

Expand Down
2 changes: 1 addition & 1 deletion accounts/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase, override_settings
from accounts.models import Account
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.core import mail
from django.conf import settings

Expand Down
23 changes: 12 additions & 11 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf.urls import url
from django.core.urlresolvers import reverse_lazy
from django.urls import re_path
from django.urls import reverse_lazy
from accounts import views
from oauth2_provider.views.token import AuthorizedTokenDeleteView, AuthorizedTokensListView
from accounts.views import home
Expand All @@ -9,23 +9,24 @@
# https://stackoverflow.com/questions/6930982/how-to-use-a-variable-inside-a-regular-expression
# domainPrefix = "authenticate/"
domainPrefix = ""
app_name = 'accounts'
urlpatterns = [
# Home
url(r'^%s$' % domainPrefix, home, name='home'),
url(r'^%sabout/$' % domainPrefix, views.about, name='about'),
re_path(r'^%s$' % domainPrefix, home, name='home'),
re_path(r'^%sabout/$' % domainPrefix, views.about, name='about'),

# Link services
url(r'^%slink_services/$' % domainPrefix, views.link_services, name='link_services'),
url(r'^%slink_service/(?P<service_id>[^\/]+)/$' % domainPrefix, views.link_service_callback, name='link_service_callback'),
url(r'^%slink_service_get_token/(?P<service_id>[^\/]+)/$' % domainPrefix, views.link_service_get_token, name='link_service_get_token'),
url(r'^%sunlink_service/(?P<service_id>[^\/]+)/$' % domainPrefix, views.unlink_service, name='unlink_service'),
re_path(r'^%slink_services/$' % domainPrefix, views.link_services, name='link_services'),
re_path(r'^%slink_service/(?P<service_id>[^\/]+)/$' % domainPrefix, views.link_service_callback, name='link_service_callback'),
re_path(r'^%slink_service_get_token/(?P<service_id>[^\/]+)/$' % domainPrefix, views.link_service_get_token, name='link_service_get_token'),
re_path(r'^%sunlink_service/(?P<service_id>[^\/]+)/$' % domainPrefix, views.unlink_service, name='unlink_service'),

# Manage given api credentials
url(r'^%sauthorized_clients/$' % domainPrefix, AuthorizedTokensListView.as_view(
re_path(r'^%sauthorized_clients/$' % domainPrefix, AuthorizedTokensListView.as_view(
template_name='accounts/authorized-tokens.html',
), name="authorized-token-list"),
url(r'^%sauthorized_clients/(?P<pk>\d+)/delete/$' % domainPrefix, AuthorizedTokenDeleteView.as_view(
re_path(r'^%sauthorized_clients/(?P<pk>\d+)/delete/$' % domainPrefix, AuthorizedTokenDeleteView.as_view(
template_name='accounts/authorized-token-delete.html',
success_url=reverse_lazy('authorized-token-list'),
success_url=reverse_lazy('accounts:authorized-token-list'),
), name="authorized-token-delete"),
]
12 changes: 6 additions & 6 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.http import HttpResponseRedirect
from accounts.forms import RegistrationForm, ReactivationForm
from accounts.models import ServiceCredentials, Account
Expand All @@ -11,8 +11,8 @@


def registration(request):
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('home'))
if request.user.is_authenticated:
return HttpResponseRedirect(reverse('accounts:home'))
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
Expand All @@ -28,7 +28,7 @@ def registration(request):

def activate_account(request, username, uid_hash):
if request.user.is_authenticated:
return HttpResponseRedirect(reverse('home'))
return HttpResponseRedirect(reverse('accounts:home'))

try:
account = Account.objects.get(username__iexact=username)
Expand All @@ -46,7 +46,7 @@ def activate_account(request, username, uid_hash):

def resend_activation_emmil(request):
if request.user.is_authenticated:
return HttpResponseRedirect(reverse('home'))
return HttpResponseRedirect(reverse('accounts:home'))

if request.method == 'POST':
form = ReactivationForm(request.POST)
Expand Down Expand Up @@ -138,4 +138,4 @@ def link_service_get_token(request, service_id):
@login_required
def unlink_service(request, service_id):
ServiceCredentials.objects.filter(account=request.user, service_id=service_id).delete()
return HttpResponseRedirect(reverse('link_services'))
return HttpResponseRedirect(reverse('accounts:link_services'))
2 changes: 1 addition & 1 deletion api/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.forms import ModelForm
from django.forms.fields import Field
from django.utils.text import mark_safe
from django.utils.safestring import mark_safe
from django.forms.widgets import HiddenInput
from api.models import ApiClient
setattr(Field, 'is_checkbox', lambda self: isinstance(self.widget, forms.CheckboxInput)) # Used in the template
Expand Down
30 changes: 30 additions & 0 deletions api/migrations/0005_auto_20200206_1610.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2.10 on 2020-02-06 15:10

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0004_apiclient_password_grant_is_allowed'),
]

operations = [
migrations.AddField(
model_name='apiclient',
name='updated',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='apiclient',
name='id',
field=models.BigAutoField(primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='apiclient',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_apiclient', to=settings.AUTH_USER_MODEL),
),
]
4 changes: 2 additions & 2 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.core.urlresolvers import reverse
from django.urls import reverse
from oauth2_provider.models import AbstractApplication


Expand All @@ -14,7 +14,7 @@ class ApiClient(AbstractApplication):
# Add more custom fields here like description, logo, preferred services...

def get_absolute_url(self):
return reverse('developers-app-detail', args=[self.id])
return reverse('developers:app-detail', args=[self.id])

def clean(self):
"""
Expand Down
13 changes: 7 additions & 6 deletions api/oauth2_urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.conf.urls import url
from django.urls import re_path
from oauth2_provider import views

urlpatterns = (
url(r'^authorize/?$', views.AuthorizationView.as_view(
app_name = 'oauth2_provider'
urlpatterns = [
re_path(r'^authorize/?$', views.AuthorizationView.as_view(
template_name='accounts/authorize_client.html',
), name="authorize"),
url(r'^token/?$', views.TokenView.as_view(), name="token"),
url(r'^revoke_token/?$', views.RevokeTokenView.as_view(), name="revoke-token"),
)
re_path(r'^token/?$', views.TokenView.as_view(), name="token"),
re_path(r'^revoke_token/?$', views.RevokeTokenView.as_view(), name="revoke-token"),
]
4 changes: 2 additions & 2 deletions api/request_distributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def process_request(request, wait_until_complete=False, include=None, exclude=No
return a response right after all requests have been sent. This response will mainly
include a response_id parameter that can be later used to pull the actual responses
from the 3rd party services (see ResponseAggregator.collect_response).
If wait_until_complete is set to False, then this method will wait untill a response is
If wait_until_complete is set to False, then this method will wait until a response is
received for all requests and only then will return an aggregated response including the
contents of all 3rd party services individual responses.

Expand Down Expand Up @@ -83,7 +83,7 @@ def process_request(request, wait_until_complete=False, include=None, exclude=No
# Wait until all responses are received (only if wait_until_complete == True)
if wait_until_complete:
# We wait until we get a response for all the requests we sent
# We do that by continuously iterating over all async_response_objetcs in a while
# We do that by continuously iterating over all async_response_objects in a while
# loop and only exit when all of them have been flagged as ready
# TODO: we should add some control over timeouts, etc as this operation is blocking
while True:
Expand Down
2 changes: 1 addition & 1 deletion api/response_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def collect_response(self, response_id, format='json'):
to_return = response.copy()
to_return['meta']['response_id'] = response_id # Add response_id to returned dictionary
to_return['meta']['collect_url'] = \
settings.BASE_URL + '{0}?rid={1}'.format(reverse('api-collect'),
settings.BASE_URL + '{0}?rid={1}'.format(reverse('api:api-collect'),
response_id) # Add collect url for convenience
to_return['meta']['current_timestamp'] = str(datetime.datetime.now())
if response['meta']['status'] == RESPONSE_STATUS_FINISHED and settings.DELETE_RESPONSES_AFTER_CONSUMED:
Expand Down
10 changes: 5 additions & 5 deletions api/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.test import TestCase, override_settings
from api.models import ApiClient
from accounts.models import Account
from django.core.urlresolvers import reverse
from django.urls import reverse
from services import management
from django.conf import settings
import oauth2_provider
Expand Down Expand Up @@ -399,7 +399,7 @@ def get_download_url(self, acid):
def test_get_download_link(self):

# Make unauthenticated request and assert it returns 401
resp = self.client.get(reverse('api-download'), {
resp = self.client.get(reverse('api:download'), {
'acid': 'DownloadService:123',
})
self.assertEqual(resp.status_code, 401)
Expand All @@ -414,19 +414,19 @@ def test_get_download_link(self):
)

# Make API request authenticated and assert it returns 200
resp = self.client.get(reverse('api-download'), {
resp = self.client.get(reverse('api:download'), {
'acid': 'DownloadService:123',
}, HTTP_AUTHORIZATION='Bearer {0}'.format(access_token))
self.assertEqual(resp.status_code, 200)

# Ensure request for non existing service returns 404
resp = self.client.get(reverse('api-download'), {
resp = self.client.get(reverse('api:download'), {
'acid': 'DownloadService2:123',
}, HTTP_AUTHORIZATION='Bearer {0}'.format(access_token))
self.assertEqual(resp.status_code, 404)

# Ensure request with no acid parameter returns 400
resp = self.client.get(reverse('api-download'), {
resp = self.client.get(reverse('api:download'), {
'acid2': 'DownloadService:123',
}, HTTP_AUTHORIZATION='Bearer {0}'.format(access_token))
self.assertEqual(resp.status_code, 400)
19 changes: 10 additions & 9 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from django.conf.urls import include, url
from django.urls import re_path, include
from api import views

app_name = 'api'
urlpatterns = [
url(r'^v1/services/$', views.services, name='api-services'),
url(r'^v1/collect/$', views.collect_response, name='api-collect'),
url(r'^v1/search/text/$', views.text_search, name='api-text-search'),
url(r'^v1/license/$', views.licensing, name='api-licensing'),
url(r'^v1/download/$', views.download, name='api-download'),
url(r'^v1/me/$', views.me, name='api-me'),
re_path(r'^v1/services/$', views.services, name='services'),
re_path(r'^v1/collect/$', views.collect_response, name='collect'),
re_path(r'^v1/search/text/$', views.text_search, name='text-search'),
re_path(r'^v1/license/$', views.licensing, name='licensing'),
re_path(r'^v1/download/$', views.download, name='download'),
re_path(r'^v1/me/$', views.me, name='me'),

# Oauth2 urls
url(r'^o/', include('api.oauth2_urls', namespace='oauth2_provider')),
re_path(r'^o/', include('api.oauth2_urls')),

# Invalid url
url(r'$', views.invalid_url),
re_path(r'$', views.invalid_url),
]
Loading