Merge branch 'master' of gs-gitlab:tools/inwx
This commit is contained in:
commit
513657c1fe
26
readme.md
26
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`
|
- the default location is `~/.inwx-conf.json`
|
||||||
- a minial configuration file for specifying the credentials would look as follows:
|
- a minial configuration file for specifying the credentials would look as follows:
|
||||||
|
|
||||||
{
|
```
|
||||||
"account": {
|
{
|
||||||
"username": "___",
|
"account": {
|
||||||
"password": "___"
|
"username": "___",
|
||||||
}
|
"password": "___"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
|
### `info`
|
||||||
|
|
||||||
|
- synopsis: `inwx info`
|
||||||
|
- description: for listing the records of a domain
|
||||||
|
|
||||||
|
|
||||||
### `list`
|
### `list`
|
||||||
|
|
||||||
- synopsis: `inwx list <domain>`
|
- synopsis: `inwx list <domain>`
|
||||||
|
|
@ -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
|
- description: for creating or updating a records of a domain
|
||||||
- example: `inwx save example.org dat TXT 'foo bar'`
|
- 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,5 @@ import json as _json
|
||||||
import http.client as _http_client
|
import http.client as _http_client
|
||||||
import argparse as _argparse
|
import argparse as _argparse
|
||||||
import pathlib as _pathlib
|
import pathlib as _pathlib
|
||||||
|
import time as _time
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,40 +5,77 @@ def args(
|
||||||
description = "INWX CLI Frontend"
|
description = "INWX CLI Frontend"
|
||||||
)
|
)
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
'--conf',
|
"-c",
|
||||||
|
"--conf",
|
||||||
dest = "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 = "<conf>",
|
||||||
|
help = "path to configuration file",
|
||||||
)
|
)
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
'--environment',
|
"-e",
|
||||||
|
"--environment",
|
||||||
dest = "environment",
|
dest = "environment",
|
||||||
default = None
|
metavar = "<environment>",
|
||||||
|
default = None,
|
||||||
|
help = "environment to use; one of the keys in the 'url' filed of the configuration; overwrites the configuration value",
|
||||||
)
|
)
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
'--username',
|
"-u",
|
||||||
|
"--username",
|
||||||
dest = "username",
|
dest = "username",
|
||||||
default = None
|
metavar = "<username>",
|
||||||
|
default = None,
|
||||||
|
help = "username; overwrites the configuration value",
|
||||||
)
|
)
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
'--password',
|
"-p",
|
||||||
|
"--password",
|
||||||
dest = "password",
|
dest = "password",
|
||||||
default = None
|
metavar = "<password>",
|
||||||
|
default = None,
|
||||||
|
help = "password; overwrites the configuration value",
|
||||||
)
|
)
|
||||||
'''
|
'''
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
'--domain',
|
"-d",
|
||||||
|
"--domain",
|
||||||
dest = "domain",
|
dest = "domain",
|
||||||
default = None
|
default = None,
|
||||||
|
metavar = "<domain>",
|
||||||
|
help = "the domain to work with"
|
||||||
)
|
)
|
||||||
'''
|
'''
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
"command",
|
"-x",
|
||||||
type = str
|
"--challenge-prefix",
|
||||||
|
dest = "challenge_prefix",
|
||||||
|
metavar = "<challenge-prefix>",
|
||||||
|
default = "_acme-challenge",
|
||||||
|
help = "which subdomain to use for ACME challanges",
|
||||||
|
)
|
||||||
|
argumentparser.add_argument(
|
||||||
|
"-w",
|
||||||
|
"--delay",
|
||||||
|
dest = "delay",
|
||||||
|
type = float,
|
||||||
|
default = 60.0,
|
||||||
|
metavar = "<delay>",
|
||||||
|
help = "seconds to wait at end of certbot auth hook",
|
||||||
|
)
|
||||||
|
argumentparser.add_argument(
|
||||||
|
"action",
|
||||||
|
type = str,
|
||||||
|
choices = ["info", "list", "save", "certbot-hook"],
|
||||||
|
metavar = "<action>",
|
||||||
|
help = "action to execute",
|
||||||
)
|
)
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
"parameter",
|
"parameter",
|
||||||
nargs = "*",
|
nargs = "*",
|
||||||
type = str
|
type = str,
|
||||||
|
metavar = "<parameters>",
|
||||||
|
help = "action specific parameters",
|
||||||
)
|
)
|
||||||
arguments = argumentparser.parse_args()
|
arguments = argumentparser.parse_args()
|
||||||
return arguments
|
return arguments
|
||||||
|
|
@ -53,14 +90,14 @@ def main(
|
||||||
if (not (arguments.username is None)): conf_set("account.username", arguments.username)
|
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 (not (arguments.password is None)): conf_set("account.password", arguments.password)
|
||||||
|
|
||||||
if (arguments.command == "info"):
|
if (arguments.action == "info"):
|
||||||
result = api_macro_info(
|
result = api_macro_info(
|
||||||
conf_get("environment"),
|
conf_get("environment"),
|
||||||
conf_get("account.username"),
|
conf_get("account.username"),
|
||||||
conf_get("account.password")
|
conf_get("account.password")
|
||||||
)
|
)
|
||||||
print(_json.dumps(result, indent = "\t"))
|
print(_json.dumps(result, indent = "\t"))
|
||||||
elif (arguments.command == "list"):
|
elif (arguments.action == "list"):
|
||||||
domain = arguments.parameter[0]
|
domain = arguments.parameter[0]
|
||||||
result = api_macro_list(
|
result = api_macro_list(
|
||||||
conf_get("environment"),
|
conf_get("environment"),
|
||||||
|
|
@ -69,7 +106,7 @@ def main(
|
||||||
domain
|
domain
|
||||||
)
|
)
|
||||||
print(_json.dumps(result, indent = "\t"))
|
print(_json.dumps(result, indent = "\t"))
|
||||||
elif (arguments.command == "save"):
|
elif (arguments.action == "save"):
|
||||||
domain = arguments.parameter[0]
|
domain = arguments.parameter[0]
|
||||||
name = arguments.parameter[1]
|
name = arguments.parameter[1]
|
||||||
type_ = arguments.parameter[2]
|
type_ = arguments.parameter[2]
|
||||||
|
|
@ -84,8 +121,25 @@ def main(
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
# print(_json.dumps(result, indent = "\t"))
|
# 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:
|
else:
|
||||||
log("unhandled command '%s'" % (arguments.command, ))
|
log("unhandled action '%s'" % (arguments.action, ))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue