Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def wait(input_image, timeout, interval):
"""
Wait for an image to go to analyzed or analysis_failed status with a specific timeout
:param input_image:
:param timeout:
:return:
"""
ecode = 0
try:
itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
image = input_image
#timeout = float(timeout)
t1 = time.time()
while timeout < 0 or time.time() - t1 < timeout:
_logger.debug("discovery from input: " + str(itype) + " : " + str(image))
if itype == 'tag':
ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=False)
elif itype == 'imageid':
ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
elif itype == 'imageDigest':
ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
else:
ecode = 1
raise Exception("cannot use input image string: no discovered imageDigest")
if ret['payload'] and ret['payload'][0]['analysis_status'] in ['analyzed', 'analysis_failed']:
def add(input_image, force, dockerfile, annotation, noautosubscribe):
"""
INPUT_IMAGE: Input image can be in the following formats: registry/repo:tag
"""
ecode = 0
try:
itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
dockerfile_contents = None
if dockerfile:
with open(dockerfile, 'r') as FH:
dockerfile_contents = base64.b64encode(FH.read().encode('utf-8')).decode('utf-8')
autosubscribe = not noautosubscribe
if itype == 'tag':
annotations = {}
if annotation:
for a in annotation:
try:
(k,v) = a.split('=', 1)
if k and v:
annotations[k] = v
def get(input_image, show_history):
"""
INPUT_IMAGE: Input image can be in the following formats: Image Digest, ImageID or registry/repo:tag
"""
ecode = 0
try:
itype = anchorecli.cli.utils.discover_inputimage_format(config, input_image)
image = input_image
_logger.debug("discovery from input: " + str(itype) + " : " + str(image))
if itype == 'tag':
ret = anchorecli.clients.apiexternal.get_image(config, tag=image, history=show_history)
elif itype == 'imageid':
ret = anchorecli.clients.apiexternal.get_image(config, image_id=image, history=False)
elif itype == 'imageDigest':
ret = anchorecli.clients.apiexternal.get_image(config, imageDigest=image, history=False)
else:
ecode = 1
raise Exception("cannot use input image string: no discovered imageDigest")
if ret:
ecode = anchorecli.cli.utils.get_ecode(ret)
if ret['success']: