54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
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)
|
|
def run(
|
|
domains: list[str],
|
|
token: str,
|
|
login: str,
|
|
private_key_path: str,
|
|
service: str,
|
|
api_url: str,
|
|
read_only: bool,
|
|
) -> None:
|
|
if not domains:
|
|
raise ValueError("No domain(s) specified")
|
|
|
|
token_retrieval = any(
|
|
(
|
|
login,
|
|
private_key_path,
|
|
)
|
|
)
|
|
|
|
if token_retrieval and 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,
|
|
read_only,
|
|
)
|