48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import click
|
|
|
|
from transip_client.main import detect
|
|
|
|
|
|
DEFAULT_DNS = "myip.opendns.com"
|
|
DEFAULT_DNS_NAME = "@resolver1.opendns.com"
|
|
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("--dns", envvar="DNS", default=DEFAULT_DNS)
|
|
@click.option("--dns-name", envvar="DNS_NAME", default=DEFAULT_DNS_NAME)
|
|
@click.option("--api-url", envvar="API_URL", default=DEFAULT_API_URL)
|
|
@click.option("--read-only/--write", envvar="READ_ONLY", default=False)
|
|
def run(domains, token, login, private_key_path, dns, dns_name, api_url, read_only):
|
|
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,
|
|
(dns, dns_name),
|
|
(private_key_path, login),
|
|
token,
|
|
api_url,
|
|
read_only,
|
|
)
|