Skip to content

feat: httpc_params_loader (httpc default timeout refactor) #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 2 additions & 4 deletions src/cryptojwt/key_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
from .jwk.rsa import RSAKey
from .jwk.rsa import new_rsa_key
from .utils import as_unicode
from .utils import httpc_params_loader

__author__ = "Roland Hedberg"

KEYLOADERR = "Failed to load %s key from '%s' (%s)"
REMOTE_FAILED = "Remote key update from '{}' failed, HTTP status {}"
MALFORMED = "Remote key update from {} failed, malformed JWKS."
DEFAULT_HTTPC_TIMEOUT = 10

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -254,9 +254,7 @@ def __init__(
else:
self.httpc = requests.request

self.httpc_params = httpc_params or {}
if "timeout" not in self.httpc_params:
self.httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
self.httpc_params = httpc_params_loader(httpc_params)

if keys:
self.source = None
Expand Down
6 changes: 2 additions & 4 deletions src/cryptojwt/key_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from .jwe.utils import alg2keytype as jwe_alg2keytype
from .jws.utils import alg2keytype as jws_alg2keytype
from .key_bundle import DEFAULT_HTTPC_TIMEOUT
from .key_bundle import KeyBundle
from .key_bundle import build_key_bundle
from .key_bundle import key_diff
from .key_bundle import update_key_bundle
from .utils import httpc_params_loader
from .utils import importer
from .utils import qualified_name

Expand Down Expand Up @@ -58,9 +58,7 @@ def __init__(

self.ca_certs = ca_certs
self.httpc = httpc or request
self.httpc_params = httpc_params or {}
if "timeout" not in self.httpc_params:
self.httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
self.httpc_params = httpc_params_loader(httpc_params)
self.keybundle_cls = keybundle_cls
self.name = name
self.remove_after = remove_after
Expand Down
6 changes: 2 additions & 4 deletions src/cryptojwt/key_jar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from .exception import IssuerNotFound
from .jwe.jwe import alg2keytype as jwe_alg2keytype
from .jws.utils import alg2keytype as jws_alg2keytype
from .key_bundle import DEFAULT_HTTPC_TIMEOUT
from .key_bundle import KeyBundle
from .key_issuer import KeyIssuer
from .key_issuer import build_keyissuer
from .key_issuer import init_key_issuer
from .utils import deprecated_alias
from .utils import httpc_params_loader
from .utils import importer
from .utils import qualified_name

Expand Down Expand Up @@ -51,9 +51,7 @@ def __init__(
self.keybundle_cls = keybundle_cls
self.remove_after = remove_after
self.httpc = httpc or request
self.httpc_params = httpc_params or {}
if "timeout" not in self.httpc_params:
self.httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
self.httpc_params = httpc_params_loader(httpc_params)

# Now part of httpc_params
# self.verify_ssl = verify_ssl
Expand Down
9 changes: 9 additions & 0 deletions src/cryptojwt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from cryptojwt.exception import BadSyntax

DEFAULT_HTTPC_TIMEOUT = 10

# ---------------------------------------------------------------------------
# Helper functions

Expand Down Expand Up @@ -255,3 +257,10 @@ def rename_kwargs(func_name, kwargs, aliases):
raise TypeError("{} received both {} and {}".format(func_name, alias, new))
warnings.warn("{} is deprecated; use {}".format(alias, new), DeprecationWarning)
kwargs[new] = kwargs.pop(alias)


def httpc_params_loader(httpc_params):
httpc_params = httpc_params or {}
if "timeout" not in httpc_params:
httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
return httpc_params