Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions keystone_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import abc
from typing import Any, Dict, Optional, Union
from typing import Any, Callable, Dict, Optional, Union

import httpx
from httpx import HTTPStatusError
Expand Down Expand Up @@ -57,19 +57,19 @@ def is_authenticated(self) -> dict:
"""Return metadata for the currently authenticated user."""

@abc.abstractmethod
def _create_factory(self, endpoint: Endpoint) -> callable:
def _create_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data creation methods."""

@abc.abstractmethod
def _retrieve_factory(self, endpoint: Endpoint) -> callable:
def _retrieve_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data retrieval methods."""

@abc.abstractmethod
def _update_factory(self, endpoint: Endpoint) -> callable:
def _update_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data update methods."""

@abc.abstractmethod
def _delete_factory(self, endpoint: Endpoint) -> callable:
def _delete_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data deletion methods."""

@staticmethod
Expand Down Expand Up @@ -215,7 +215,7 @@ def is_authenticated(self, timeout: int = httpx.USE_CLIENT_DEFAULT) -> dict:
response = self.http_get(self.IDENTITY_ENDPOINT, timeout=timeout)
return self._handle_identity_response(response)

def _create_factory(self, endpoint: Endpoint) -> callable:
def _create_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data creation methods."""

def create_record(data: Optional[RequestData] = None, files: Optional[RequestFiles] = None) -> dict:
Expand All @@ -235,7 +235,7 @@ def create_record(data: Optional[RequestData] = None, files: Optional[RequestFil

return create_record

def _retrieve_factory(self, endpoint: Endpoint) -> callable:
def _retrieve_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data retrieval methods."""

def retrieve_record(
Expand Down Expand Up @@ -269,7 +269,7 @@ def retrieve_record(

return retrieve_record

def _update_factory(self, endpoint: Endpoint) -> callable:
def _update_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data update methods."""

def update_record(
Expand All @@ -294,7 +294,7 @@ def update_record(

return update_record

def _delete_factory(self, endpoint: Endpoint) -> callable:
def _delete_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data deletion methods."""

def delete_record(pk: int, raise_not_exists: bool = False) -> None:
Expand Down Expand Up @@ -366,7 +366,7 @@ async def is_authenticated(self, timeout: int = httpx.USE_CLIENT_DEFAULT) -> dic
response = await self.http_get(self.IDENTITY_ENDPOINT, timeout=timeout)
return self._handle_identity_response(response)

def _create_factory(self, endpoint: Endpoint) -> callable:
def _create_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data creation methods."""

async def create_record(data: Optional[RequestData] = None, files: Optional[RequestFiles] = None) -> dict:
Expand All @@ -386,7 +386,7 @@ async def create_record(data: Optional[RequestData] = None, files: Optional[Requ

return create_record

def _retrieve_factory(self, endpoint: Endpoint) -> callable:
def _retrieve_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data retrieval methods."""

async def retrieve_record(
Expand Down Expand Up @@ -420,7 +420,7 @@ async def retrieve_record(

return retrieve_record

def _update_factory(self, endpoint: Endpoint) -> callable:
def _update_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data update methods."""

async def update_record(
Expand All @@ -445,7 +445,7 @@ async def update_record(

return update_record

def _delete_factory(self, endpoint: Endpoint) -> callable:
def _delete_factory(self, endpoint: Endpoint) -> Callable:
"""Factory function for data deletion methods."""

async def delete_record(pk: int, raise_not_exists: bool = False) -> None:
Expand Down
16 changes: 5 additions & 11 deletions keystone_client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@

from .log import DefaultContextAdapter

DEFAULT_TIMEOUT = 15
DEFAULT_REDIRECTS = 10
DEFAULT_VERIFY = True
DEFAULT_FOLLOW = True
DEFAULT_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)

HttpMethod = Literal["get", "post", "put", "patch", "delete"]

logger = logging.getLogger('kclient')
Expand All @@ -41,11 +35,11 @@ def __init__(
self,
base_url: str,
*,
verify_ssl: bool = DEFAULT_VERIFY,
follow_redirects: bool = DEFAULT_FOLLOW,
max_redirects: int = DEFAULT_REDIRECTS,
timeout: Optional[int] = DEFAULT_TIMEOUT,
limits: httpx.Limits = DEFAULT_LIMITS,
verify_ssl: bool = True,
follow_redirects: bool = False,
max_redirects: int = 10,
timeout: Optional[int] = 15,
limits: httpx.Limits = httpx.Limits(max_connections=100, max_keepalive_connections=20),
transport: Optional[httpx.BaseTransport] = None,
) -> None:
"""Initialize a new HTTP session.
Expand Down
3 changes: 2 additions & 1 deletion keystone_client/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import logging
from typing import Literal


class DefaultContextAdapter(logging.LoggerAdapter):
Expand All @@ -32,7 +33,7 @@ class ContextFilter(logging.Filter):

required_attr = ("cid", "baseurl", "method", "endpoint", "url")

def filter(self, record: logging.LogRecord) -> True:
def filter(self, record: logging.LogRecord) -> Literal[True]:
"""Ensure a log record has all required contextual attributes.

Any missing contextual attributes are set to an empty string.
Expand Down
Loading