Ejemplo n.º 1
0
def test_api_cache(monkeypatch, isolated_pio_core):
    regclient = RegistryClient()
    api_kwargs = {"method": "get", "path": "/v2/stats", "cache_valid": "10s"}
    result = regclient.fetch_json_data(**api_kwargs)
    assert result and "boards" in result
    monkeypatch.setattr(http, "_internet_on", lambda: False)
    assert regclient.fetch_json_data(**api_kwargs) == result
Ejemplo n.º 2
0
def access_grant(level, client, urn, urn_type):
    reg_client = RegistryClient()
    reg_client.grant_access_for_resource(urn=urn, client=client, level=level)
    return click.secho(
        "Access for resource %s has been granted for %s" % (urn, client),
        fg="green",
    )
Ejemplo n.º 3
0
def access_private(urn, urn_type):
    client = RegistryClient()
    client.update_resource(urn=urn, private=1)
    return click.secho(
        "The resource %s has been successfully updated." % urn,
        fg="green",
    )
Ejemplo n.º 4
0
def access_revoke(client, urn, urn_type):
    reg_client = RegistryClient()
    reg_client.revoke_access_from_resource(urn=urn, client=client)
    return click.secho(
        "Access for resource %s has been revoked for %s" % (urn, client),
        fg="green",
    )
Ejemplo n.º 5
0
def package_publish(package, owner, released_at, private, notify):
    p = PackagePacker(package)
    archive_path = p.pack()
    response = RegistryClient().publish_package(archive_path, owner,
                                                released_at, private, notify)
    os.remove(archive_path)
    click.secho(response.get("message"), fg="green")
Ejemplo n.º 6
0
def package_unpublish(package, type, undo):  # pylint: disable=redefined-builtin
    spec = PackageSpec(package)
    response = RegistryClient().unpublish_package(
        type=type,
        name=spec.name,
        owner=spec.owner,
        version=str(spec.requirements),
        undo=undo,
    )
    click.secho(response.get("message"), fg="green")
Ejemplo n.º 7
0
def package_publish(package, owner, released_at, private, notify):
    assert ensure_python3()
    with tempfile.TemporaryDirectory() as tmp_dir:  # pylint: disable=no-member
        with fs.cd(tmp_dir):
            p = PackagePacker(package)
            archive_path = p.pack()
            response = RegistryClient().publish_package(
                archive_path, owner, released_at, private, notify
            )
            os.remove(archive_path)
            click.secho(response.get("message"), fg="green")
Ejemplo n.º 8
0
def access_list(owner, urn_type, json_output):
    reg_client = RegistryClient()
    resources = reg_client.list_resources(owner=owner)
    if json_output:
        return click.echo(json.dumps(resources))
    if not resources:
        return click.secho("You do not have any resources.", fg="yellow")
    for resource in resources:
        click.echo()
        click.secho(resource.get("name"), fg="cyan")
        click.echo("-" * len(resource.get("name")))
        table_data = []
        table_data.append(("URN:", resource.get("urn")))
        table_data.append(("Owner:", resource.get("owner")))
        table_data.append((
            "Access level(s):",
            ", ".join((level.capitalize()
                       for level in resource.get("access_levels"))),
        ))
        click.echo(tabulate(table_data, tablefmt="plain"))
    return click.echo()
Ejemplo n.º 9
0
def package_publish(package, owner, released_at, private, notify):
    assert ensure_python3()

    # publish .tar.gz instantly without repacking
    if not os.path.isdir(package) and isinstance(
            FileUnpacker.new_archiver(package), TARArchiver):
        response = RegistryClient().publish_package(package, owner,
                                                    released_at, private,
                                                    notify)
        click.secho(response.get("message"), fg="green")
        return

    with tempfile.TemporaryDirectory() as tmp_dir:  # pylint: disable=no-member
        with fs.cd(tmp_dir):
            p = PackagePacker(package)
            archive_path = p.pack()
            response = RegistryClient().publish_package(
                archive_path, owner, released_at, private, notify)
            os.remove(archive_path)
            click.secho(response.get("message"), fg="green")
Ejemplo n.º 10
0
def test_api_internet_offline(without_internet, isolated_pio_core):
    regclient = RegistryClient()
    with pytest.raises(http.InternetIsOffline):
        regclient.fetch_json_data("get", "/v2/stats")
Ejemplo n.º 11
0
 def get_registry_client_instance(self):
     if not self._registry_client:
         self._registry_client = RegistryClient()
     return self._registry_client
Ejemplo n.º 12
0
def test_saving_deps(clirunner, validate_cliresult, isolated_pio_core,
                     tmpdir_factory):
    regclient = RegistryClient()
    project_dir = tmpdir_factory.mktemp("project")
    project_dir.join("platformio.ini").write("""
[env]
lib_deps = ArduinoJson

[env:one]
board = devkit

[env:two]
framework = foo
lib_deps =
    CustomLib
    ArduinoJson @ 5.10.1
""")
    result = clirunner.invoke(
        cmd_lib,
        [
            "-d",
            str(project_dir), "install", "64", "knolleary/PubSubClient@~2.7"
        ],
    )
    validate_cliresult(result)
    aj_pkg_data = regclient.get_package(PackageType.LIBRARY, "bblanchon",
                                        "ArduinoJson")
    config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini"))
    assert sorted(config.get("env:one", "lib_deps")) == sorted([
        "bblanchon/ArduinoJson@^%s" % aj_pkg_data["version"]["name"],
        "knolleary/PubSubClient@~2.7",
    ])
    assert sorted(config.get("env:two", "lib_deps")) == sorted([
        "CustomLib",
        "bblanchon/ArduinoJson@^%s" % aj_pkg_data["version"]["name"],
        "knolleary/PubSubClient@~2.7",
    ])

    # ensure "build" version without NPM spec
    result = clirunner.invoke(
        cmd_lib,
        [
            "-d",
            str(project_dir), "-e", "one", "install",
            "mbed-sam-grove/LinkedList"
        ],
    )
    validate_cliresult(result)
    ll_pkg_data = regclient.get_package(PackageType.LIBRARY, "mbed-sam-grove",
                                        "LinkedList")
    config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini"))
    assert sorted(config.get("env:one", "lib_deps")) == sorted([
        "bblanchon/ArduinoJson@^%s" % aj_pkg_data["version"]["name"],
        "knolleary/PubSubClient@~2.7",
        "mbed-sam-grove/LinkedList@%s" % ll_pkg_data["version"]["name"],
    ])

    # check external package via Git repo
    result = clirunner.invoke(
        cmd_lib,
        [
            "-d",
            str(project_dir),
            "-e",
            "one",
            "install",
            "https://github.com/OttoWinter/async-mqtt-client.git#v0.8.3 @ 0.8.3",
        ],
    )
    validate_cliresult(result)
    config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini"))
    assert len(config.get("env:one", "lib_deps")) == 4
    assert config.get("env:one", "lib_deps")[3] == (
        "https://github.com/OttoWinter/async-mqtt-client.git#v0.8.3 @ 0.8.3")

    # test uninstalling
    # from all envs
    result = clirunner.invoke(
        cmd_lib, ["-d", str(project_dir), "uninstall", "ArduinoJson"])
    validate_cliresult(result)
    # from "one" env
    result = clirunner.invoke(
        cmd_lib,
        [
            "-d",
            str(project_dir),
            "-e",
            "one",
            "uninstall",
            "knolleary/PubSubClient@~2.7",
        ],
    )
    validate_cliresult(result)
    config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini"))
    assert len(config.get("env:one", "lib_deps")) == 2
    assert len(config.get("env:two", "lib_deps")) == 2
    assert config.get("env:one", "lib_deps") == [
        "mbed-sam-grove/LinkedList@%s" % ll_pkg_data["version"]["name"],
        "https://github.com/OttoWinter/async-mqtt-client.git#v0.8.3 @ 0.8.3",
    ]
    assert config.get("env:two", "lib_deps") == [
        "CustomLib",
        "knolleary/PubSubClient@~2.7",
    ]

    # test list
    result = clirunner.invoke(cmd_lib, ["-d", str(project_dir), "list"])
    validate_cliresult(result)
    assert "Version: 0.8.3+sha." in result.stdout
    assert (
        "Source: git+https://github.com/OttoWinter/async-mqtt-client.git#v0.8.3"
        in result.stdout)
    result = clirunner.invoke(
        cmd_lib, ["-d", str(project_dir), "list", "--json-output"])
    validate_cliresult(result)
    data = {}
    for key, value in json.loads(result.stdout).items():
        data[os.path.basename(key)] = value
    ame_lib = next(item for item in data["one"]
                   if item["name"] == "AsyncMqttClient-esphome")
    ame_vcs = VCSClientFactory.new(ame_lib["__pkg_dir"], ame_lib["__src_url"])
    assert len(data["two"]) == 1
    assert data["two"][0]["name"] == "PubSubClient"
    assert "__pkg_dir" in data["one"][0]
    assert (ame_lib["__src_url"] ==
            "git+https://github.com/OttoWinter/async-mqtt-client.git#v0.8.3")
    assert ame_lib["version"] == ("0.8.3+sha.%s" %
                                  ame_vcs.get_current_revision())