121 lines
2.7 KiB
Python
121 lines
2.7 KiB
Python
|
|
def args(
|
|
):
|
|
argumentparser = _argparse.ArgumentParser(
|
|
description = "INWX CLI Frontend"
|
|
)
|
|
argumentparser.add_argument(
|
|
'--conf',
|
|
dest = "conf",
|
|
default = _os.path.join(str(_pathlib.Path.home()), ".inwx-conf.json")
|
|
)
|
|
argumentparser.add_argument(
|
|
'--environment',
|
|
dest = "environment",
|
|
default = None
|
|
)
|
|
argumentparser.add_argument(
|
|
'--username',
|
|
dest = "username",
|
|
default = None
|
|
)
|
|
argumentparser.add_argument(
|
|
'--password',
|
|
dest = "password",
|
|
default = None
|
|
)
|
|
'''
|
|
argumentparser.add_argument(
|
|
'--domain',
|
|
dest = "domain",
|
|
default = None
|
|
)
|
|
'''
|
|
argumentparser.add_argument(
|
|
'--delay',
|
|
dest = "delay",
|
|
type = float,
|
|
default = 60.0,
|
|
help = "seconds to wait at end of certbot auth hook",
|
|
)
|
|
argumentparser.add_argument(
|
|
"command",
|
|
type = str
|
|
)
|
|
argumentparser.add_argument(
|
|
"parameter",
|
|
nargs = "*",
|
|
type = str
|
|
)
|
|
arguments = argumentparser.parse_args()
|
|
return arguments
|
|
|
|
|
|
def main(
|
|
):
|
|
arguments = args()
|
|
|
|
conf_load(arguments.conf)
|
|
if (not (arguments.environment is None)): conf_set("environment", arguments.environment)
|
|
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"):
|
|
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"):
|
|
domain = arguments.parameter[0]
|
|
result = api_macro_list(
|
|
conf_get("environment"),
|
|
conf_get("account.username"),
|
|
conf_get("account.password"),
|
|
domain
|
|
)
|
|
print(_json.dumps(result, indent = "\t"))
|
|
elif (arguments.command == "save"):
|
|
domain = arguments.parameter[0]
|
|
name = arguments.parameter[1]
|
|
type_ = arguments.parameter[2]
|
|
content = arguments.parameter[3]
|
|
api_macro_save(
|
|
conf_get("environment"),
|
|
conf_get("account.username"),
|
|
conf_get("account.password"),
|
|
domain,
|
|
name,
|
|
type_,
|
|
content
|
|
)
|
|
# print(_json.dumps(result, indent = "\t"))
|
|
elif (arguments.command == "certbot-hook"):
|
|
domain_full = _os.environ["CERTBOT_DOMAIN"]
|
|
domain_full_parts = _os.environ["CERTBOT_DOMAIN"].split(".", 1)
|
|
domain = domain_full_parts[1]
|
|
name = 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(args.delay)
|
|
# print(_json.dumps(result, indent = "\t"))
|
|
else:
|
|
log("unhandled command '%s'" % (arguments.command, ))
|
|
|
|
|
|
try:
|
|
main()
|
|
except ValueError as error:
|
|
_sys.stderr.write(str(error) + "\n")
|
|
|