How to use the conan.utils.sha256_digest function in conan

To help you get started, we’ve selected a few conan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nexB / conan / src / conan / image_v11.py View on Github external
image.tags = image_config.get('RepoTags') or []
            for tag in image.tags:
                self.image_id_by_tags[tag] = image.image_id

            image_layers_by_digest = {l.layer_digest: l for l in image.layers}

            layer_paths = image_config.get('Layers') or []
            layers = OrderedDict()
            for lp in layer_paths:
                is_layer_dot_tar = lp.endswith('/layer.tar')
                is_layerid_tar = lp.endswith('.tar') and '/layer.tar' not in lp
                if is_layer_dot_tar:
                    layer_dir = fileutils.parent_directory(lp).strip('/')
                    layer_id = layer_dir
                    layer_dir = join(repo_dir, layer_dir)
                    layer_digest = sha256_digest(join(repo_dir, lp))
                elif is_layerid_tar:
                    layer_id = lp.replace('.tar', '')
                    layer_dir = join(repo_dir, lp)
                    layer_digest = sha256_digest(layer_dir)
                else:
                    raise Exception('Unknown layer layout')

                layer = Layer.load_layer(layer_dir)

                if layer.layer_digest:
                    assert layer.layer_digest == layer_digest
                layers[layer_id] = layer
                self.layers_by_id[layer_id] = layer
                image_layer = image_layers_by_digest.get(layer_digest)
                if image_layer:
                    image_layer.layer_id = layer_id
github nexB / conan / src / conan / image_v11.py View on Github external
# this is in order from bottom-most to top-most
            # each id is the sha256 of a layer.tar
            # NOTE: Empty layer may NOT have their digest listed here, so this list
            # may not align exactly with the history list:
            # e.g. this list only has entries if "empty_layer" is not set to True for that layer.
            'rootfs': {
                'diff_ids': ['sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef',
                             'sha256:2436bc321ced91d2f3052a98ff886a2feed0788eb524b2afeb48099d084c33f5',
                             'sha256:cd141a5beb0ec83004893dfea6ea8508c6d09a0634593c3f35c0d433898c9322',]
                'type': u'layers'
            }
        }
        """

        image_id = fileutils.file_base_name(config_file)
        config_digest = sha256_digest(config_file)
        if image_id != as_bare_id(config_digest):
            print('WARNING: image config digest is not consistent.')
            config_digest = 'sha256' + image_id

        image_config = load_json(config_file)

        # merge "configs"
        ccnf = image_config.pop('container_config', {})
        cnf = image_config.pop('config', {})
        config, warns = merge_configs(ccnf, cnf)

        if warns and verbose:
            print('Warning when loading: %(config_file)r' % locals())

            for w in warns:
                print(w)
github nexB / conan / src / conan / image_v11.py View on Github external
def load_layer(cls, layer_dir, verbose=True):
        """
        Return a Layer object built from layer metadata in the layer_dir.
        Raise an exception on errors.
        """
        if not layer_dir:
            return
        # infer from the directory
        layer_id = fileutils.file_name(layer_dir)
        is_tar = layer_dir.endswith('.tar') and not layer_dir.endswith('/layer.tar')
        if is_tar:
            layer_id = layer_id.replace('.tar', '')
            layer_digest = sha256_digest(layer_dir)
            layer_size = filetype.get_size(layer_dir)
            return Layer(layer_id=layer_id, layer_digest=layer_digest, layer_size=layer_size)

        if not isdir(layer_dir):
            return Layer(layer_id=layer_id)

        files = listdir(layer_dir)

        assert files
        logger_debug('load_layer: Layer files: ', files, 'layer_dir: ', layer_dir)

        # check that all the files we expect to be in the layer dir are present note:
        # we ignore any other files (such as extracted tars, etc)
        if LAYER_VERSION_FILE in files:
            layer_format_version_file = join(layer_dir, LAYER_VERSION_FILE)
            supported_format_version = cls.format_version
github nexB / conan / src / conan / image_v11.py View on Github external
else:
            print('Missing layer VERSION for:', layer_dir)

        if not LAYER_JSON_FILE in files:
            print('Missing layer json for:', layer_dir)
            return Layer(layer_id=layer_id)

        # load data
        with open(join(layer_dir, LAYER_JSON_FILE)) as layer_json:
            layer_data = json.load(layer_json, object_pairs_hook=OrderedDict)

        # Note: it is possible to have an EMPTY layer.tar that is a link to another
        # non-empty layer.tar
        if LAYER_TAR_FILE in files:
            layer_tar = join(layer_dir, LAYER_TAR_FILE)
            layer_digest = sha256_digest(layer_tar)
            layer_size = filetype.get_size(layer_tar)
        else:
            layer_digest = None
            layer_size = 0

        # do not rely on this
        if 'Size' in layer_data:
            del layer_data['Size']

        # do not rely on this
        if 'id' in layer_data:
            lid = layer_data.pop('id')
            # make some basic checks
            assert layer_id == lid
github nexB / conan / src / conan / image_v11.py View on Github external
image_layers_by_digest = {l.layer_digest: l for l in image.layers}

            layer_paths = image_config.get('Layers') or []
            layers = OrderedDict()
            for lp in layer_paths:
                is_layer_dot_tar = lp.endswith('/layer.tar')
                is_layerid_tar = lp.endswith('.tar') and '/layer.tar' not in lp
                if is_layer_dot_tar:
                    layer_dir = fileutils.parent_directory(lp).strip('/')
                    layer_id = layer_dir
                    layer_dir = join(repo_dir, layer_dir)
                    layer_digest = sha256_digest(join(repo_dir, lp))
                elif is_layerid_tar:
                    layer_id = lp.replace('.tar', '')
                    layer_dir = join(repo_dir, lp)
                    layer_digest = sha256_digest(layer_dir)
                else:
                    raise Exception('Unknown layer layout')

                layer = Layer.load_layer(layer_dir)

                if layer.layer_digest:
                    assert layer.layer_digest == layer_digest
                layers[layer_id] = layer
                self.layers_by_id[layer_id] = layer
                image_layer = image_layers_by_digest.get(layer_digest)
                if image_layer:
                    image_layer.layer_id = layer_id



            # the last one is the top one