def test_get_image_with_storage(images, initialized_db): for current in images: storage_uuid = current.storage.uuid with assert_query_count(1): retrieved = image.get_image_with_storage(current.docker_image_id, storage_uuid) assert retrieved.id == current.id assert retrieved.storage.uuid == storage_uuid
def get_matching_tags(docker_image_id, storage_uuid, *args): """ Returns a query pointing to all tags that contain the image with the given docker_image_id and storage_uuid. """ image_row = image.get_image_with_storage(docker_image_id, storage_uuid) if image_row is None: return RepositoryTag.select().where( RepositoryTag.id < 0) # Empty query. ancestors_str = "%s%s/%%" % (image_row.ancestors, image_row.id) return _tag_alive( RepositoryTag.select( *args).distinct().join(Image).join(ImageStorage).where( RepositoryTag.hidden == False).where( (Image.id == image_row.id) | (Image.ancestors**ancestors_str)))
def delete_layer(self, layer): """ Calls DELETE on the given layer in the security scanner, removing it from its database. """ layer_id = compute_layer_id(layer) if layer_id is None: return None # NOTE: We are adding an extra check here for the time being just to be sure we're # not hitting any overlap. docker_image_id, layer_storage_uuid = layer_id.split(".") if get_image_with_storage(docker_image_id, layer_storage_uuid): logger.warning("Found shared Docker ID and storage for layer %s", layer_id) return False try: self._call("DELETE", _API_METHOD_DELETE_LAYER % layer_id) return True except Non200ResponseException: return False except requests.exceptions.RequestException: logger.exception("Failed to delete layer: %s", layer_id) return False