Skip to content

Commit

Permalink
add flag to image_name_extractor to return short image name (#3622)
Browse files Browse the repository at this point in the history
* add flag to image_name_extractor to return short img name

* Address review comment
  • Loading branch information
hkaj committed Jan 8, 2018
1 parent a8d6a47 commit cbebaf6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/dockerutil.py
Expand Up @@ -573,15 +573,19 @@ def image_tag_extractor(self, entity, key):

return None

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

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

0 comments on commit cbebaf6

Please sign in to comment.