From 75d64ea3eb0867f12c06c6f1e5b50cff3021427d Mon Sep 17 00:00:00 2001 From: black Date: Mon, 2 Dec 2024 10:27:59 +0100 Subject: [PATCH] Support auto_policy --- desec.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/desec.py b/desec.py index 57834d3..0adb37b 100755 --- a/desec.py +++ b/desec.py @@ -101,6 +101,7 @@ class JsonTokenType(t.TypedDict): """API token information.""" allowed_subnets: list[str] + auto_policy: bool created: str id: str is_valid: bool @@ -679,6 +680,7 @@ def create_token( create_domain: bool | None = None, delete_domain: bool | None = None, allowed_subnets: list[str] | None = None, + auto_policy: bool | None = None, ) -> JsonTokenSecretType: """Create a new authentication token. @@ -694,6 +696,7 @@ def create_token( value. allowed_subnets: Set the "allowed_subnets" attribute of the new token to this value. + auto_policy: Set the "auto_policy" attribute of the new token to this value. Returns: A dictionary containing all metadata of the newly created token as well as the @@ -717,6 +720,8 @@ def create_token( request_data["perm_delete_domain"] = delete_domain if allowed_subnets is not None: request_data["allowed_subnets"] = allowed_subnets + if auto_policy is not None: + request_data["auto_policy"] = auto_policy data = self.query("POST", url, request_data) return t.cast(JsonTokenSecretType, data) @@ -728,6 +733,7 @@ def modify_token( create_domain: bool | None = None, delete_domain: bool | None = None, allowed_subnets: list[str] | None = None, + auto_policy: bool | None = None, ) -> JsonTokenType: """Modify an existing authentication token. @@ -744,6 +750,7 @@ def modify_token( value. allowed_subnets: Set the "allowed_subnets" attribute of the target token to this value. + auto_policy: Set the "auto_policy" attribute of the target token to this value. Returns: A dictionary containing all metadata of the changed token, not including the @@ -769,6 +776,8 @@ def modify_token( request_data["perm_delete_domain"] = delete_domain if allowed_subnets is not None: request_data["allowed_subnets"] = allowed_subnets + if auto_policy is not None: + request_data["auto_policy"] = auto_policy data = self.query("PATCH", url, request_data) return t.cast(JsonTokenType, data) @@ -1626,6 +1635,11 @@ def _main() -> None: action="append", help="IPv4/IPv6 addresses or subnets from which clients may authenticate with this token", ) + p.add_argument( + "--auto-policy", + action="store_true", + help="automatically set up a permissive policy for any domains created with this token", + ) p = p_action.add_parser("modify-token", help="modify an existing authentication token") p.add_argument("id", help="token id") @@ -1676,6 +1690,19 @@ def _main() -> None: action="append", help="IPv4/IPv6 addresses or subnets from which clients may authenticate with this token", ) + p.add_argument( + "--auto-policy", + action="store_true", + default=None, + help="automatically set up a permissive policy for any domains created with this token", + ) + p.add_argument( + "--no-auto-policy", + dest="auto_policy", + action="store_false", + default=None, + help="do not automatically set up a policy for any domains created with this token", + ) p = p_action.add_parser("delete-token", help="delete an authentication token") p.add_argument("id", help="token id") @@ -2056,6 +2083,7 @@ def _main() -> None: arguments.create_domain, arguments.delete_domain, arguments.allowed_subnets, + arguments.auto_policy, ) print(new_token_result["token"]) @@ -2067,6 +2095,7 @@ def _main() -> None: arguments.create_domain, arguments.delete_domain, arguments.allowed_subnets, + arguments.auto_policy, ) pprint(token_result)