Skip to content

default httpc timeout if unset #94

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 1 commit into from
Oct 11, 2021
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
3 changes: 3 additions & 0 deletions src/cryptojwt/key_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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,6 +255,8 @@ def __init__(
self.httpc = requests.request

self.httpc_params = httpc_params or {}
if "timeout" not in self.httpc_params:
self.httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead or copy the same code all around probably it would be better to create a default httpc loader and use it in all the classes


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

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
Expand Down Expand Up @@ -58,6 +59,8 @@ 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.keybundle_cls = keybundle_cls
self.name = name
self.remove_after = remove_after
Expand Down
4 changes: 4 additions & 0 deletions src/cryptojwt/key_jar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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
Expand Down Expand Up @@ -51,6 +52,9 @@ def __init__(
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

# Now part of httpc_params
# self.verify_ssl = verify_ssl
if not self.httpc_params: # backward compatibility
Expand Down
2 changes: 1 addition & 1 deletion tests/test_04_key_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def test_localhost_url():

kb = issuer.find(url)
assert len(kb) == 1
assert kb[0].httpc_params == {"verify": False}
assert kb[0].httpc_params == {"timeout": 10, "verify": False}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops... That would be instead DEFAULT_HTTPC_TIMEOUT ...



def test_add_url():
Expand Down