Skip to content

Commit 92fc6b8

Browse files
Merge pull request #134 from benshalev849/master
Add user agent configuration to the new_account function.
2 parents 5c57ac6 + 4daeafc commit 92fc6b8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

simple_acme_dns/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,15 @@ def revoke_certificate(self, reason: int = 0) -> None:
285285
cert_obj = jose.ComparableX509(OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, self.certificate))
286286
self.acme_client.revoke(cert_obj, reason)
287287

288-
def new_account(self, verify_ssl=True) -> None:
288+
def new_account(self, verify_ssl=True, user_agent='simple_acme_dns/v2') -> None:
289289
"""
290290
Registers a new ACME account at the set ACME `directory` URL. By running this method, you are agreeing to the
291291
ACME servers terms of use.
292292
293293
Args:
294294
verify_ssl (bool): Verify the SSL certificate of the ACME server when making requests.
295-
295+
user_agent (str): Configures the user agent that is sent when making requests to the ACME server.
296+
296297
Examples:
297298
>>> client.new_account()
298299
"""
@@ -301,7 +302,7 @@ def new_account(self, verify_ssl=True) -> None:
301302
self.account_key = jose.JWKRSA(key=rsa_key)
302303

303304
# Initialize our ACME client object
304-
self.net = client.ClientNetwork(self.account_key, user_agent='simple_acme_dns/v2', verify_ssl=verify_ssl)
305+
self.net = client.ClientNetwork(self.account_key, user_agent=user_agent, verify_ssl=verify_ssl)
305306
self.directory_obj = messages.Directory.from_json(self.net.get(self.directory).json())
306307
self.acme_client = client.ClientV2(self.directory_obj, net=self.net)
307308

@@ -421,6 +422,7 @@ def load_account(json_data: str) -> 'ACMEClient':
421422

422423
# Format the serialized data back into the object
423424
verify_ssl = acct_data.get('verify_ssl', True)
425+
user_agent = acct_data.get('user_agent', 'simple_acme_dns/v2')
424426
obj.directory = acct_data.get('directory', None)
425427
obj.domains = acct_data.get('domains', [])
426428
obj.certificate = acct_data.get('certificate', '').encode()
@@ -431,7 +433,7 @@ def load_account(json_data: str) -> 'ACMEClient':
431433
obj.account_key = jose.JWKRSA.json_loads(acct_data['account_key'])
432434

433435
# Re-initialize the ACME client and registration
434-
obj.net = client.ClientNetwork(obj.account_key, user_agent='simple_acme_dns/1.0.0', verify_ssl=verify_ssl)
436+
obj.net = client.ClientNetwork(obj.account_key, user_agent=user_agent, verify_ssl=verify_ssl)
435437
obj.directory_obj = messages.Directory.from_json(obj.net.get(obj.directory).json())
436438
obj.acme_client = client.ClientV2(obj.directory_obj, net=obj.net)
437439
obj.account = obj.acme_client.query_registration(obj.account)

0 commit comments

Comments
 (0)