Skip to content

Commit 948d99b

Browse files
authored
Fix URL parsing for configuration dumping (#19)
* Use Python's `urlparse` function to parse the Sonarr instance URL, accepting any valid URL of any hostname/address * Add explicit `json5` dependency to the plugin dependencies, instead of relying on the implicit dependency from Buildarr Core
1 parent b9ce32d commit 948d99b

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

buildarr_sonarr/cli.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222
import functools
2323

2424
from getpass import getpass
25+
from typing import TYPE_CHECKING
2526
from urllib.parse import urlparse
2627

2728
import click
28-
import click_params # type: ignore[import]
2929

3030
from .config import SonarrInstanceConfig
3131
from .manager import SonarrManager
3232
from .secrets import SonarrSecrets
3333

34+
if TYPE_CHECKING:
35+
from urllib.parse import ParseResult as Url
36+
3437
HOSTNAME_PORT_TUPLE_LENGTH = 2
3538

3639

@@ -49,7 +52,7 @@ def sonarr():
4952
"The configuration is dumped to standard output in Buildarr-compatible YAML format."
5053
),
5154
)
52-
@click.argument("url", type=click_params.URL)
55+
@click.argument("url", type=urlparse)
5356
@click.option(
5457
"-k",
5558
"--api-key",
@@ -58,15 +61,14 @@ def sonarr():
5861
default=functools.partial(getpass, "Sonarr instance API key: "),
5962
help="API key of the Sonarr instance. The user will be prompted if undefined.",
6063
)
61-
def dump_config(url: str, api_key: str) -> int:
64+
def dump_config(url: Url, api_key: str) -> int:
6265
"""
6366
Dump configuration from a remote Sonarr instance.
6467
The configuration is dumped to standard output in Buildarr-compatible YAML format.
6568
"""
6669

67-
url_obj = urlparse(url)
68-
protocol = url_obj.scheme
69-
hostname_port = url_obj.netloc.split(":", 1)
70+
protocol = url.scheme
71+
hostname_port = url.netloc.split(":", 1)
7072
hostname = hostname_port[0]
7173
port = (
7274
int(hostname_port[1])

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ packages = [{include = "buildarr_sonarr"}]
3333
[tool.poetry.dependencies]
3434
python = ">=3.8,<4.0"
3535
buildarr = ">=0.5.0,<0.7.0"
36+
json5 = ">=0.9.7"
3637

3738
[tool.poetry.group.dev.dependencies]
3839
black = "23.7.0"

0 commit comments

Comments
 (0)