diff --git a/docs/providers/gandi.rst b/docs/providers/gandi.rst index 5c864a776..a380c36ca 100644 --- a/docs/providers/gandi.rst +++ b/docs/providers/gandi.rst @@ -1,4 +1,4 @@ gandi - * ``auth_token`` Specify gandi api key + * ``auth_token`` Specify gandi api key or personal access token * ``api_protocol`` (optional) specify gandi api protocol to use: rpc (default) or rest diff --git a/src/lexicon/_private/providers/gandi.py b/src/lexicon/_private/providers/gandi.py index a337b2767..dce33549f 100644 --- a/src/lexicon/_private/providers/gandi.py +++ b/src/lexicon/_private/providers/gandi.py @@ -57,7 +57,7 @@ def get_nameservers() -> List[str]: @staticmethod def configure_parser(parser: ArgumentParser) -> None: - parser.add_argument("--auth-token", help="specify Gandi API key") + parser.add_argument("--auth-token", help="specify Gandi API key or Personal Access Token") parser.add_argument( "--api-protocol", help="(optional) specify Gandi API protocol to use: rpc (default) or rest", @@ -269,10 +269,11 @@ def _request(self, action="GET", url="/", data=None, query_params=None): data = {} if query_params is None: query_params = {} + auth_method = "Apikey " if len(self._get_provider_option("auth_token")) <= 24 else "Bearer " default_headers = { "Accept": "application/json", "Content-Type": "application/json", - "Authorization": "Apikey " + self._get_provider_option("auth_token"), + "Authorization": auth_method + self._get_provider_option("auth_token"), } if not url.startswith(self.api_endpoint): url = self.api_endpoint + url