diff --git a/swh/web/api/utils.py b/swh/web/api/utils.py --- a/swh/web/api/utils.py +++ b/swh/web/api/utils.py @@ -164,9 +164,12 @@ - filetype_url: its filetype information """ + checksums = content + if 'checksums' in content: + checksums = content['checksums'] for h in ['sha1', 'sha1_git', 'sha256']: - if h in content: - q = '%s:%s' % (h, content[h]) + if h in checksums: + q = '%s:%s' % (h, checksums[h]) if top_url: content['content_url'] = reverse('content', kwargs={'q': q}) content['data_url'] = reverse('content-raw', kwargs={'q': q}) diff --git a/swh/web/common/service.py b/swh/web/common/service.py --- a/swh/web/common/service.py +++ b/swh/web/common/service.py @@ -651,6 +651,14 @@ """ algo, hash = query.parse_hash(q) c = storage.content_find({algo: hash}) + if c: + # group all computed content checksums in a dictionnary + checksums = {} + for hash in ['sha1', 'sha1_git', 'sha256', 'blake2s256']: + if hash in c: + checksums[hash] = c[hash] + del c[hash] + c['checksums'] = checksums return converters.from_content(c) diff --git a/swh/web/tests/api/views/test_content.py b/swh/web/tests/api/views/test_content.py --- a/swh/web/tests/api/views/test_content.py +++ b/swh/web/tests/api/views/test_content.py @@ -384,10 +384,12 @@ def api_content_metadata(self, mock_service): # given mock_service.lookup_content.return_value = { - 'sha1': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', - 'sha1_git': 'b4e8f472ffcb01a03875b26e462eb568739f6882', - 'sha256': '83c0e67cc80f60caf1fcbec2d84b0ccd7968b3be4735637006560' - 'cde9b067a4f', + 'checksums': { + 'sha1': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', + 'sha1_git': 'b4e8f472ffcb01a03875b26e462eb568739f6882', + 'sha256': '83c0e67cc80f60caf1fcbec2d84b0ccd7968b3be47' + '35637006560cde9b067a4f', + }, 'length': 17, 'status': 'visible' } @@ -399,6 +401,12 @@ self.assertEquals(rv.status_code, 200) self.assertEquals(rv['Content-Type'], 'application/json') self.assertEquals(rv.data, { + 'checksums': { + 'sha1': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', + 'sha1_git': 'b4e8f472ffcb01a03875b26e462eb568739f6882', + 'sha256': '83c0e67cc80f60caf1fcbec2d84b0ccd7968b3be47' + '35637006560cde9b067a4f', + }, 'data_url': '/api/1/content/' 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03/raw/', 'filetype_url': '/api/1/content/' @@ -407,10 +415,6 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03/language/', 'license_url': '/api/1/content/' 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03/license/', - 'sha1': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', - 'sha1_git': 'b4e8f472ffcb01a03875b26e462eb568739f6882', - 'sha256': '83c0e67cc80f60caf1fcbec2d84b0ccd7968b3be4735637006560c' - 'de9b067a4f', 'length': 17, 'status': 'visible' }) diff --git a/swh/web/tests/common/test_service.py b/swh/web/tests/common/test_service.py --- a/swh/web/tests/common/test_service.py +++ b/swh/web/tests/common/test_service.py @@ -84,9 +84,11 @@ } self.SAMPLE_CONTENT = { - 'sha1': self.SHA1_SAMPLE, - 'sha256': self.SHA256_SAMPLE, - 'sha1_git': self.SHA1GIT_SAMPLE, + 'checksums': { + 'sha1': self.SHA1_SAMPLE, + 'sha256': self.SHA256_SAMPLE, + 'sha1_git': self.SHA1GIT_SAMPLE, + }, 'length': 190, 'status': 'absent' }