[add] record-deletion
This commit is contained in:
parent
2131476d2c
commit
8dcc0a761d
|
|
@ -1,3 +1,6 @@
|
||||||
|
'''
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02.html#account.login
|
||||||
|
'''
|
||||||
def api_macro_login(
|
def api_macro_login(
|
||||||
environment : str,
|
environment : str,
|
||||||
username : str,
|
username : str,
|
||||||
|
|
@ -21,6 +24,9 @@ def api_macro_login(
|
||||||
return response["_accesstoken"]
|
return response["_accesstoken"]
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02.html#account.logout
|
||||||
|
'''
|
||||||
def api_macro_logout(
|
def api_macro_logout(
|
||||||
environment : str,
|
environment : str,
|
||||||
accesstoken : str
|
accesstoken : str
|
||||||
|
|
@ -36,6 +42,9 @@ def api_macro_logout(
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02.html#account.info
|
||||||
|
'''
|
||||||
def api_macro_info(
|
def api_macro_info(
|
||||||
environment : str,
|
environment : str,
|
||||||
username : str,
|
username : str,
|
||||||
|
|
@ -54,6 +63,9 @@ def api_macro_info(
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.info
|
||||||
|
'''
|
||||||
def api_macro_list(
|
def api_macro_list(
|
||||||
environment : str,
|
environment : str,
|
||||||
username : str,
|
username : str,
|
||||||
|
|
@ -74,6 +86,11 @@ def api_macro_list(
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.info
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.createRecord
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.updateRecord
|
||||||
|
'''
|
||||||
def api_macro_save(
|
def api_macro_save(
|
||||||
environment : str,
|
environment : str,
|
||||||
username : str,
|
username : str,
|
||||||
|
|
@ -133,3 +150,53 @@ def api_macro_save(
|
||||||
api_macro_logout(environment, accesstoken)
|
api_macro_logout(environment, accesstoken)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.info
|
||||||
|
@see https://www.inwx.de/de/help/apidoc/f/ch02s15.html#nameserver.deleteRecord
|
||||||
|
'''
|
||||||
|
def api_macro_delete(
|
||||||
|
environment : str,
|
||||||
|
username : str,
|
||||||
|
password : str,
|
||||||
|
domain : str,
|
||||||
|
name : str,
|
||||||
|
type_
|
||||||
|
):
|
||||||
|
accesstoken = api_macro_login(environment, username, password)
|
||||||
|
info = api_call(
|
||||||
|
environment,
|
||||||
|
accesstoken,
|
||||||
|
"nameserver",
|
||||||
|
"info",
|
||||||
|
{
|
||||||
|
"domain": domain,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
matching = list(
|
||||||
|
filter(
|
||||||
|
lambda record: (
|
||||||
|
(record["name"] == (name + "." + domain))
|
||||||
|
and
|
||||||
|
(
|
||||||
|
(type_ is None)
|
||||||
|
or
|
||||||
|
(record["type"] == type_)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
info["record"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for entry in matching:
|
||||||
|
id_ = entry["id"]
|
||||||
|
result = api_call(
|
||||||
|
environment,
|
||||||
|
accesstoken,
|
||||||
|
"nameserver",
|
||||||
|
"deleteRecord",
|
||||||
|
{
|
||||||
|
"id": id_,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
api_macro_logout(environment, accesstoken)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,9 @@ def args(
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
"action",
|
"action",
|
||||||
type = str,
|
type = str,
|
||||||
choices = ["info", "list", "save", "certbot-hook"],
|
choices = ["info", "list", "save", "delete", "certbot-hook"],
|
||||||
metavar = "<action>",
|
metavar = "<action>",
|
||||||
help = "action to execute",
|
help = "action to execute; options: info,list,save,delete,certbot-hook",
|
||||||
)
|
)
|
||||||
argumentparser.add_argument(
|
argumentparser.add_argument(
|
||||||
"parameter",
|
"parameter",
|
||||||
|
|
@ -121,6 +121,18 @@ def main(
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
# print(_json.dumps(result, indent = "\t"))
|
# print(_json.dumps(result, indent = "\t"))
|
||||||
|
elif (arguments.action == "delete"):
|
||||||
|
domain = arguments.parameter[0]
|
||||||
|
name = arguments.parameter[1]
|
||||||
|
type_ = (arguments.parameter[2] if (len(arguments.parameter) >= 2) else None)
|
||||||
|
api_macro_delete(
|
||||||
|
conf_get("environment"),
|
||||||
|
conf_get("account.username"),
|
||||||
|
conf_get("account.password"),
|
||||||
|
domain,
|
||||||
|
name,
|
||||||
|
type_
|
||||||
|
)
|
||||||
elif (arguments.action == "certbot-hook"):
|
elif (arguments.action == "certbot-hook"):
|
||||||
domain_full_parts = _os.environ["CERTBOT_DOMAIN"].split(".")
|
domain_full_parts = _os.environ["CERTBOT_DOMAIN"].split(".")
|
||||||
account = ".".join(domain_full_parts[-2:])
|
account = ".".join(domain_full_parts[-2:])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue