-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add type hints to various handlers. #9223
Changes from 1 commit
8a72405
a4434a7
02b5509
3f2562b
706060a
23b3a58
50927fc
3f34357
f67b6e6
7115c66
47c7c16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,10 @@ | |
imported conditionally. | ||
""" | ||
import logging | ||
from typing import Dict, Iterable, List | ||
|
||
import attr | ||
import pem | ||
from cryptography.hazmat.backends import default_backend | ||
from cryptography.hazmat.primitives import serialization | ||
from josepy import JWKRSA | ||
|
@@ -36,20 +38,27 @@ | |
from zope.interface import implementer | ||
|
||
from twisted.internet import defer | ||
from twisted.internet.interfaces import IReactorTCP | ||
from twisted.python.filepath import FilePath | ||
from twisted.python.url import URL | ||
from twisted.web.resource import IResource | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_issuing_service(reactor, acme_url, account_key_file, well_known_resource): | ||
def create_issuing_service( | ||
reactor: IReactorTCP, | ||
acme_url: str, | ||
account_key_file: str, | ||
well_known_resource: IResource, | ||
) -> AcmeIssuingService: | ||
"""Create an ACME issuing service, and attach it to a web Resource | ||
|
||
Args: | ||
reactor: twisted reactor | ||
acme_url (str): URL to use to request certificates | ||
account_key_file (str): where to store the account key | ||
well_known_resource (twisted.web.IResource): web resource for .well-known. | ||
acme_url: URL to use to request certificates | ||
account_key_file: where to store the account key | ||
well_known_resource: web resource for .well-known. | ||
we will attach a child resource for "acme-challenge". | ||
|
||
Returns: | ||
|
@@ -83,18 +92,20 @@ class ErsatzStore: | |
A store that only stores in memory. | ||
""" | ||
|
||
certs = attr.ib(default=attr.Factory(dict)) | ||
certs = attr.ib(type=Dict[bytes, List[bytes]], default=attr.Factory(dict)) | ||
|
||
def store(self, server_name, pem_objects): | ||
def store( | ||
self, server_name: bytes, pem_objects: Iterable[pem.AbstractPEMObject] | ||
) -> defer.Deferred: | ||
self.certs[server_name] = [o.as_bytes() for o in pem_objects] | ||
return defer.succeed(None) | ||
|
||
|
||
def load_or_create_client_key(key_file): | ||
def load_or_create_client_key(key_file: str) -> JWKRSA: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should be writing stubs for libraries. Since we ignore the lib in mypy.ini it'll be treated as We do this in other places though, so happy to leave this as is and discuss the broader issue separately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that would make sense to do as a separate step? 🤷 The ACME stuff in particular is deprecated I think, so maybe not worthwhile to write stubs there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, I just know that we sometimes get confused at why mypy isn't picking up obvious bugs because of this sort of thing, but that can be dealt with separately There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I filed #9228. |
||
"""Load the ACME account key from a file, creating it if it does not exist. | ||
|
||
Args: | ||
key_file (str): name of the file to use as the account key | ||
key_file: name of the file to use as the account key | ||
""" | ||
# this is based on txacme.endpoint.load_or_create_client_key, but doesn't | ||
# hardcode the 'client.key' filename | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is just awaited and the return type is never used.