Skip to content
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

Add linter #3

Merged
merged 4 commits into from
Jul 17, 2023
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
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:1-3.8-bookworm",
"postCreateCommand": "pip3 install --user -r requirements.txt"
}
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
max_line_length = 120

[*.{yml,yaml,json,toml}]
indent_size = 2
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length=120

per-file-ignores =
src/joserfc/jws.py: E731
53 changes: 34 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ on:


jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Install dependencies
run: pip install -r requirements.txt

- name: flake8 lint
run: flake8 src/joserfc

test:
needs: lint
runs-on: ubuntu-latest

strategy:
Expand All @@ -30,22 +45,22 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pip install -r tests/requirements.txt

- name: Report coverage
run: pytest --cov=joserfc --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
name: GitHub
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pip install -r tests/requirements.txt

- name: Report coverage
run: pytest --cov=joserfc --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
name: GitHub
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ exclude_lines = [
"raise NotImplementedError",
"@(abc\\.)?abstractmethod",
]

[tool.mypy]
python_version = "3.8"
files = ["src/joserfc"]
show_error_codes = true
pretty = true
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cryptography
pycryptodome
mypy
flake8
6 changes: 5 additions & 1 deletion src/joserfc/jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ def detach_content(value: t.Union[str, JSONSerialization]):

>>> obj = jws.serialize_json({"protected": {"alg": "HS256"}}, b"hello", "secret")
>>> jws.detach_content(obj)
{'payload': '', 'signature': 'UYmO_lPAY5V0Wf4KZsfhiYs1SxqXPhxvjuYqellDV5A', 'protected': 'eyJhbGciOiJIUzI1NiJ9'}
{
'payload': '',
'signature': 'UYmO_lPAY5V0Wf4KZsfhiYs1SxqXPhxvjuYqellDV5A',
'protected': 'eyJhbGciOiJIUzI1NiJ9'
}
"""
if isinstance(value, str):
return detach_compact_content(value)
Expand Down
2 changes: 2 additions & 0 deletions src/joserfc/rfc7516/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"GeneralJSONSerialization",
]


class JSONRecipientDict(t.TypedDict, total=False):
header: t.Dict[str, t.Any]
encrypted_key: str
Expand All @@ -31,4 +32,5 @@ class FlattenJSONSerialization(t.TypedDict, total=False):
ciphertext: str
tag: str


JSONSerialization = t.Union[GeneralJSONSerialization, FlattenJSONSerialization]
12 changes: 10 additions & 2 deletions src/joserfc/rfc7517/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ def validate_dict_key(cls, data: KeyDict):
cls.binding.validate_dict_key_use_operations(data)

@classmethod
def import_key(cls, value: KeyAny, parameters: t.Optional[KeyParameters] = None, password: t.Optional[t.Any] = None) -> "BaseKey":
def import_key(
cls,
value: KeyAny,
parameters: t.Optional[KeyParameters] = None,
password: t.Optional[t.Any] = None) -> "BaseKey":
if isinstance(value, dict):
cls.validate_dict_key(value)
raw_key = cls.binding.import_from_dict(value)
Expand All @@ -226,7 +230,11 @@ def import_key(cls, value: KeyAny, parameters: t.Optional[KeyParameters] = None,
return cls(raw_key, value, parameters)

@classmethod
def generate_key(cls, size_or_crv, parameters: t.Optional[KeyParameters] = None, private: bool = True) -> "BaseKey":
def generate_key(
cls,
size_or_crv,
parameters: t.Optional[KeyParameters] = None,
private: bool = True) -> "BaseKey":
raise NotImplementedError()


Expand Down