From 175e6852a70eb6711025547d29e9e0441c0f8f3f Mon Sep 17 00:00:00 2001 From: Federico Barcelona Date: Thu, 6 May 2021 19:48:36 +0200 Subject: [PATCH] feat(scanning): Add list all image tags method --- sdcclient/_scanning.py | 13 ++++++++++++ specs/secure/scanning/list_image_tags_spec.py | 20 +++++++++++++++++++ specs/secure/scanning/list_images_spec.py | 19 ++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 specs/secure/scanning/list_image_tags_spec.py create mode 100644 specs/secure/scanning/list_images_spec.py diff --git a/sdcclient/_scanning.py b/sdcclient/_scanning.py index 6a44ce99..149a4d3e 100644 --- a/sdcclient/_scanning.py +++ b/sdcclient/_scanning.py @@ -105,6 +105,19 @@ def list_images(self): return [True, res.json()] + def list_image_tags(self): + """ + Lists the current set of image tags in the scanner. + + Returns: A JSON object containing all the image tags. + """ + url = self.url + "/api/scanning/v1/anchore/summaries/imagetags" + res = self.http.get(url, headers=self.hdrs, verify=self.ssl_verify) + if not self._checkResponse(res): + return [False, self.lasterr] + + return [True, res.json()] + def list_whitelisted_cves(self): '''**Description** List the whitelisted global CVEs. diff --git a/specs/secure/scanning/list_image_tags_spec.py b/specs/secure/scanning/list_image_tags_spec.py new file mode 100644 index 00000000..5c0a9631 --- /dev/null +++ b/specs/secure/scanning/list_image_tags_spec.py @@ -0,0 +1,20 @@ +import os + +from expects import expect, contain, have_keys +from mamba import before, description, it + +from sdcclient import SdScanningClient +from specs import be_successful_api_call + +with description("Scanning list_image_tags") as self: + with before.all: + self.client = SdScanningClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"), + token=os.getenv("SDC_SECURE_TOKEN")) + + with it("is able to retrieve all the image tags"): + ok, res = self.client.list_image_tags() + + expect((ok, res)).to(be_successful_api_call) + expect(res).to( + contain(have_keys("analyzed_at", "created_at", "fulltag", "imageDigest", "imageId", "parentDigest", + "tag_detected_at", "analysis_status"))) diff --git a/specs/secure/scanning/list_images_spec.py b/specs/secure/scanning/list_images_spec.py new file mode 100644 index 00000000..7f3e33dc --- /dev/null +++ b/specs/secure/scanning/list_images_spec.py @@ -0,0 +1,19 @@ +import os + +from expects import expect, contain, have_keys +from mamba import before, description, it + +from sdcclient import SdScanningClient +from specs import be_successful_api_call + +with description("Scanning list_images") as self: + with before.all: + self.client = SdScanningClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"), + token=os.getenv("SDC_SECURE_TOKEN")) + with it("is able to list all the scanned images"): + ok, res = self.client.list_images() + + expect((ok, res)).to(be_successful_api_call) + expect(res).to(contain( + have_keys("annotations", "imageDigest", "last_updated", "analysis_status", "image_content", "image_detail", + "image_status", "parentDigest", "userId", "created_at")))