def args( ): argumentparser = _argparse.ArgumentParser( description = "INWX CLI Frontend" ) argumentparser.add_argument( "-c", "--conf", dest = "conf", default = _os.path.join(str(_pathlib.Path.home()), ".inwx-conf.json"), metavar = "", help = "path to configuration file", ) argumentparser.add_argument( "-e", "--environment", dest = "environment", 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( "-u", "--username", dest = "username", metavar = "", default = None, help = "username; overwrites the configuration value", ) argumentparser.add_argument( "-p", "--password", dest = "password", metavar = "", default = None, help = "password; overwrites the configuration value", ) ''' argumentparser.add_argument( "-d", "--domain", dest = "domain", default = None, metavar = "", help = "the domain to work with" ) ''' argumentparser.add_argument( "-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, metavar = "", help = "action specific parameters", ) 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.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.action == "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.action == "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.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 action '%s'" % (arguments.action, )) try: main() except ValueError as error: _sys.stderr.write(str(error) + "\n")