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

Update HTTP Basic auth for FastAPI and Starlette #32

Merged
merged 1 commit into from
Apr 18, 2021

Conversation

br3ndonland
Copy link
Owner

Description

The HTTP Basic auth methods have been useful as examples, but they could also be used by other applications when the inboard Python package has been installed. This PR will provide some updates to these methods.

The only potentially breaking change is that the default BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD will be removed. These environment variables must be set on the server to use HTTP Basic auth.

Changes

Update HTTP Basic auth for FastAPI and Starlette (2630dea)

  • Remove default username and password (IMPORTANT): the environment variables BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD must now be set on the server to use HTTP Basic auth. Defaults were provided as examples, but in production contexts, the defaults shouldn't be used.
  • Raise an exception if server HTTP Basic auth credentials are not set, and clients make requests to authenticate with HTTP Basic auth
  • Add docstrings to HTTP Basic auth methods
  • Update example username and password throughout tests and examples

Related

- Remove default username and password (**IMPORTANT**): the environment
  variables `BASIC_AUTH_USERNAME` and `BASIC_AUTH_PASSWORD` must now be
  set on the server to use HTTP Basic auth. Defaults were provided as
  examples, but in production contexts, the defaults shouldn't be used.
- Raise an exception if server HTTP Basic auth credentials are not set,
  and clients make requests to authenticate with HTTP Basic auth
- Add docstrings to HTTP Basic auth methods
- Update example username and password throughout tests and examples
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Apr 18, 2021

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.71%.

Quality metrics Before After Change
Complexity 0.80 ⭐ 1.02 ⭐ 0.22 👎
Method Length 38.96 ⭐ 41.04 ⭐ 2.08 👎
Working memory 7.07 🙂 7.04 🙂 -0.03 👍
Quality 82.35% 81.64% -0.71% 👎
Other metrics Before After Change
Lines 454 496 42
Changed files Quality Before Quality After Quality Change
inboard/app/main_starlette.py 90.20% ⭐ 90.20% ⭐ 0.00%
inboard/app/utilities_fastapi.py 84.20% ⭐ 81.33% ⭐ -2.87% 👎
inboard/app/utilities_starlette.py 66.42% 🙂 67.06% 🙂 0.64% 👍
tests/conftest.py 89.35% ⭐ 89.35% ⭐ 0.00%
tests/app/test_main.py 78.44% ⭐ 78.59% ⭐ 0.15% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
tests/app/test_main.py TestEndpoints.test_get_status_message 4 ⭐ 103 🙂 12 😞 60.98% 🙂 Extract out complex expressions
inboard/app/utilities_fastapi.py set_fields_from_pyproject 1 ⭐ 57 ⭐ 12 😞 70.74% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

@codecov
Copy link

codecov bot commented Apr 18, 2021

Codecov Report

Merging #32 (2630dea) into develop (c9dd974) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           develop       #32   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          256       264    +8     
=========================================
+ Hits           256       264    +8     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
inboard/app/main_starlette.py 100.00% <ø> (ø)
inboard/app/utilities_fastapi.py 100.00% <100.00%> (ø)
inboard/app/utilities_starlette.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c9dd974...2630dea. Read the comment docs.

@br3ndonland br3ndonland merged commit a0ab4d0 into develop Apr 18, 2021
@br3ndonland br3ndonland deleted the update-http-basic-auth branch April 18, 2021 20:02
@br3ndonland br3ndonland mentioned this pull request Apr 18, 2021
1 task
br3ndonland added a commit that referenced this pull request Apr 19, 2021
#20
#32
#33

This commit will refine the imports in inboard/`__init__.py` so that
FastAPI and Starlette are imported separately. This way, if Starlette is
installed but FastAPI is not, the HTTP Basic auth implementation for
Starlette can still be imported and added to `__all__`.
@br3ndonland br3ndonland mentioned this pull request May 16, 2021
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant