diff --git a/readme.md b/readme.md index a73f590..2043313 100644 --- a/readme.md +++ b/readme.md @@ -22,16 +22,24 @@ For most API calls it is necessary to provide login information. There are two w - the default location is `~/.inwx-conf.json` - a minial configuration file for specifying the credentials would look as follows: - { - "account": { - "username": "___", - "password": "___" - } - } +``` +{ + "account": { + "username": "___", + "password": "___" + } +} +``` ## Commands +### `info` + +- synopsis: `inwx info` +- description: for listing the records of a domain + + ### `list` - synopsis: `inwx list ` @@ -44,3 +52,9 @@ For most API calls it is necessary to provide login information. There are two w - description: for creating or updating a records of a domain - example: `inwx save example.org dat TXT 'foo bar'` + +### `certbot-hook` + +- synopsis: `inwx certbot-hook` +- description: for executing the DNS certbot challenge; will read the environment variables `CERTBOT_DOMAIN` and `CERTBOT_VALIDATION` to store a `TXT` record + diff --git a/source/head.py b/source/head.py index 23fa5a0..5212350 100644 --- a/source/head.py +++ b/source/head.py @@ -8,5 +8,5 @@ import json as _json import http.client as _http_client import argparse as _argparse import pathlib as _pathlib - +import time as _time diff --git a/source/main.py b/source/main.py index 87f135e..ff50521 100644 --- a/source/main.py +++ b/source/main.py @@ -5,40 +5,77 @@ def args( description = "INWX CLI Frontend" ) argumentparser.add_argument( - '--conf', + "-c", + "--conf", dest = "conf", - default = _os.path.join(str(_pathlib.Path.home()), ".inwx-conf.json") + default = _os.path.join(str(_pathlib.Path.home()), ".inwx-conf.json"), + metavar = "", + help = "path to configuration file", ) argumentparser.add_argument( - '--environment', + "-e", + "--environment", dest = "environment", - default = None + metavar = "", + default = None, + help = "environment to use; one of the keys in the 'url' filed of the configuration; overwrites the configuration value", ) argumentparser.add_argument( - '--username', + "-u", + "--username", dest = "username", - default = None + metavar = "", + default = None, + help = "username; overwrites the configuration value", ) argumentparser.add_argument( - '--password', + "-p", + "--password", dest = "password", - default = None + metavar = "", + default = None, + help = "password; overwrites the configuration value", ) ''' argumentparser.add_argument( - '--domain', + "-d", + "--domain", dest = "domain", - default = None + default = None, + metavar = "", + help = "the domain to work with" ) ''' argumentparser.add_argument( - "command", - type = str + "-x", + "--challenge-prefix", + dest = "challenge_prefix", + metavar = "", + default = "_acme-challenge", + help = "which subdomain to use for ACME challanges", + ) + argumentparser.add_argument( + "-w", + "--delay", + dest = "delay", + type = float, + default = 60.0, + metavar = "", + help = "seconds to wait at end of certbot auth hook", + ) + argumentparser.add_argument( + "action", + type = str, + choices = ["info", "list", "save", "certbot-hook"], + metavar = "", + help = "action to execute", ) argumentparser.add_argument( "parameter", nargs = "*", - type = str + type = str, + metavar = "", + help = "action specific parameters", ) arguments = argumentparser.parse_args() return arguments @@ -53,14 +90,14 @@ def main( if (not (arguments.username is None)): conf_set("account.username", arguments.username) if (not (arguments.password is None)): conf_set("account.password", arguments.password) - if (arguments.command == "info"): + if (arguments.action == "info"): result = api_macro_info( conf_get("environment"), conf_get("account.username"), conf_get("account.password") ) print(_json.dumps(result, indent = "\t")) - elif (arguments.command == "list"): + elif (arguments.action == "list"): domain = arguments.parameter[0] result = api_macro_list( conf_get("environment"), @@ -69,7 +106,7 @@ def main( domain ) print(_json.dumps(result, indent = "\t")) - elif (arguments.command == "save"): + elif (arguments.action == "save"): domain = arguments.parameter[0] name = arguments.parameter[1] type_ = arguments.parameter[2] @@ -84,8 +121,25 @@ def main( content ) # print(_json.dumps(result, indent = "\t")) + elif (arguments.action == "certbot-hook"): + domain_full_parts = _os.environ["CERTBOT_DOMAIN"].split(".", 1) + domain = domain_full_parts[1] + name = (arguments.challenge_prefix + "." + domain_full_parts[0]) + type_ = "TXT" + content = _os.environ["CERTBOT_VALIDATION"] + api_macro_save( + conf_get("environment"), + conf_get("account.username"), + conf_get("account.password"), + domain, + name, + type_, + content + ) + _time.sleep(arguments.delay) + # print(_json.dumps(result, indent = "\t")) else: - log("unhandled command '%s'" % (arguments.command, )) + log("unhandled action '%s'" % (arguments.action, )) try: