From: tierno Date: Tue, 4 Aug 2020 14:14:16 +0000 (+0000) Subject: fix 1107 allow getting single file package with text/plain X-Git-Tag: release-v9.0-start~25 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=commitdiff_plain;h=ee00275276c75cb1737539b48db33952177ec777 fix 1107 allow getting single file package with text/plain According to SOL005 this should be available if descriptor does not contains artifacts Change-Id: I4def3bdc6193f0a9189eb50e0145a3f60e2f3ca4 Signed-off-by: tierno --- diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index 9113b0c..24f47a9 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -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: