mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-08 07:24:56 -04:00
Add missing type hints to non-client REST servlets. (#10817)
Including admin, consent, key, synapse, and media. All REST servlets (the synapse.rest module) now require typed method definitions.
This commit is contained in:
parent
8c7a531e27
commit
b93259082c
27 changed files with 169 additions and 96 deletions
|
@ -12,16 +12,21 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from canonicaljson import encode_canonical_json
|
||||
from signedjson.sign import sign_json
|
||||
from unpaddedbase64 import encode_base64
|
||||
|
||||
from twisted.web.resource import Resource
|
||||
from twisted.web.server import Request
|
||||
|
||||
from synapse.http.server import respond_with_json_bytes
|
||||
from synapse.types import JsonDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from synapse.server import HomeServer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -58,18 +63,18 @@ class LocalKey(Resource):
|
|||
|
||||
isLeaf = True
|
||||
|
||||
def __init__(self, hs):
|
||||
def __init__(self, hs: "HomeServer"):
|
||||
self.config = hs.config
|
||||
self.clock = hs.get_clock()
|
||||
self.update_response_body(self.clock.time_msec())
|
||||
Resource.__init__(self)
|
||||
|
||||
def update_response_body(self, time_now_msec):
|
||||
def update_response_body(self, time_now_msec: int) -> None:
|
||||
refresh_interval = self.config.key_refresh_interval
|
||||
self.valid_until_ts = int(time_now_msec + refresh_interval)
|
||||
self.response_body = encode_canonical_json(self.response_json_object())
|
||||
|
||||
def response_json_object(self):
|
||||
def response_json_object(self) -> JsonDict:
|
||||
verify_keys = {}
|
||||
for key in self.config.signing_key:
|
||||
verify_key_bytes = key.verify_key.encode()
|
||||
|
@ -94,7 +99,7 @@ class LocalKey(Resource):
|
|||
json_object = sign_json(json_object, self.config.server.server_name, key)
|
||||
return json_object
|
||||
|
||||
def render_GET(self, request):
|
||||
def render_GET(self, request: Request) -> int:
|
||||
time_now = self.clock.time_msec()
|
||||
# Update the expiry time if less than half the interval remains.
|
||||
if time_now + self.config.key_refresh_interval / 2 > self.valid_until_ts:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue