diff --git a/TsaApi/urls.py b/TsaApi/urls.py index 7962cfed18985be06cc6bf6156b68292eceb2750..ab79e229c4dec07f54aca43c559dea39176aae3e 100644 --- a/TsaApi/urls.py +++ b/TsaApi/urls.py @@ -6,5 +6,6 @@ from django.urls import include urlpatterns = [ url(r'api/tsa/', include('app.urls')), - url(r'^api-token-auth/', obtain_jwt_token), + # Habilitar para permitir la autenticación + #url(r'^api-token-auth/', obtain_jwt_token, name='jwt'), ] diff --git a/app/views.py b/app/views.py index 93b32ec638638cf7cce586d7353f00a4fd0d46c7..f756cda8b88a2dda75421d9420c0a827fac9ac2d 100644 --- a/app/views.py +++ b/app/views.py @@ -2,6 +2,7 @@ import base64 from django.core.exceptions import ValidationError from django.utils.translation import gettext as _ from rest_framework import status +from rest_framework.schemas import AutoSchema from rest_framework.views import APIView from rest_framework.response import Response from web3.exceptions import CannotHandleRequest @@ -14,36 +15,22 @@ from app.utils import Utils from TsaApi.local_settings import TEMPORARY_OTS_PREFIX, PERMANENT_OTS_PREFIX, CONTRACTS class Stamp(APIView): - """ - [POST] - Permite realizar un stamp de un archivo - - Parámetros recibidos: - [Content-Type:application/json] - - file_hash: El hash del archivo encodeado en sha256 - - Devuelve un OTS para poder verificar en el futuro que el archivo fue incluido a la Blockchain - - Ejemplo: - { - "file_hash": "1957db7fe23e4be1740ddeb941ddda7ae0a6b782e536a9e00b5aa82db1e84547" - } - """ - - schema = ManualSchema(fields=[ - coreapi.Field( - name='file_hash', - required=True, - location='form', - schema=coreschema.String(), - description='El hash del archivo encodeado en sha256', - - ), + schema = ManualSchema(description='Permite realizar el stamp de un archivo sha256', + fields=[ + coreapi.Field( + 'json', + required=True, + location='body', + schema=coreschema.String( + title='json', + description='Parámetros:<br><ul><li>file_hash: El hash del archivo encodeado en sha256</li></ul><br> Ejemplo: <pre>{"file_hash": "1957db7fe23e4be1740ddeb941ddda7ae0a6b782e536a9e00b5aa82db1e84547"}', default='{"file_hash": "1957db7fe23e4be1740ddeb941ddda7ae0a6b782e536a9e00b5aa82db1e84547"}</pre>'), + ), ]) def post(self, request): + try: if not request.data.get('file_hash'): raise ValidationError('file_hash') @@ -87,20 +74,14 @@ class Verify(APIView): } """ - schema = ManualSchema(fields=[ - coreapi.Field( - name='file_hash', - required=True, - location='form', - schema=coreschema.String(), - description='El hash del archivo encodeado en sha256', - ), coreapi.Field( - name='ots', - required=True, - location='form', - schema=coreschema.String(), - description='El OTS recibido al hacer el stamp del archivo encodeado en sha256', - ) + schema = ManualSchema(description='Permite verificar que un archivo fue subido a la Blockchain', + fields=[ + coreapi.Field( + name='json', + required=True, + location='body', + schema=coreschema.String(description='Parámetros:<br><ul><li>file_hash: El hash del archivo encodeado en sha256</li><li>ots: OTS (Temporal o definitivo) recibido como prueba al momento de realizar el stamp o el verify</li></ul><br>Ejemplo:<br> <pre>{"file_hash": "1957db7fe23e4be1740ddeb941ddda7ae0a6b782e536a9e00b5aa82db1e84547","ots": "MHgtZWViNzJhMzYxZmU3NWMyNDA4Y2VmYjU1NDZkNTRkMDYzNWJmOTA5MmNkNmFkNTYxMjQ4YzFlZjNjZTJkMzQ4NDAxLTB4OTAyMDdiZTI5OTExMGJmZGFhYTliZDI1Zjg5ZTdiYTNhMmFmM2U0YTIzNmYzYTEzMWVmZWRjYjE4Y2E2YTE2Zg=="}</pre>'), + ), ]) def post(self, request): @@ -177,7 +158,3 @@ class Verify(APIView): except Exception as e: client.captureException() return Response({_('status'): _('failure'), _('messages'): _('operation_failed')}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - - - diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo index 08266c018960074527b9cec8d54e5728feb3257c..35e8dd882e2b928bb7b80a76691ffd7582894ec6 100644 Binary files a/locale/en/LC_MESSAGES/django.mo and b/locale/en/LC_MESSAGES/django.mo differ diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 7440447c3a45bb6e3c10462a3fde77aba925cec3..bf94172e4767b16eddc36eeea58898fe235f6fea 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 15:08-0300\n" +"POT-Creation-Date: 2018-09-03 12:22-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -17,17 +17,17 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: TsaApi/settings.py:121 +#: TsaApi/settings.py:120 msgid "Spanish" msgstr "" #: app/views.py:60 app/views.py:63 app/views.py:65 app/views.py:68 -#: app/views.py:144 app/views.py:150 app/views.py:171 app/views.py:176 -#: app/views.py:180 app/views.py:185 app/views.py:187 app/views.py:190 +#: app/views.py:139 app/views.py:145 app/views.py:162 app/views.py:167 +#: app/views.py:171 app/views.py:174 app/views.py:176 app/views.py:179 msgid "status" msgstr "" -#: app/views.py:60 app/views.py:144 app/views.py:171 +#: app/views.py:60 app/views.py:139 app/views.py:162 msgid "success" msgstr "" @@ -35,45 +35,45 @@ msgstr "" msgid "temporary_ots" msgstr "" -#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:150 -#: app/views.py:180 app/views.py:185 app/views.py:187 app/views.py:190 +#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:145 +#: app/views.py:171 app/views.py:174 app/views.py:176 app/views.py:179 msgid "failure" msgstr "" -#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:146 -#: app/views.py:150 app/views.py:171 app/views.py:176 app/views.py:180 -#: app/views.py:185 app/views.py:187 app/views.py:190 +#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:141 +#: app/views.py:145 app/views.py:162 app/views.py:167 app/views.py:171 +#: app/views.py:174 app/views.py:176 app/views.py:179 msgid "messages" msgstr "" -#: app/views.py:63 app/views.py:185 +#: app/views.py:63 app/views.py:174 msgid "parameter_missing" msgstr "" -#: app/views.py:65 app/views.py:187 +#: app/views.py:65 app/views.py:176 msgid "could_not_connect" msgstr "" -#: app/views.py:68 app/views.py:190 +#: app/views.py:68 app/views.py:179 msgid "operation_failed" msgstr "" -#: app/views.py:145 app/views.py:171 +#: app/views.py:140 app/views.py:162 msgid "permanent_ots" msgstr "" -#: app/views.py:146 app/views.py:171 +#: app/views.py:141 app/views.py:162 msgid "file_uploaded" msgstr "" -#: app/views.py:150 app/views.py:180 +#: app/views.py:145 app/views.py:171 msgid "file_not_found" msgstr "" -#: app/views.py:176 +#: app/views.py:167 msgid "pending" msgstr "" -#: app/views.py:176 +#: app/views.py:167 msgid "transaction_pending" msgstr "" diff --git a/locale/es/LC_MESSAGES/django.mo b/locale/es/LC_MESSAGES/django.mo index 65ffac623e60eaa6a9d11a66c990a7e8aa28de4d..49694b2a0a7dec8e57e95995bf94aba3a2bdb18f 100644 Binary files a/locale/es/LC_MESSAGES/django.mo and b/locale/es/LC_MESSAGES/django.mo differ diff --git a/locale/es/LC_MESSAGES/django.po b/locale/es/LC_MESSAGES/django.po index 9f6f22660c8261817f3bf6a03a31fdc616130153..007a4e23587a58fd7a6b1bea5eac406e69d9f170 100644 --- a/locale/es/LC_MESSAGES/django.po +++ b/locale/es/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 15:08-0300\n" +"POT-Creation-Date: 2018-09-03 12:22-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -18,17 +18,17 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: TsaApi/settings.py:121 +#: TsaApi/settings.py:120 msgid "Spanish" msgstr "" #: app/views.py:60 app/views.py:63 app/views.py:65 app/views.py:68 -#: app/views.py:144 app/views.py:150 app/views.py:171 app/views.py:176 -#: app/views.py:180 app/views.py:185 app/views.py:187 app/views.py:190 +#: app/views.py:139 app/views.py:145 app/views.py:162 app/views.py:167 +#: app/views.py:171 app/views.py:174 app/views.py:176 app/views.py:179 msgid "status" msgstr "status" -#: app/views.py:60 app/views.py:144 app/views.py:171 +#: app/views.py:60 app/views.py:139 app/views.py:162 msgid "success" msgstr "success" @@ -36,46 +36,46 @@ msgstr "success" msgid "temporary_ots" msgstr "temporay_ots" -#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:150 -#: app/views.py:180 app/views.py:185 app/views.py:187 app/views.py:190 +#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:145 +#: app/views.py:171 app/views.py:174 app/views.py:176 app/views.py:179 msgid "failure" msgstr "failure" -#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:146 -#: app/views.py:150 app/views.py:171 app/views.py:176 app/views.py:180 -#: app/views.py:185 app/views.py:187 app/views.py:190 +#: app/views.py:63 app/views.py:65 app/views.py:68 app/views.py:141 +#: app/views.py:145 app/views.py:162 app/views.py:167 app/views.py:171 +#: app/views.py:174 app/views.py:176 app/views.py:179 msgid "messages" msgstr "messages" -#: app/views.py:63 app/views.py:185 +#: app/views.py:63 app/views.py:174 msgid "parameter_missing" msgstr "Parámetro faltante: %s" -#: app/views.py:65 app/views.py:187 +#: app/views.py:65 app/views.py:176 msgid "could_not_connect" msgstr "No se pudo conectar a la Blockchain" -#: app/views.py:68 app/views.py:190 +#: app/views.py:68 app/views.py:179 msgid "operation_failed" msgstr "No se pudo realizar la operación" -#: app/views.py:145 app/views.py:171 +#: app/views.py:140 app/views.py:162 msgid "permanent_ots" msgstr "permanent_ots" -#: app/views.py:146 app/views.py:171 +#: app/views.py:141 app/views.py:162 msgid "file_uploaded" msgstr "El archivo %s fue ingresado en el bloque %s el %s" -#: app/views.py:150 app/views.py:180 +#: app/views.py:145 app/views.py:171 msgid "file_not_found" msgstr "No se encontró el archivo" -#: app/views.py:176 +#: app/views.py:167 msgid "pending" msgstr "pending" -#: app/views.py:176 +#: app/views.py:167 msgid "transaction_pending" msgstr "La transacción se encuentra pendiente de subida a la Blockchain"