示例#1
0
def test_get_yarn_component_info_from_non_hosted_nexus(mock_get_js_component):
    general_js.get_yarn_component_info_from_non_hosted_nexus("foo",
                                                             "1.0.0-external",
                                                             "cachito-yarn-1",
                                                             max_attempts=5)
    mock_get_js_component.assert_called_once_with("foo",
                                                  "1.0.0-external",
                                                  "cachito-yarn-1",
                                                  is_hosted=False,
                                                  max_attempts=5)
示例#2
0
文件: yarn.py 项目: tkdchen/cachito
def _set_proxy_resolved_urls(yarn_lock: Dict[str, dict], proxy_repo_name: str) -> bool:
    """
    Set the "resolved" urls for all dependencies, make them point to the proxy repo.

    This must be called *after* Cachito downloads the dependencies, before that they do not yet
    exist in the cachito-yarn-{request_id} proxy repo.

    External dependencies in yarn.lock must be replaced *before* calling this function, see
    _replace_deps_in_yarn_lock.

    :param dict yarn_lock: parsed yarn.lock data with nexus replacements already applied
    :param str proxy_repo_name: the proxy repo name, cachito-yarn-{request_id}
    :return: bool, was anything in the yarn.lock data modified?
    """
    modified = False

    for dep_identifier, dep_data in yarn_lock.items():
        pkg = pyarn.lockfile.Package.from_dict(dep_identifier, dep_data)
        if not pkg.url:
            # Local dependency, does not have a resolved url (and does not need one)
            continue

        pkg_name = pkg.name
        pkg_version = dep_data["version"]

        component_info = get_yarn_component_info_from_non_hosted_nexus(
            pkg_name, pkg_version, proxy_repo_name, max_attempts=5
        )
        if not component_info:
            raise CachitoError(
                f"The dependency {pkg_name}@{pkg_version} was uploaded to the Nexus hosted "
                f"repository but is not available in {proxy_repo_name}"
            )

        dep_data["resolved"] = component_info["assets"][0]["downloadUrl"]
        modified = True

    return modified
示例#3
0
文件: yarn.py 项目: hjmodi/cachito
def _set_non_hosted_resolved_urls(nexus_replacements: Dict[str, dict],
                                  proxy_repo_name: str):
    """
    Set the "resolved" urls for all external dependencies, make them point to the proxy repo.

    This must be called *after* Cachito downloads the dependencies, before that they do not yet
    exist in the cachito-yarn-{request_id} proxy repo.

    :param dict nexus_replacements: the replaced external dependencies, will be *modified in-place*
    :param str proxy_repo_name: the proxy repo name, cachito-yarn-{request_id}
    """
    for dep_identifier, dep_data in nexus_replacements.items():
        pkg_name = pyarn.lockfile.Package.from_dict(dep_identifier,
                                                    dep_data).name
        pkg_version = dep_data["version"]

        component_info = get_yarn_component_info_from_non_hosted_nexus(
            pkg_name, pkg_version, proxy_repo_name, max_attempts=5)
        if not component_info:
            raise CachitoError(
                f"The dependency {pkg_name}@{pkg_version} was uploaded to the Nexus hosted "
                f"repository but is not available in {proxy_repo_name}")

        dep_data["resolved"] = component_info["assets"][0]["downloadUrl"]