-
Notifications
You must be signed in to change notification settings - Fork 17
Add type hints and make typing information available to users of the library #181
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2aae519
Sem-ver: bugfix Remove the need and use of asynctest during testing
dbaxa 706d59c
Sem-ver: api-break Add type hints to the code base
dbaxa 69d8f30
Sem-ver: bugfix Configure mypy and run it in ci
dbaxa d99e87b
Sem-ver: feature Provide type information to consumers of the library
dbaxa 52eb4ef
Sem-ver: bugfix Use __all__ instead of noqa
dbaxa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,19 @@ | ||
| from atlassian_jwt_auth.algorithms import get_permitted_algorithm_names # noqa | ||
|
|
||
| from atlassian_jwt_auth.signer import ( # noqa | ||
| from atlassian_jwt_auth.algorithms import get_permitted_algorithm_names | ||
| from atlassian_jwt_auth.key import ( | ||
| HTTPSPublicKeyRetriever, | ||
| KeyIdentifier, | ||
| ) | ||
| from atlassian_jwt_auth.signer import ( | ||
| create_signer, | ||
| create_signer_from_file_private_key_repository, | ||
| ) | ||
| from atlassian_jwt_auth.verifier import JWTAuthVerifier | ||
|
|
||
| from atlassian_jwt_auth.key import ( # noqa | ||
| KeyIdentifier, | ||
| HTTPSPublicKeyRetriever, | ||
| ) | ||
|
|
||
| from atlassian_jwt_auth.verifier import ( # noqa | ||
| JWTAuthVerifier, | ||
| ) | ||
| __all__ = [ | ||
| "get_permitted_algorithm_names", | ||
| "HTTPSPublicKeyRetriever", | ||
| "KeyIdentifier", | ||
| "create_signer", | ||
| "create_signer_from_file_private_key_repository", | ||
| "JWTAuthVerifier", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dbaxa marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,42 @@ | ||
| from __future__ import absolute_import | ||
|
|
||
| from typing import Any, Iterable, Union | ||
|
|
||
| import atlassian_jwt_auth | ||
| from atlassian_jwt_auth import KeyIdentifier | ||
| from atlassian_jwt_auth.signer import JWTAuthSigner | ||
|
|
||
|
|
||
| class BaseJWTAuth(object): | ||
| """Adds a JWT bearer token to the request per the ASAP specification""" | ||
|
|
||
| def __init__(self, signer, audience, *args, **kwargs): | ||
| def __init__( | ||
| self, | ||
| signer: JWTAuthSigner, | ||
| audience: Union[str, Iterable[str]], | ||
| *args: Any, | ||
| **kwargs: Any, | ||
| ) -> None: | ||
| self._audience = audience | ||
| self._signer = signer | ||
| self._additional_claims = kwargs.get("additional_claims", {}) | ||
|
|
||
| @classmethod | ||
| def create(cls, issuer, key_identifier, private_key_pem, audience, **kwargs): | ||
| def create( | ||
| cls, | ||
| issuer: str, | ||
| key_identifier: Union[KeyIdentifier, str], | ||
| private_key_pem: Union[str, bytes], | ||
| audience: Union[str, Iterable[str]], | ||
| **kwargs: Any, | ||
| ) -> "BaseJWTAuth": | ||
| """Instantiate a JWTAuth while creating the signer inline""" | ||
| signer = atlassian_jwt_auth.create_signer( | ||
| issuer, key_identifier, private_key_pem, **kwargs | ||
| ) | ||
| return cls(signer, audience) | ||
|
|
||
| def _get_header_value(self): | ||
| def _get_header_value(self) -> bytes: | ||
| return b"Bearer " + self._signer.generate_jwt( | ||
| self._audience, additional_claims=self._additional_claims | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,11 @@ | ||
| """Provide asyncio support""" | ||
|
|
||
| import sys | ||
|
|
||
| if sys.version_info >= (3, 5): | ||
| try: | ||
| import aiohttp # noqa | ||
| from .auth import JWTAuth # noqa | ||
| from .key import HTTPSPublicKeyRetriever # noqa | ||
| from .verifier import JWTAuthVerifier # noqa | ||
| except ImportError as e: | ||
| import warnings | ||
|
|
||
| warnings.warn(str(e)) | ||
|
|
||
|
|
||
| del sys | ||
| from .auth import JWTAuth | ||
| from .key import HTTPSPublicKeyRetriever | ||
| from .verifier import JWTAuthVerifier | ||
|
|
||
| __all__ = [ | ||
| "JWTAuth", | ||
| "HTTPSPublicKeyRetriever", | ||
| "JWTAuthVerifier", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,30 @@ | ||
| from __future__ import absolute_import | ||
|
|
||
| from typing import Any, Iterable, Union | ||
|
|
||
| import requests | ||
| from requests.auth import AuthBase | ||
|
|
||
| from atlassian_jwt_auth import KeyIdentifier | ||
| from atlassian_jwt_auth.auth import BaseJWTAuth | ||
|
|
||
|
|
||
| class JWTAuth(AuthBase, BaseJWTAuth): | ||
| """Adds a JWT bearer token to the request per the ASAP specification""" | ||
|
|
||
| def __call__(self, r): | ||
| r.headers["Authorization"] = self._get_header_value() | ||
| def __call__( | ||
| self, r: requests.models.PreparedRequest | ||
| ) -> requests.models.PreparedRequest: | ||
| r.headers["Authorization"] = self._get_header_value() # type: ignore[assignment] | ||
| return r | ||
|
|
||
|
|
||
| def create_jwt_auth(issuer, key_identifier, private_key_pem, audience, **kwargs): | ||
| def create_jwt_auth( | ||
| issuer: str, | ||
| key_identifier: Union[KeyIdentifier, str], | ||
| private_key_pem: str, | ||
| audience: Union[str, Iterable[str]], | ||
| **kwargs: Any, | ||
| ) -> BaseJWTAuth: | ||
| """Instantiate a JWTAuth while creating the signer inline""" | ||
| return JWTAuth.create(issuer, key_identifier, private_key_pem, audience, **kwargs) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.