mirror of
https://github.com/certbot/certbot.git
synced 2026-06-03 13:59:02 -04: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:
parent
246d79b401
commit
e88a23ad76
1 changed files with 14 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ import datetime
|
||||||
from email.utils import parsedate_tz
|
from email.utils import parsedate_tz
|
||||||
import heapq
|
import heapq
|
||||||
import http.client as http_client
|
import http.client as http_client
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -672,7 +673,19 @@ class ClientV2(ClientBase):
|
||||||
only_existing_reg = regr.body.update(only_return_existing=True)
|
only_existing_reg = regr.body.update(only_return_existing=True)
|
||||||
response = self._post(self.directory['newAccount'], only_existing_reg)
|
response = self._post(self.directory['newAccount'], only_existing_reg)
|
||||||
updated_uri = response.headers['Location']
|
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)
|
uri=updated_uri)
|
||||||
self.net.account = new_regr
|
self.net.account = new_regr
|
||||||
return new_regr
|
return new_regr
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue