def _check_or_add_account(self):
if 'account' in self._config:
account = self._config['account']
with open(account['key'], 'rb') as f:
data = f.read()
if account['key_type'] == 'raw':
key = data
elif account['key_type'] == 'pem':
key = serialization.load_pem_private_key(data, None, backend)
elif account['key_type'] == 'der':
key = serialization.load_der_private_key(data, None, backend)
else:
raise RuntimeError('Unknown key type: ' + account['key_type'])
registration = account['registration']
else:
registration, key = self._add_account()
links, account = self._client.registration(key, registration)
agreement = links.get('terms-of-service', {}).get('url')
if account.get('agreement') != agreement:
self._log('account: accepting {} in 5 seconds...',
agreement,
level=logging.WARN)
time.sleep(5)
self._client.registration(key, registration, agreement)
self._log('account: done')
return key
评论列表
文章目录