certbot-dns-stackit 0.1.10__tar.gz → 0.1.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: certbot-dns-stackit
3
- Version: 0.1.10
3
+ Version: 0.1.11
4
4
  Summary: STACKIT DNS Authenticator plugin for Certbot
5
5
  Home-page: https://github.com/stackitcloud/certbot-dns-stackit
6
6
  Author: STACKIT DNS
@@ -97,6 +97,8 @@ certificates. The subsequent section delineates the pertinent arguments and thei
97
97
  | `--dns-stackit-project-id` | '8a4c68b1-586a-4534-aa0c-9f8c12334a76' | Sets the STACKIT project id if the service account authentication is used. (Recommended)|
98
98
  | `--dns-stackit-service-account` | ./service-account.pem | Denotes the directory path to the STACKIT service account file. (Recommended) |
99
99
  | `--dns-stackit-credentials` | ./credentials.ini | Denotes the directory path to the credentials file for STACKIT DNS. This document must encapsulate the dns_stackit_auth_token and dns_stackit_project_id variables. |
100
+ | `--dns-stackit-base-url` | https://dns.api.stackit.cloud | Sets the STACKIT DNS API base URL. (Default: https://dns.api.stackit.cloud) |
101
+ | `--dns-stackit-token-url` | https://service-account.api.stackit.cloud/token | Sets the STACKIT service account token endpoint URL when using service account authentication. (Default: https://service-account.api.stackit.cloud/token) |
100
102
  | `--dns-stackit-propagation-seconds` | 900 | Configures the delay prior to initiating the DNS record query. A 900-second interval (equivalent to 15 minutes) is recommended. (Default: 900) |
101
103
  Either the --dns-stackit-credentials flag or the --dns-stackit-service-account and --dns-stackit-project-id flags are mandatory.
102
104
 
@@ -32,6 +32,8 @@ certificates. The subsequent section delineates the pertinent arguments and thei
32
32
  | `--dns-stackit-project-id` | '8a4c68b1-586a-4534-aa0c-9f8c12334a76' | Sets the STACKIT project id if the service account authentication is used. (Recommended)|
33
33
  | `--dns-stackit-service-account` | ./service-account.pem | Denotes the directory path to the STACKIT service account file. (Recommended) |
34
34
  | `--dns-stackit-credentials` | ./credentials.ini | Denotes the directory path to the credentials file for STACKIT DNS. This document must encapsulate the dns_stackit_auth_token and dns_stackit_project_id variables. |
35
+ | `--dns-stackit-base-url` | https://dns.api.stackit.cloud | Sets the STACKIT DNS API base URL. (Default: https://dns.api.stackit.cloud) |
36
+ | `--dns-stackit-token-url` | https://service-account.api.stackit.cloud/token | Sets the STACKIT service account token endpoint URL when using service account authentication. (Default: https://service-account.api.stackit.cloud/token) |
35
37
  | `--dns-stackit-propagation-seconds` | 900 | Configures the delay prior to initiating the DNS record query. A 900-second interval (equivalent to 15 minutes) is recommended. (Default: 900) |
36
38
  Either the --dns-stackit-credentials flag or the --dns-stackit-service-account and --dns-stackit-project-id flags are mandatory.
37
39
 
@@ -275,6 +275,14 @@ class Authenticator(dns_common.DNSAuthenticator):
275
275
  add("service-account", help="Service account file path")
276
276
  add("credentials", help="STACKIT credentials INI file.")
277
277
  add("project-id", help="STACKIT project ID")
278
+ add(
279
+ "base-url",
280
+ help="STACKIT DNS API base URL (default: https://dns.api.stackit.cloud)",
281
+ )
282
+ add(
283
+ "token-url",
284
+ help="STACKIT service account token URL (default: https://service-account.api.stackit.cloud/token)",
285
+ )
278
286
 
279
287
  def _setup_credentials(self):
280
288
  """Set up and configure the STACKIT credentials based on provided input."""
@@ -319,8 +327,11 @@ class Authenticator(dns_common.DNSAuthenticator):
319
327
  :return: A StackitClient object.
320
328
  """
321
329
  base_url = "https://dns.api.stackit.cloud"
322
- if self.credentials and self.credentials.conf("base_url") is not None:
323
- base_url = self.credentials.conf("base_url")
330
+ custom_base_url = self.conf("base-url")
331
+ if isinstance(custom_base_url, str) and custom_base_url:
332
+ base_url = custom_base_url.rstrip("/")
333
+ elif self.credentials and self.credentials.conf("base_url") is not None:
334
+ base_url = self.credentials.conf("base_url").rstrip("/")
324
335
 
325
336
  if self.service_account is not None:
326
337
  access_token = self._generate_jwt_token(self.conf("service_account"))
@@ -376,13 +387,18 @@ class Authenticator(dns_common.DNSAuthenticator):
376
387
  :param jwt_token: The JWT token used to request the access token.
377
388
  :return: An access token if the request is successful, None otherwise.
378
389
  """
390
+ token_url = "https://service-account.api.stackit.cloud/token"
391
+ custom_token_url = self.conf("token-url")
392
+ if isinstance(custom_token_url, str) and custom_token_url:
393
+ token_url = custom_token_url
394
+
379
395
  data = {
380
396
  "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
381
397
  "assertion": jwt_token,
382
398
  }
383
399
  try:
384
400
  response = requests.post(
385
- "https://service-account.api.stackit.cloud/token",
401
+ token_url,
386
402
  data=data,
387
403
  headers={"Content-Type": "application/x-www-form-urlencoded"},
388
404
  )
@@ -215,7 +215,7 @@ class TestStackitClient(unittest.TestCase):
215
215
  class TestAuthenticator(unittest.TestCase):
216
216
  def setUp(self):
217
217
  mock_config = Mock()
218
- mock_name = Mock()
218
+ mock_name = "dns-stackit"
219
219
  self.authenticator = Authenticator(mock_config, mock_name)
220
220
 
221
221
  @patch.object(Authenticator, "conf")
@@ -351,6 +351,62 @@ class TestAuthenticator(unittest.TestCase):
351
351
  )
352
352
  self.assertEqual(result, "mocked_access_token")
353
353
 
354
+ @patch.object(Authenticator, "conf")
355
+ @patch("requests.post")
356
+ def test_request_access_token_custom_token_url(self, mock_post, mock_conf):
357
+ mock_conf.return_value = "https://custom.token.url/token"
358
+ mock_response = mock_post.return_value
359
+ mock_response.raise_for_status = lambda: None
360
+ mock_response.json.return_value = {"access_token": "mocked_access_token"}
361
+
362
+ result = self.authenticator._request_access_token("jwt_token_example")
363
+
364
+ mock_post.assert_called_once_with(
365
+ "https://custom.token.url/token",
366
+ data={
367
+ "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
368
+ "assertion": "jwt_token_example",
369
+ },
370
+ headers={"Content-Type": "application/x-www-form-urlencoded"},
371
+ )
372
+ self.assertEqual(result, "mocked_access_token")
373
+
374
+ @patch.object(Authenticator, "_generate_jwt_token", return_value="sa_token")
375
+ @patch.object(Authenticator, "conf")
376
+ def test_get_stackit_client_service_account_custom_base_url(
377
+ self, mock_conf, mock_gen_jwt
378
+ ):
379
+ self.authenticator.service_account = "path/to/sa.json"
380
+ conf_values = {
381
+ "base-url": "https://custom.dns.api.stackit.cloud/",
382
+ "service_account": "path/to/sa.json",
383
+ "project-id": "proj-123",
384
+ }
385
+ mock_conf.side_effect = lambda key: conf_values.get(key)
386
+
387
+ client = self.authenticator._get_stackit_client()
388
+
389
+ self.assertEqual(client.base_url, "https://custom.dns.api.stackit.cloud")
390
+ self.assertEqual(client.project_id, "proj-123")
391
+ self.assertEqual(client.auth_token, "sa_token")
392
+
393
+ @patch.object(Authenticator, "conf", return_value=None)
394
+ def test_get_stackit_client_credentials_base_url(self, mock_conf):
395
+ mock_creds = Mock()
396
+ creds_values = {
397
+ "base_url": "https://ini.dns.api.stackit.cloud/",
398
+ "auth_token": "ini_token",
399
+ "project_id": "proj-456",
400
+ }
401
+ mock_creds.conf.side_effect = lambda key: creds_values.get(key)
402
+ self.authenticator.credentials = mock_creds
403
+
404
+ client = self.authenticator._get_stackit_client()
405
+
406
+ self.assertEqual(client.base_url, "https://ini.dns.api.stackit.cloud")
407
+ self.assertEqual(client.project_id, "proj-456")
408
+ self.assertEqual(client.auth_token, "ini_token")
409
+
354
410
  @patch("requests.post")
355
411
  def test_request_access_token_failure_raises_http_error(self, mock_post):
356
412
  mock_response = Response()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: certbot-dns-stackit
3
- Version: 0.1.10
3
+ Version: 0.1.11
4
4
  Summary: STACKIT DNS Authenticator plugin for Certbot
5
5
  Home-page: https://github.com/stackitcloud/certbot-dns-stackit
6
6
  Author: STACKIT DNS
@@ -97,6 +97,8 @@ certificates. The subsequent section delineates the pertinent arguments and thei
97
97
  | `--dns-stackit-project-id` | '8a4c68b1-586a-4534-aa0c-9f8c12334a76' | Sets the STACKIT project id if the service account authentication is used. (Recommended)|
98
98
  | `--dns-stackit-service-account` | ./service-account.pem | Denotes the directory path to the STACKIT service account file. (Recommended) |
99
99
  | `--dns-stackit-credentials` | ./credentials.ini | Denotes the directory path to the credentials file for STACKIT DNS. This document must encapsulate the dns_stackit_auth_token and dns_stackit_project_id variables. |
100
+ | `--dns-stackit-base-url` | https://dns.api.stackit.cloud | Sets the STACKIT DNS API base URL. (Default: https://dns.api.stackit.cloud) |
101
+ | `--dns-stackit-token-url` | https://service-account.api.stackit.cloud/token | Sets the STACKIT service account token endpoint URL when using service account authentication. (Default: https://service-account.api.stackit.cloud/token) |
100
102
  | `--dns-stackit-propagation-seconds` | 900 | Configures the delay prior to initiating the DNS record query. A 900-second interval (equivalent to 15 minutes) is recommended. (Default: 900) |
101
103
  Either the --dns-stackit-credentials flag or the --dns-stackit-service-account and --dns-stackit-project-id flags are mandatory.
102
104