Skip to content

Commit cbebaf6

Browse files
authored
add flag to image_name_extractor to return short image name (#3622)
* add flag to image_name_extractor to return short img name * Address review comment
1 parent a8d6a47 commit cbebaf6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

utils/dockerutil.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,19 @@ def image_tag_extractor(self, entity, key):
573573

574574
return None
575575

576-
def image_name_extractor(self, co):
576+
def image_name_extractor(self, co, short=False):
577577
"""
578578
Returns the image name for a container, either directly from the
579579
container's Image property or by inspecting the image entity if
580580
the reference is its sha256 sum and not its name.
581581
Result is cached for performance, no invalidation planned as image
582582
churn is low on typical hosts.
583+
If short is true, the repository is stripped from the result
583584
"""
584-
return self.image_name_resolver(co.get('Image', ''))
585+
image = self.image_name_resolver(co.get('Image', ''))
586+
if short:
587+
return image.split('/')[-1]
588+
return image
585589

586590
def image_name_resolver(self, image):
587591
if image.startswith('sha256:') or '@sha256:' in image:

0 commit comments

Comments
 (0)