Allows using different ways to retrieve hosts IP address
This commit is contained in:
parent
97cf1a8f5c
commit
84558826fb
15 changed files with 861 additions and 710 deletions
|
|
@ -1,54 +1,40 @@
|
|||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from transip_client.main import detect
|
||||
|
||||
|
||||
DEFAULT_SERVICE = "https://api.ipify.org"
|
||||
DEFAULT_API_URL = "https://api.transip.nl/v6"
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("domains", envvar="DOMAINS", nargs=-1)
|
||||
@click.option("--token", envvar="TOKEN")
|
||||
@click.option("--login", envvar="LOGIN")
|
||||
@click.option("--private-key-path", envvar="PRIVATE_KEY_PATH")
|
||||
@click.option("--service", envvar="SERVICE", default=DEFAULT_SERVICE)
|
||||
@click.option("--api-url", envvar="API_URL", default=DEFAULT_API_URL)
|
||||
@click.option("--read-only/--write", envvar="READ_ONLY", default=False)
|
||||
@click.argument("login")
|
||||
@click.argument("private-key-path")
|
||||
@click.argument("domains", nargs=-1)
|
||||
@click.option(
|
||||
"--adapter-class",
|
||||
default="transip_client.adapters.OpenDNSAdapter",
|
||||
)
|
||||
@click.option("--read-only/--write", default=False)
|
||||
def run(
|
||||
domains: list[str],
|
||||
token: str,
|
||||
login: str,
|
||||
private_key_path: str,
|
||||
service: str,
|
||||
api_url: str,
|
||||
adapter_class: str,
|
||||
read_only: bool,
|
||||
) -> None:
|
||||
if not domains:
|
||||
raise ValueError("No domain(s) specified")
|
||||
|
||||
token_retrieval = any(
|
||||
(
|
||||
login,
|
||||
private_key_path,
|
||||
)
|
||||
)
|
||||
if not Path(private_key_path).exists():
|
||||
raise ValueError(f"Unknown private key path: {private_key_path}")
|
||||
|
||||
if token_retrieval and not all((login, private_key_path)):
|
||||
if not all((login, private_key_path)):
|
||||
raise ValueError(
|
||||
"Both a login name and the path to a private key need to be specified"
|
||||
)
|
||||
elif not token_retrieval and not token:
|
||||
raise ValueError(
|
||||
"Either a token or a login name with a path to a private key need"
|
||||
" to be specified"
|
||||
)
|
||||
|
||||
detect(
|
||||
domains,
|
||||
service,
|
||||
(private_key_path, login),
|
||||
token,
|
||||
api_url,
|
||||
adapter_class,
|
||||
read_only,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue