1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-27 19:42:53 +03:00

Typed jose fields (#9073)

* Add generic methods to save some casts, and fix lint

* Update current and oldest pinning

* Fix classes

* Remove some todos thanks to josepy 1.11.0

* Cleanup some useless pylint disable

* Finish complete typing

* Better TypeVar names

* Upgrade pinning and fix some typing errors

* Use protocol

* Fix types in apache

Co-authored-by: Brad Warren <bmw@users.noreply.github.com>
This commit is contained in:
Adrien Ferrand
2022-01-25 00:16:19 +01:00
committed by GitHub
parent 7198f43008
commit dac0b2c187
32 changed files with 398 additions and 325 deletions

View File

@@ -1180,7 +1180,7 @@ class NginxConfigurator(common.Configurator):
# Entry point in main.py for performing challenges
def perform(self, achalls: List[achallenges.AnnotatedChallenge]
) -> List[challenges.HTTP01Response]:
) -> List[challenges.ChallengeResponse]:
"""Perform the configuration related challenge.
This function currently assumes all challenges will be fulfilled.
@@ -1189,13 +1189,16 @@ class NginxConfigurator(common.Configurator):
"""
self._chall_out += len(achalls)
responses: List[Optional[challenges.HTTP01Response]] = [None] * len(achalls)
responses: List[Optional[challenges.ChallengeResponse]] = [None] * len(achalls)
http_doer = http_01.NginxHttp01(self)
for i, achall in enumerate(achalls):
# Currently also have chall_doer hold associated index of the
# challenge. This helps to put all of the responses back together
# when they are all complete.
if not isinstance(achall, achallenges.KeyAuthorizationAnnotatedChallenge):
raise errors.Error("Challenge should be an instance "
"of KeyAuthorizationAnnotatedChallenge")
http_doer.add_chall(achall, i)
http_response = http_doer.perform()

View File

@@ -11,7 +11,7 @@ from certbot_nginx._internal import nginxparser
from certbot_nginx._internal.obj import Addr
from acme import challenges
from acme.challenges import HTTP01Response
from acme.challenges import KeyAuthorizationChallengeResponse
from certbot import errors
from certbot.achallenges import KeyAuthorizationAnnotatedChallenge
from certbot.compat import os
@@ -49,10 +49,10 @@ class NginxHttp01(common.ChallengePerformer):
self.challenge_conf = os.path.join(
configurator.config.config_dir, "le_http_01_cert_challenge.conf")
def perform(self) -> List[HTTP01Response]:
def perform(self) -> List[KeyAuthorizationChallengeResponse]:
"""Perform a challenge on Nginx.
:returns: list of :class:`certbot.acme.challenges.HTTP01Response`
:returns: list of :class:`acme.challenges.KeyAuthorizationChallengeResponse`
:rtype: list
"""

View File

@@ -2,6 +2,7 @@
# Forked from https://github.com/fatiherikli/nginxparser (MIT Licensed)
import copy
import logging
import operator
import typing
from typing import Any
from typing import IO
@@ -167,13 +168,14 @@ class UnspacedList(List[Any]):
inbound = UnspacedList(inbound)
return inbound, inbound.spaced
def insert(self, i: int, x: Any) -> None:
def insert(self, i: "SupportsIndex", x: Any) -> None:
"""Insert object before index."""
idx = operator.index(i)
item, spaced_item = self._coerce(x)
slicepos = self._spaced_position(i) if i < len(self) else len(self.spaced)
slicepos = self._spaced_position(idx) if idx < len(self) else len(self.spaced)
self.spaced.insert(slicepos, spaced_item)
if not spacey(item):
super().insert(i, item)
super().insert(idx, item)
self.dirty = True
def append(self, x: Any) -> None:
@@ -246,7 +248,7 @@ class UnspacedList(List[Any]):
def _spaced_position(self, idx: "SupportsIndex") -> int:
"""Convert from indexes in the unspaced list to positions in the spaced one"""
int_idx = idx.__index__()
int_idx = operator.index(idx)
pos = spaces = 0
# Normalize indexes like list[-1] etc, and save the result
if int_idx < 0: