mirror of
https://github.com/certbot/certbot.git
synced 2026-01-27 19:42:53 +03:00
Improve _get_v2_account()
Required for proper working of `certbot.main.update_registration()`. This function updates the `regr.body` locally instead of passing the fields which need to be updated to `acme.client.update_registration()` as a separate argument in the `update` parameter.
This commit is contained in:
@@ -8,6 +8,7 @@ import datetime
|
||||
from email.utils import parsedate_tz
|
||||
import heapq
|
||||
import http.client as http_client
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
@@ -672,7 +673,19 @@ class ClientV2(ClientBase):
|
||||
only_existing_reg = regr.body.update(only_return_existing=True)
|
||||
response = self._post(self.directory['newAccount'], only_existing_reg)
|
||||
updated_uri = response.headers['Location']
|
||||
new_regr = regr.update(body=messages.Registration.from_json(response.json()),
|
||||
|
||||
# Check for an empty `regr.body` by using the `json_dumps()` method to remove all the
|
||||
# `None` fields from the `regr.body` (subclass of `jose.JSONObjectWithFields`) object
|
||||
# which only leaves a `contact` field if everything else is `None`. The `contact` field
|
||||
# contains an empty list if the `regr.body` is empty.
|
||||
regr_body = json.loads(regr.body.json_dumps())
|
||||
regr_body_empty = bool(len(regr_body) == 1 and not regr_body['contact'])
|
||||
|
||||
# If the original `regr.body` was empty, populate it with info received from the
|
||||
# ACME server. If it isn't empty, pass through the original body, as it might be
|
||||
# an updated body in `certbot.main.update_account()`.
|
||||
new_regr = regr.update(body=messages.Registration.from_json(response.json())
|
||||
if regr_body_empty else regr.body,
|
||||
uri=updated_uri)
|
||||
self.net.account = new_regr
|
||||
return new_regr
|
||||
|
||||
Reference in New Issue
Block a user