Skip to content

Commit 2d00380

Browse files
marojorDavide Schiera
authored andcommitted
Add support for importing images asynchronously (#111)
1 parent 83fadab commit 2d00380

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sdcclient/_scanning.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,33 @@ def get_pdf_report(self, image, tag=None, date=None):
307307

308308
return [True, res.content]
309309

310-
def import_image(self, infile):
310+
def import_image(self, infile, sync=True):
311311
'''**Description**
312312
Import an image archive
313313
314314
**Arguments**
315315
- infile: An image archive file
316+
- sync: Whether the import should be synchronous or asynchronous
316317
317318
**Success Return Value**
318-
A JSON object representing the image that was imported.
319+
If synchronous, A JSON object representing the image that was imported.
320+
319321
'''
320322
try:
321323
m = MultipartEncoder(
322324
fields={'archive_file': (infile, open(infile, 'rb'), 'text/plain')}
323325
)
324-
url = self.url + "/api/scanning/v1/anchore/import/images"
326+
if sync:
327+
url = self.url + "/api/scanning/v1/anchore/import/images"
328+
else:
329+
url = self.url + "/api/scanning/v1/import/images"
325330

326331
headers = {'Authorization': 'Bearer ' + self.token, 'Content-Type': m.content_type}
327332
res = requests.post(url, data=m, headers=headers, verify=self.ssl_verify)
328333
if not self._checkResponse(res):
329334
return [False, self.lasterr]
330335

331-
return [True, res.json()]
336+
return [True, res.json() if sync else res.content]
332337

333338
except Exception as err:
334339
print(err)

0 commit comments

Comments
 (0)