Beispiel #1
0
def package_proxy_relationships(
    db: PartitionedDatabase,
    tx: Transaction,
    config,
    s3,
    file_manifests: List[FileManifest],
) -> Iterator[PackageProxyRelationship]:
    """
    Yield all proxy package relationships in the dataset

    Explodes each proxy package into multiple source files.  If the package no
    longer exists in the dataset, ignore it.
    """

    files_by_package_id: Dict[str, List[FileManifest]] = defaultdict(list)
    for f in file_manifests:
        if f.source_package_id:
            files_by_package_id[f.source_package_id].append(f)

    for pp, record in db.get_all_package_proxies_tx(tx):
        for file_manifest in files_by_package_id.get(pp.package_node_id, []):
            assert file_manifest.id is not None

            yield PackageProxyRelationship(from_=record.id,
                                           to=file_manifest.id,
                                           relationship=pp.relationship_type)
Beispiel #2
0
def get_all_proxy_instances(db: PartitionedDatabase,
                            proxy_type: str) -> List[JsonDict]:
    with db.transaction() as tx:

        proxy_instances = []
        package_proxy_ids = []
        record_ids = []

        x_bf_trace_id = AuditLogger.trace_id_header()

        for package_proxy, record in db.get_all_package_proxies_tx(tx):
            proxy_instances.append(to_proxy_instance(PROXY_TYPE,
                                                     package_proxy))
            package_proxy_ids.append(str(package_proxy.id))
            record_ids.append(str(record.id))

        AuditLogger.get().message().append("package-proxies",
                                           *package_proxy_ids).append(
                                               "records",
                                               *record_ids).log(x_bf_trace_id)

        return proxy_instances