Skip to content
Snippets Groups Projects
Commit f7754d99 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

New upstream version 0.0.16

parents 580afa12 889d219e
No related branches found
Tags debian/upstream/0.0.16
No related merge requests found
Showing
with 290 additions and 72 deletions
Metadata-Version: 1.0
Metadata-Version: 2.1
Name: swh.deposit
Version: 0.0.15
Version: 0.0.16
Summary: Software Heritage Deposit Server
Home-page: https://forge.softwareheritage.org/source/swh-deposit/
Author: Software Heritage developers
......@@ -8,3 +8,4 @@ Author-email: swh-devel@inria.fr
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Provides-Extra: injection
DEPOSIT_ID=1
ARCHIVE=../../swh-deposit.zip
ARCHIVE2=../../swh-model.zip
STATUS=false
PARTIAL_STATUS=true
UPDATE_STATUS='success'
create-archives:
7z a $(ARCHIVE) $(FOLDER)
7z a $(ARCHIVE2) $(FOLDER2)
new:
./create_deposit.sh $(ARCHIVE) $(STATUS)
new-partial:
make new STATUS=$(PARTIAL_STATUS) ARCHIVE=$(ARCHIVE)
update:
./update-deposit-with-another-archive.sh $(DEPOSIT_ID) $(ARCHIVE_2) $(STATUS)
update-partial:
make update DEPOSIT_ID=$(DEPOSIT_ID) ARCHIVE2=$(ARCHIVE2) STATUS=$(PARTIAL_STATUS)
replace:
./replace-deposit-archive.sh $(ARCHIVE2) $(DEPOSIT_ID)
download:
./download-deposit-archive.sh $(DEPOSIT_ID)
status:
./status.sh $(DEPOSIT_ID)
service-document:
./service-document.sh
home:
./home.sh
update-status:
./update-status.sh $(DEPOSIT_ID) $(UPDATE_STATUS)
......@@ -4,4 +4,4 @@
DEPOSIT_ID=${1-1}
curl -u "$CREDS" ${SERVER}/1/${COLLECTION}/${DEPOSIT_ID}/raw/
curl ${SERVER}/1/${COLLECTION}/${DEPOSIT_ID}/raw/
#!/usr/bin/env bash
. ./default-setup
curl ${SERVER}
echo
#!/usr/bin/env bash
. ./default-setup
DEPOSIT_ID=${1-1}
UPDATE_STATUS=${2-'success'}
curl -i \
-X PUT \
-H 'Content-Type: application/json' \
-d "{\"status\": \"${UPDATE_STATUS}\"}" \
${SERVER}/1/${COLLECTION}/${DEPOSIT_ID}/update/
......@@ -3,18 +3,21 @@ Maintainer: Software Heritage developers <swh-devel@inria.fr>
Section: python
Priority: optional
Build-Depends: debhelper (>= 9),
dh-python,
dh-python (>= 2),
python3-setuptools,
python3-all,
python3-nose,
python3-vcversioner,
python3-swh.core (>= 0.0.14~),
python3-swh.loader.tar (>= 0.0.26~),
python3-swh.loader.core (>= 0.0.19~),
python3-swh.loader.tar (>= 0.0.27~),
python3-swh.scheduler (>= 0.0.17~),
python3-django,
python3-click,
python3-vcversioner,
python3-djangorestframework,
python3-djangorestframework-xml
python3-djangorestframework-xml,
python3-requests
Standards-Version: 3.9.6
Homepage: https://forge.softwareheritage.org/source/swh-deposit/
......@@ -22,5 +25,16 @@ Package: python3-swh.deposit
Architecture: all
Depends: python3-swh.core (>= 0.0.14~),
python3-swh.loader.tar (>= 0.0.26~),
python3-swh.scheduler (>= 0.0.17~),
${misc:Depends}, ${python3:Depends}
Description: Software Heritage Deposit Server
Package: python3-swh.deposit.injection
Architecture: all
Depends: python3-swh.core (>= 0.0.14~),
python3-swh.loader.core (>= 0.0.19~),
python3-swh.loader.tar (>= 0.0.26~),
python3-swh.scheduler (>= 0.0.17~),
python3-requests,
${misc:Depends}, ${python3:Depends}
Description: Software Heritage Deposit Injection
#!/usr/bin/make -f
export PYBUILD_NAME=swh-deposit
export PYBUILD_NAME=swh.deposit
export PYBUILD_TEST_ARGS=--with-doctest -sv -a !db,!fs
%:
dh $@ --with python3 --buildsystem=pybuild
override_dh_install:
dh_install
rm -v $(CURDIR)/debian/python3-*/usr/lib/python*/dist-packages/swh/__init__.py
for pyvers in $(shell py3versions -vr); do \
mkdir -p $(CURDIR)/debian/python3-swh.deposit.injection/usr/lib/python$$pyvers/dist-packages/swh/deposit/injection ; \
mv $(CURDIR)/debian/python3-swh.deposit/usr/lib/python$$pyvers/dist-packages/swh/deposit/injection/* \
$(CURDIR)/debian/python3-swh.deposit.injection/usr/lib/python$$pyvers/dist-packages/swh/deposit/injection/ ; \
done
override_dh_auto_test:
swh.core >= 0.0.14
swh.loader.tar >= 0.0.26
swh.loader.tar >= 0.0.27
swh.scheduler >= 0.0.17
from setuptools import setup
from setuptools import setup, find_packages
def parse_requirements():
......@@ -19,18 +19,13 @@ setup(
author='Software Heritage developers',
author_email='swh-devel@inria.fr',
url='https://forge.softwareheritage.org/source/swh-deposit/',
packages=['swh.deposit',
'swh.deposit.api',
'swh.deposit.fixtures',
'swh.deposit.migrations',
'swh.deposit.scheduler',
'swh.deposit.settings',
'swh.deposit.static',
'swh.deposit.templates',
'swh.deposit.templates.deposit',
'swh.deposit.tests'],
packages=find_packages(),
scripts=[], # scripts to package
install_requires=parse_requirements(),
extras_require={
'injection': ['swh.loader.core >= 0.0.19',
'requests'],
},
setup_requires=['vcversioner'],
vcversioner={},
include_package_data=True,
......
Metadata-Version: 1.0
Metadata-Version: 2.1
Name: swh.deposit
Version: 0.0.15
Version: 0.0.16
Summary: Software Heritage Deposit Server
Home-page: https://forge.softwareheritage.org/source/swh-deposit/
Author: Software Heritage developers
......@@ -8,3 +8,4 @@ Author-email: swh-devel@inria.fr
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Provides-Extra: injection
......@@ -13,14 +13,17 @@ requirements-swh.txt
requirements.txt
setup.py
version.txt
bin/Makefile
bin/create_deposit.sh
bin/create_deposit_with_metadata.sh
bin/default-setup
bin/download-deposit-archive.sh
bin/home.sh
bin/replace-deposit-archive.sh
bin/service-document.sh
bin/status.sh
bin/update-deposit-with-another-archive.sh
bin/update-status.sh
debian/changelog
debian/compat
debian/control
......@@ -37,6 +40,7 @@ docs/images/deposit-create-chart.png
docs/images/deposit-delete-chart.png
docs/images/deposit-update-chart.png
resources/deposit/server.yml
swh/__init__.py
swh/manage.py
swh.deposit.egg-info/PKG-INFO
swh.deposit.egg-info/SOURCES.txt
......@@ -44,7 +48,6 @@ swh.deposit.egg-info/dependency_links.txt
swh.deposit.egg-info/requires.txt
swh.deposit.egg-info/top_level.txt
swh/deposit/__init__.py
swh/deposit/admin.py
swh/deposit/apps.py
swh/deposit/auth.py
swh/deposit/config.py
......@@ -57,12 +60,17 @@ swh/deposit/wsgi.py
swh/deposit/api/common.py
swh/deposit/api/deposit.py
swh/deposit/api/deposit_content.py
swh/deposit/api/deposit_read.py
swh/deposit/api/deposit_status.py
swh/deposit/api/deposit_update.py
swh/deposit/api/service_document.py
swh/deposit/api/urls.py
swh/deposit/api/private/deposit_read.py
swh/deposit/api/private/deposit_update_status.py
swh/deposit/fixtures/__init__.py
swh/deposit/fixtures/deposit_data.yaml
swh/deposit/injection/__init__.py
swh/deposit/injection/loader.py
swh/deposit/injection/tasks.py
swh/deposit/migrations/0001_initial.py
swh/deposit/migrations/0002_depositrequest_archive.py
swh/deposit/migrations/0003_temporaryarchive.py
......@@ -94,4 +102,5 @@ swh/deposit/tests/api/test_deposit_delete.py
swh/deposit/tests/api/test_deposit_multipart.py
swh/deposit/tests/api/test_deposit_status.py
swh/deposit/tests/api/test_deposit_update.py
swh/deposit/tests/api/test_deposit_update_status.py
swh/deposit/tests/api/test_service_document.py
\ No newline at end of file
......@@ -4,5 +4,10 @@ djangorestframework
djangorestframework-xml
retrying
swh.core>=0.0.14
swh.loader.tar>=0.0.26
swh.loader.tar>=0.0.27
swh.scheduler>=0.0.17
vcversioner
[injection]
requests
swh.loader.core>=0.0.19
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
# Copyright (C) 2017 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from django.contrib import admin
from .models import Deposit, DepositCollection, DepositRequestType
from .models import DepositClient
admin.site.register(DepositClient)
admin.site.register(Deposit)
admin.site.register(DepositCollection)
admin.site.register(DepositRequestType)
......@@ -14,6 +14,7 @@ from django.shortcuts import render
from django.utils import timezone
from rest_framework import status
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated, AllowAny
from ..config import SWHDefaultConfig, EDIT_SE_IRI, EM_IRI, CONT_FILE_IRI
from ..config import ARCHIVE_KEY, METADATA_KEY
......@@ -30,16 +31,20 @@ ACCEPT_PACKAGINGS = ['http://purl.org/net/sword/package/SimpleZip']
ACCEPT_CONTENT_TYPES = ['application/zip']
def index(req):
return HttpResponse('SWH Deposit API')
class SWHAPIView(APIView):
"""Mixin intended as a based API view to enforce the basic
authentication check
"""
pass
permission_classes = (IsAuthenticated, )
class SWHPrivateAPIView(SWHAPIView):
"""Mixin intended as private api (so no authentication) based API view
(for the private ones).
"""
permission_classes = (AllowAny, )
class SWHBaseDeposit(SWHDefaultConfig, SWHAPIView, metaclass=ABCMeta):
......@@ -589,7 +594,16 @@ class SWHBaseDeposit(SWHDefaultConfig, SWHAPIView, metaclass=ABCMeta):
args=[collection_name, deposit_id]),
}
def _primary_input_checks(self, req, collection_name, deposit_id=None):
def additional_checks(self, req, collection_name, deposit_id=None):
"""Permit the child class to enrich with additional checks.
Returns:
dict with 'error' detailing the problem.
"""
return {}
def checks(self, req, collection_name, deposit_id=None):
try:
self._collection = DepositCollection.objects.get(
name=collection_name)
......@@ -598,17 +612,19 @@ class SWHBaseDeposit(SWHDefaultConfig, SWHAPIView, metaclass=ABCMeta):
NOT_FOUND,
'Unknown collection name %s' % collection_name)
try:
username = req.user.username
self._client = DepositClient.objects.get(username=username)
except DepositClient.DoesNotExist:
return make_error_dict(NOT_FOUND,
'Unknown client name %s' % username)
username = req.user.username
if username: # unauthenticated request can have the username empty
try:
self._client = DepositClient.objects.get(username=username)
except DepositClient.DoesNotExist:
return make_error_dict(NOT_FOUND,
'Unknown client name %s' % username)
if self._collection.id not in self._client.collections:
return make_error_dict(FORBIDDEN,
'Client %s cannot access collection %s' % (
username, collection_name))
if self._collection.id not in self._client.collections:
return make_error_dict(
FORBIDDEN,
'Client %s cannot access collection %s' % (
username, collection_name))
if deposit_id:
try:
......@@ -619,20 +635,30 @@ class SWHBaseDeposit(SWHDefaultConfig, SWHAPIView, metaclass=ABCMeta):
'Deposit with id %s does not exist' %
deposit_id)
if req.method != 'GET' and deposit.status != 'partial':
summary = "You can only act on deposit with status 'partial'"
description = "This deposit has status '%s'" % deposit.status
return make_error_dict(
BAD_REQUEST, summary=summary,
verbose_description=description)
checks = self.restrict_access(req, deposit)
if checks:
return checks
headers = self._read_headers(req)
if headers['on-behalf-of']:
return make_error_dict(MEDIATION_NOT_ALLOWED,
'Mediation is not supported.')
checks = self.additional_checks(req, collection_name, deposit_id)
if 'error' in checks:
return checks
return {'headers': headers}
def restrict_access(self, req, deposit=None):
if deposit:
if req.method != 'GET' and deposit.status != 'partial':
summary = "You can only act on deposit with status 'partial'"
description = "This deposit has status '%s'" % deposit.status
return make_error_dict(
BAD_REQUEST, summary=summary,
verbose_description=description)
def get(self, req, *args, **kwargs):
return make_error_response(req, METHOD_NOT_ALLOWED)
......@@ -659,7 +685,7 @@ class SWHGetDepositAPI(SWHBaseDeposit, metaclass=ABCMeta):
404 if the deposit or the collection does not exist
"""
checks = self._primary_input_checks(req, collection_name, deposit_id)
checks = self.checks(req, collection_name, deposit_id)
if 'error' in checks:
return make_error_response_from_dict(req, checks['error'])
......@@ -693,7 +719,7 @@ class SWHPostDepositAPI(SWHBaseDeposit, metaclass=ABCMeta):
"""
checks = self._primary_input_checks(req, collection_name, deposit_id)
checks = self.checks(req, collection_name, deposit_id)
if 'error' in checks:
return make_error_response_from_dict(req, checks['error'])
......@@ -741,7 +767,7 @@ class SWHPutDepositAPI(SWHBaseDeposit, metaclass=ABCMeta):
400 if the deposit does not belong to the collection
404 if the deposit or the collection does not exist
"""
checks = self._primary_input_checks(req, collection_name, deposit_id)
checks = self.checks(req, collection_name, deposit_id)
if 'error' in checks:
return make_error_response_from_dict(req, checks['error'])
......@@ -778,7 +804,7 @@ class SWHDeleteDepositAPI(SWHBaseDeposit, metaclass=ABCMeta):
404 if the deposit or the collection does not exist
"""
checks = self._primary_input_checks(req, collection_name, deposit_id)
checks = self.checks(req, collection_name, deposit_id)
if 'error' in checks:
return make_error_response_from_dict(req, checks['error'])
......
......@@ -14,7 +14,7 @@ from ..models import DEPOSIT_STATUS_DETAIL, Deposit, DepositRequest
class SWHDepositContent(SWHBaseDeposit):
def get(self, req, collection_name, deposit_id, format=None):
checks = self._primary_input_checks(req, collection_name, deposit_id)
checks = self.checks(req, collection_name, deposit_id)
if 'error' in checks:
return make_error_response_from_dict(req, checks['error'])
......
......@@ -21,7 +21,7 @@ class SWHDepositStatus(SWHBaseDeposit):
"""
def get(self, req, collection_name, deposit_id, format=None):
checks = self._primary_input_checks(req, collection_name, deposit_id)
checks = self.checks(req, collection_name, deposit_id)
if 'error' in checks:
return make_error_response_from_dict(req, checks['error'])
......
......@@ -4,10 +4,12 @@
# See top-level LICENSE file for more information
from rest_framework import status
from rest_framework.parsers import JSONParser
from .common import SWHPostDepositAPI, SWHPutDepositAPI, SWHDeleteDepositAPI
from ..config import CONT_FILE_IRI, EDIT_SE_IRI, EM_IRI
from ..errors import make_error_response, BAD_REQUEST
from ..errors import make_error_response, make_error_dict, BAD_REQUEST
from ..models import Deposit, DEPOSIT_STATUS_DETAIL
from ..parsers import SWHFileUploadParser, SWHAtomEntryParser
from ..parsers import SWHMultiPartParser
......@@ -153,3 +155,42 @@ class SWHUpdateMetadataDeposit(SWHPostDepositAPI, SWHPutDepositAPI,
#protocoloperations_deleteconteiner
"""
return self._delete_deposit(collection_name, deposit_id)
class SWHUpdateStatusDeposit(SWHPutDepositAPI):
"""Deposit request class to update the deposit's status.
HTTP verbs supported: PUT
"""
parser_classes = (JSONParser, )
def restrict_access(self, req, deposit=None):
"""Remove restriction modification to 'partial' deposit.
Update is possible regardless of the existing status.
"""
return None
def process_put(self, req, headers, collection_name, deposit_id):
"""Update the deposit's status
Returns:
204 No content
"""
status = req.data.get('status')
if not status:
msg = 'The status key is mandatory with possible values %s' % list(
DEPOSIT_STATUS_DETAIL.keys())
return make_error_dict(BAD_REQUEST, msg)
if status not in DEPOSIT_STATUS_DETAIL:
msg = 'Possible status in %s' % list(DEPOSIT_STATUS_DETAIL.keys())
return make_error_dict(BAD_REQUEST, msg)
deposit = Deposit.objects.get(pk=deposit_id)
deposit.status = status
deposit.save()
return {}
......@@ -10,8 +10,9 @@ import tempfile
from rest_framework import status
from swh.loader.tar import tarball
from .common import SWHGetDepositAPI
from ..models import Deposit, DepositRequest, TemporaryArchive
from ..common import SWHGetDepositAPI, SWHPrivateAPIView
from ...models import Deposit, DepositRequest, TemporaryArchive
def aggregate_tarballs(extraction_dir, archive_paths):
......@@ -70,11 +71,10 @@ def stream_content(tarpath):
raise ValueError('Development error: %s should exist' % tarpath)
with open(tarpath, 'rb') as f:
for chunk in f:
yield chunk
yield from f
class SWHDepositReadArchives(SWHGetDepositAPI):
class SWHDepositReadArchives(SWHGetDepositAPI, SWHPrivateAPIView):
"""Dedicated class to read a deposit's raw archives content.
Only GET is supported.
......
# Copyright (C) 2017 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from rest_framework.parsers import JSONParser
from ..common import SWHPutDepositAPI, SWHPrivateAPIView
from ...errors import make_error_dict, BAD_REQUEST
from ...models import Deposit, DEPOSIT_STATUS_DETAIL, format_swh_id
class SWHUpdateStatusDeposit(SWHPutDepositAPI, SWHPrivateAPIView):
"""Deposit request class to update the deposit's status.
HTTP verbs supported: PUT
"""
parser_classes = (JSONParser, )
def additional_checks(self, req, collection_name, deposit_id=None):
"""Enrich existing checks to the default ones.
New checks:
- Ensure the status is provided
- Ensure it exists
"""
data = req.data
status = data.get('status')
if not status:
msg = 'The status key is mandatory with possible values %s' % list(
DEPOSIT_STATUS_DETAIL.keys())
return make_error_dict(BAD_REQUEST, msg)
if status not in DEPOSIT_STATUS_DETAIL:
msg = 'Possible status in %s' % list(DEPOSIT_STATUS_DETAIL.keys())
return make_error_dict(BAD_REQUEST, msg)
if status == 'success':
swh_id = data.get('revision_id')
if not swh_id:
msg = 'Updating status to %s requires a revision_id key' % (
status, )
return make_error_dict(BAD_REQUEST, msg)
return {}
def restrict_access(self, req, deposit=None):
"""Remove restriction modification to 'partial' deposit.
Update is possible regardless of the existing status.
"""
return None
def process_put(self, req, headers, collection_name, deposit_id):
"""Update the deposit's status
Returns:
204 No content
"""
deposit = Deposit.objects.get(pk=deposit_id)
deposit.status = req.data['status'] # checks already done before
swh_id = req.data.get('revision_id')
if swh_id:
deposit.swh_id = format_swh_id(collection_name, swh_id)
deposit.save()
return {}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment