Skip to content

Commit f727a85

Browse files
committed
Added all 😄
1 parent 0b47637 commit f727a85

30 files changed

+2472
-1
lines changed

.github/workflows/bump.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Bump Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: New Version (e.i. 0.0.0)
8+
required: true
9+
10+
env:
11+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12+
13+
jobs:
14+
bump-version:
15+
name: Bump Package Version
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v1
19+
with:
20+
ref: ${{ github.head_ref }}
21+
- name: Update version file
22+
run: echo "${{ github.event.inputs.version }}" > VERSION
23+
- name: Commit version file
24+
run: |
25+
git config --global user.name ${{ github.actor }}
26+
git config --global user.email '${{ github.actor }}@users.noreply.github.com'
27+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
28+
git commit -am "Automated version update to ${{ github.event.inputs.version }}"
29+
- name: Example variable usage
30+
run: git tag ${{ github.event.inputs.version }}
31+
- name: Push all
32+
run: |
33+
git status
34+
git log --raw
35+
git push

.github/workflows/publish.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
# Sequence of patterns matched against refs/tags
6+
tags:
7+
- 'v*.*.*' # i.e. v1.0.0, v20.15.10
8+
- '*.*.*' # i.e. 1.0.0, 20.15.10
9+
10+
jobs:
11+
12+
release-github:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Create Release
17+
id: create_release
18+
uses: actions/create-release@v1
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
with:
22+
tag_name: ${{ github.ref }}
23+
release_name: ${{ github.ref }}
24+
draft: false
25+
prerelease: false
26+
27+
release-python-package:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Setup Python 3.9
33+
uses: actions/setup-python@v2
34+
with:
35+
python-version: 3.9
36+
- name: Build python package
37+
run: |
38+
python -m pip install wheel
39+
python -m pip wheel . --no-deps --wheel-dir dist
40+
twine upload -r testpypi dist/*
41+
twine upload dist/*
42+
43+
release-github-pages:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
- name: Setup Python 3.9
48+
uses: actions/setup-python@v2
49+
with:
50+
python-version: 3.9
51+
- uses: actions/cache@v2
52+
with:
53+
path: ${{ env.pythonLocation }}
54+
key: ${{ runner.os }}-python-3.9-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'setup.cfg') }}-docs
55+
restore-keys: |
56+
${{ runner.os }}-python-3.9-
57+
${{ runner.os }}-python-
58+
${{ runner.os }}-
59+
- name: Install dependencies
60+
run: python -m pip install -e .[docs]
61+
- name: Build and publish docs
62+
run: |
63+
git fetch --all
64+
# lazydocs
65+
python -m mkdocs build --config-file docs/mkdocs.yml
66+
python -m mkdocs gh-deploy --config-file docs/mkdocs.yml --force

.github/workflows/test.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
lint-python:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-python@v2
15+
with: { python-version: 3.9 }
16+
- uses: actions/cache@v2
17+
with:
18+
path: ${{ env.pythonLocation }}
19+
key: ${{ runner.os }}-python-${{ matrix.python-version }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'setup.cfg') }}-test
20+
restore-keys: |
21+
${{ runner.os }}-python-${{ matrix.python-version }}-
22+
${{ runner.os }}-python-
23+
${{ runner.os }}-
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install wheel
27+
python -m pip install -e .[test]
28+
- name: Run isort
29+
run: python -m isort fastapi_jwt --check
30+
- name: Run flake8
31+
run: python -m flake8 fastapi_jwt
32+
- name: Run mypy
33+
run: python -m mypy fastapi_jwt
34+
- name: Run pylint
35+
run: python -m pylint fastapi_jwt
36+
37+
test-python:
38+
runs-on: ubuntu-latest
39+
strategy:
40+
matrix:
41+
python-version: ['3.7', '3.8', '3.9', '3.10']
42+
fail-fast: false
43+
steps:
44+
- uses: actions/checkout@v2
45+
- name: Set up Python ${{ matrix.python-version }}
46+
uses: actions/setup-python@v2
47+
with:
48+
python-version: ${{ matrix.python-version }}
49+
- uses: actions/cache@v2
50+
with:
51+
path: ${{ env.pythonLocation }}
52+
key: ${{ runner.os }}-python-${{ matrix.python-version }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'setup.cfg') }}-test
53+
restore-keys: |
54+
${{ runner.os }}-python-${{ matrix.python-version }}-
55+
${{ runner.os }}-python-
56+
${{ runner.os }}-
57+
- name: Install dependencies
58+
run: |
59+
python -m pip install wheel
60+
python -m pip install -e .[test]
61+
- name: Test itself
62+
run: python -m pytest
63+
- name: Upload coverage
64+
uses: codecov/codecov-action@v2
65+
with:
66+
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
67+
flags: unittests # optional
68+
fail_ci_if_error: true # optional (default = false)
69+
verbose: true # optional (default = false)

CHANGELOG.md

Whitespace-only changes.

README.md

+60-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
# fastapi-jwt
2-
FastAPI extension for JWT auth
2+
3+
[![Test](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml)
4+
[![Publish](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml)
5+
[![codecov](https://codecov.io/gh/k4black/fastapi-jwt/branch/master/graph/badge.svg?token=3F9J850FX2)](https://codecov.io/gh/k4black/fastapi-jwt)
6+
[![pypi](https://img.shields.io/pypi/v/fastapi-jwt)](https://pypi.org/project/fastapi-jwt/)
7+
8+
Native FastAPI extension for JWT auth
9+
10+
---
11+
12+
13+
**Documentation:** https://k4black.github.io/fastapi-jwt/
14+
**Source Code:** https://github.com/k4black/fastapi-jwt/
15+
16+
17+
## Installation
18+
```shell
19+
pip install fastapi-jwt
20+
```
21+
22+
23+
## Usage
24+
This library made in fastapi style, so it can be used similarly with standard security features
25+
26+
```python
27+
app = FastAPI()
28+
29+
30+
access_security = JwtAccessBearer(secret_key="secret_key", auto_error=False)
31+
32+
33+
@app.post("/auth")
34+
def auth():
35+
subject = {"username": "username", "role": "user"}
36+
return {"access_token": access_security.create_access_token(subject=subject)}
37+
38+
39+
@app.get("/users/me")
40+
def read_current_user(
41+
credentials: JwtAuthorizationCredentials = Security(access_security),
42+
):
43+
return {"username": credentials["username"], "role": credentials["role"]}
44+
```
45+
46+
47+
## Alternatives
48+
49+
### [fastapi-jwt-auth](https://github.com/IndominusByte/fastapi-jwt-auth/)
50+
Nice lib, however
51+
* poorly supported
52+
* not "fastapi-style" (as native functions parameters)
53+
54+
## FastAPI Integration
55+
56+
There it is open and maintained [Pull Request #3305](https://github.com/tiangolo/fastapi/pull/3305) to the `fastapi` repo. Currently, not considered.
57+
58+
## Requirements
59+
60+
* `fastapi`
61+
* `python-jose[cryptography]`

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

docs/docs/developing.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Developing
2+
3+
Install dev dependencies
4+
```shell
5+
python -m pip install .[docs] # \[docs\] in zsh
6+
```
7+
8+
9+
---
10+
11+
## Python package
12+
13+
### Linting and Testing
14+
15+
It is important NOT ONLY to get OK from all linters (or achieve score in the case of pylint), but also to write good code.
16+
P.S. It's hard to say what a Good Code is. Let's say that it should be simple, clear, commented, and so on.
17+
```shell
18+
python -m flake8 .
19+
python -m mypy fastapi_jwt
20+
python -m pylint fastapi_jwt # fails under score 7
21+
python -m isort . --check
22+
```
23+
24+
Try NOT ONLY to achieve 100% coverage, but also to cover extreme cases, height load cases, multithreaded cases, incorrect input, and so on.
25+
```shell
26+
python -m pytest
27+
```
28+
29+
You can fix some issues in auto mode.
30+
31+
* Sorting imports and make autopep.
32+
```shell
33+
python -m isort .
34+
```
35+
36+
37+
### Publishing
38+
39+
Egg (deprecated)
40+
```shell
41+
python3 setup.py build
42+
python3 setup.py sdist
43+
twine upload -r testpypi dist/*
44+
twine upload dist/*
45+
```
46+
47+
Build Wheel and see what inside
48+
```shell
49+
python3 -m pip wheel . --no-deps --wheel-dir dist
50+
tar --list -f dist/fastapi-jwt-0.0.1-py3-none-any.whl
51+
```
52+
53+
Load dist to pypi
54+
```shell
55+
twine upload -r testpypi dist/*
56+
twine upload dist/*
57+
```
58+
59+
60+
---
61+
62+
## Docs
63+
64+
### Editing
65+
66+
Edit it in `docs/`
67+
68+
`mkdocs` can be run as dev server with auto-reload.
69+
```shell
70+
mkdocs serve --config-file docs/mkdocs.yml
71+
```
72+
73+
Note: Server will auto-restart for all changed `docs/*` files.
74+
If you want to edit `README.md` or `CONTRIBUTING.md` you should restart server on each change.
75+
76+
77+
### Building (`TODO`)
78+
79+
Add python backend docs `TODO`
80+
```shell
81+
lazydocs \
82+
--output-path="./docs/references/backend" \
83+
--overview-file="index.md" \
84+
--src-base-url="https://github.com/k4black/flowingo/blob/master" \
85+
flowingo
86+
```
87+
88+
### Deploy
89+
90+
#### Without versioning (now)
91+
Build and deploy docs itself
92+
```shell
93+
mkdocs build --config-file docs/mkdocs.yml
94+
mkdocs gh-deploy --config-file docs/mkdocs.yml
95+
```
96+
97+
#### With `mike` as versioning tool (`TODO`)
98+
99+
Deploy with `mike` to github-pages with versioning support
100+
```shell
101+
mike deploy --config-file docs/mkdocs.yml 0.0.1 latest --push
102+
mike alias --config-file docs/mkdocs.yml 0.0.1 0.0.x --push
103+
mike set-default --config-file docs/mkdocs.yml latest --push
104+
```
105+
106+
#### With `read-the-docs` as versioning tool (`TODO`)
107+
Deploy with `mkdocs` to read-the-docs for versioning support
108+
```shell
109+
TODO
110+
```
111+

docs/docs/images

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../images

docs/docs/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{%
2+
include-markdown "../../README.md"
3+
heading-offset=0
4+
%}

docs/docs/overrides/main.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:root {
2+
--md-primary-fg-color: #b71ac7;
3+
--md-primary-fg-color--light: #9c0cab;
4+
--md-primary-fg-color--dark: #cf2de0;
5+
}

docs/docs/release-notes.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{%
2+
include-markdown "../../CHANGELOG.md"
3+
heading-offset=0
4+
%}

0 commit comments

Comments
 (0)