fix 1107 allow getting single file package with text/plain 48/9548/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 4 Aug 2020 14:14:16 +0000 (14:14 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 10 Aug 2020 14:01:45 +0000 (14:01 +0000)
According to SOL005 this should be available if descriptor
does not contains artifacts

Change-Id: I4def3bdc6193f0a9189eb50e0145a3f60e2f3ca4
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_nbi/descriptor_topics.py

index 9113b0c..24f47a9 100644 (file)
@@ -377,10 +377,15 @@ class DescriptorTopic(BaseTopic):
         #                   no   yes     -> error
         # onefile           yes  no      -> zip
         #                   X    yes     -> text
-
-        if accept_text and (not storage.get('pkg-dir') or path == "$DESCRIPTOR"):
+        contain_many_files = False
+        if storage.get('pkg-dir'):
+            # check if there are more than one file in the package, ignoring checksums.txt.
+            pkg_files = self.fs.dir_ls((storage['folder'], storage['pkg-dir']))
+            if len(pkg_files) >= 3 or (len(pkg_files) == 2 and 'checksums.txt' not in pkg_files):
+                contain_many_files = True
+        if accept_text and (not contain_many_files or path == "$DESCRIPTOR"):
             return self.fs.file_open((storage['folder'], storage['descriptor']), "r"), "text/plain"
-        elif storage.get('pkg-dir') and not accept_zip:
+        elif contain_many_files and not accept_zip:
             raise EngineException("Packages that contains several files need to be retrieved with 'application/zip'"
                                   "Accept header", http_code=HTTPStatus.NOT_ACCEPTABLE)
         else: