コード例 #1
0
    def delete(self, userId, bucket, archiveid):
        if not self.archive_clients:
            raise Exception("archive not initialized")

        try:
            url = None
            with session_scope() as dbsession:
                meta = db_archivemetadata.get(userId,
                                              bucket,
                                              archiveid,
                                              session=dbsession)
                if meta:
                    url = meta.get("content_url")
                    db_archivemetadata.delete(userId,
                                              bucket,
                                              archiveid,
                                              session=dbsession)

            # Remove the data itself. Can result in orphaned data if system fails here but better than deleting the content but not the meta, leaving a confused state.
            if url:
                scheme = urllib.parse.urlparse(url).scheme
                if scheme in self.archive_clients:
                    return self.archive_clients[scheme].delete(
                        userId, bucket, archiveid)
                else:
                    logger.warn(
                        "Deleting archive document {}/{}/{}, but found no content url for backend delete so skipping backend operation"
                        .format(userId, bucket, archiveid))
            return url is not None

        except Exception as err:
            raise err
コード例 #2
0
    def get(self, userId, bucket, archiveid):
        if not self.archive_clients:
            raise Exception("archive not initialized")

        try:
            with session_scope() as dbsession:
                result = db_archivemetadata.get(
                    userId, bucket, archiveid, session=dbsession
                )
                if not result:
                    return None

            url = result.get("content_url")
            if url is None:
                raise Exception(
                    "Null reference url for valid metadata record for {}/{}/{}".format(
                        userId, bucket, archiveid
                    )
                )
            else:

                is_compressed = result.get("is_compressed", False)
                expected = result.get("digest")

                # get the raw data from driver, note content is bytes (not str)
                content = self._client_for(url).get_by_uri(url)
                found_size = len(content)

                if expected:
                    found = hashlib.md5(content).hexdigest()
                else:
                    found = None

                if expected and found != expected:
                    logger.error(
                        "Digest mismatch:\nDB Record: {}\nContent digest: {}\n, Content size: {}".format(
                            result, found, found_size, content
                        )
                    )
                    raise Exception(
                        "Detected digest mismatch on content fetch from backend. Expected: {}, Got: {}".format(
                            expected, found
                        )
                    )

                content = self._do_decompress(is_compressed, content)

            return content

        except Exception as err:
            import traceback

            traceback.print_exc()
            logger.debug("cannot get data: exception - " + str(err))
            raise err
コード例 #3
0
    def get_document_meta(self, userId, bucket, archiveId):
        if not self.archive_clients:
            raise Exception("archive not initialized")

        with session_scope() as dbsession:
            ret = db_archivemetadata.get(userId,
                                         bucket,
                                         archiveId,
                                         session=dbsession)

        return (ret)
コード例 #4
0
ファイル: manager.py プロジェクト: tsprasath/anchore-engine
    def get_document_meta(self, userId, bucket, archiveId):
        """
        Return the metadata for the doc, or None if not found

        :param userId:
        :param bucket:
        :param archiveId:
        :return:
        """
        if not self.archive_clients:
            raise Exception("archive not initialized")

        with session_scope() as dbsession:
            ret = db_archivemetadata.get(userId, bucket, archiveId, session=dbsession)
            if ret is None:
                return None
            else:
                return ret