|
3 | 3 | import json |
4 | 4 | import re |
5 | 5 | import requests |
| 6 | +from requests_toolbelt.multipart.encoder import MultipartEncoder |
6 | 7 | import time |
7 | 8 |
|
8 | 9 | try: |
@@ -54,23 +55,6 @@ def add_image(self, image, force=False, dockerfile=None, annotations={}, autosub |
54 | 55 |
|
55 | 56 | return [True, res.json()] |
56 | 57 |
|
57 | | - def import_image(self, image_data): |
58 | | - '''**Description** |
59 | | - Import an image from the scanner export |
60 | | -
|
61 | | - **Arguments** |
62 | | - - image_data: A JSON with the image information. |
63 | | -
|
64 | | - **Success Return Value** |
65 | | - A JSON object representing the image that was imported. |
66 | | - ''' |
67 | | - url = self.url + "/api/scanning/v1/anchore/imageimport" |
68 | | - res = requests.post(url, data=json.dumps(image_data), headers=self.hdrs, verify=self.ssl_verify) |
69 | | - if not self._checkResponse(res): |
70 | | - return [False, self.lasterr] |
71 | | - |
72 | | - return [True, res.json()] |
73 | | - |
74 | 58 | def get_image(self, image, show_history=False): |
75 | 59 | '''**Description** |
76 | 60 | Find the image with the tag <image> and return its json description |
@@ -323,6 +307,49 @@ def get_pdf_report(self, image, tag=None, date=None): |
323 | 307 |
|
324 | 308 | return [True, res.content] |
325 | 309 |
|
| 310 | + def import_image(self, infile): |
| 311 | + '''**Description** |
| 312 | + Import an image archive |
| 313 | +
|
| 314 | + **Arguments** |
| 315 | + - infile: An image archive file |
| 316 | +
|
| 317 | + **Success Return Value** |
| 318 | + A JSON object representing the image that was imported. |
| 319 | + ''' |
| 320 | + try: |
| 321 | + m = MultipartEncoder( |
| 322 | + fields={'archive_file': (infile, open(infile, 'rb'), 'text/plain')} |
| 323 | + ) |
| 324 | + url = self.url+"/api/scanning/v1/import/images" |
| 325 | + |
| 326 | + headers = {'Authorization': 'Bearer ' + self.token, 'Content-Type': m.content_type} |
| 327 | + res = requests.post(url, data=m, headers=headers) |
| 328 | + if not self._checkResponse(res): |
| 329 | + return [False, self.lasterr] |
| 330 | + |
| 331 | + return [True, res.json()] |
| 332 | + |
| 333 | + except Exception as err: |
| 334 | + print(err) |
| 335 | + |
| 336 | + def get_anchore_users_account(self): |
| 337 | + '''**Description** |
| 338 | + Get the anchore user account. |
| 339 | +
|
| 340 | + **Arguments** |
| 341 | + - None |
| 342 | +
|
| 343 | + **Success Return Value** |
| 344 | + A JSON object containing user account information. |
| 345 | + ''' |
| 346 | + url = self.url + "/api/scanning/v1/anchore/account" |
| 347 | + res = requests.get(url, headers=self.hdrs, verify=self.ssl_verify) |
| 348 | + if not self._checkResponse(res): |
| 349 | + return [False, self.lasterr] |
| 350 | + |
| 351 | + return [True, res.json()] |
| 352 | + |
326 | 353 | def add_registry(self, registry, registry_user, registry_pass, insecure=False, registry_type="docker_v2", validate=True): |
327 | 354 | '''**Description** |
328 | 355 | Add image registry |
|
0 commit comments