-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/dpcops 8952 #51
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,5 @@ | |
| /output | ||
|
|
||
| __pycache__ | ||
|
|
||
| *.egg-info | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| [project] | ||
| name = "aws-cloudfront-authorizer" | ||
| version = "1.0.0" | ||
| requires-python = ">=3.12" | ||
| dependencies = [ | ||
| "invoke>=2.2.1", | ||
| "pytest", | ||
| "troposphere>=4.10.1", | ||
| ] | ||
|
|
||
| [tool.uv] | ||
| package = true | ||
|
|
||
| [tool.uv.sources] | ||
| central-helpers = { git = "ssh://git@bitbucket.org/vrt-prod/aws-cloudformation-helpers.git" } | ||
| custom-resources = { git = "https://github.com/vrtdev/custom-resources.git" } | ||
|
|
||
| [tool.setuptools] | ||
| packages = [ | ||
| "templates", | ||
| ] | ||
|
|
||
| [tool.ruff] | ||
| line-length = 140 | ||
| indent-width = 4 | ||
|
|
||
| [tool.ruff.lint] | ||
| extend-select = [ | ||
| "E", | ||
| "W", | ||
| "A", | ||
| "COM", | ||
| "TID", | ||
| "B", | ||
| "SIM", | ||
| "UP", | ||
| ] | ||
|
|
||
| [[tool.uv.index]] | ||
| name = "nexus" | ||
| url = "https://nexus.core.a51.be/repository/pypi/simple" | ||
| default = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,25 @@ | ||
| import time | ||
| from urllib.parse import urlsplit, urlunsplit, urlencode | ||
| from urllib.parse import urlencode, urlsplit, urlunsplit | ||
|
|
||
| import jwt | ||
| from aws_lambda_powertools import Logger | ||
| from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
|
||
| from utils import ( | ||
| BadRequest, | ||
| InternalServerError, | ||
| NotLoggedIn, | ||
| access_token_from_refresh_token, | ||
| bad_request, | ||
| get_config, | ||
| get_refresh_token, | ||
| get_state_jwt_secret, | ||
| internal_server_error, | ||
| is_allowed_domain, | ||
| redirect_to_cognito, | ||
| ) | ||
|
|
||
| logger = Logger() | ||
|
|
||
| from utils import get_config, bad_request, get_access_token_jwt_secret, redirect_to_cognito, NotLoggedIn, BadRequest, \ | ||
| InternalServerError, internal_server_error, get_refresh_token, get_state_jwt_secret, is_allowed_domain, \ | ||
| access_token_from_refresh_token | ||
|
|
||
| @logger.inject_lambda_context | ||
| def handler(event, context: LambdaContext) -> dict: | ||
|
|
@@ -45,15 +55,15 @@ def handler(event, context: LambdaContext) -> dict: | |
| logger.error(f"{redirect_uri} is not an allowed domain") | ||
| return bad_request('', f"{redirect_uri} is not an allowed domain") | ||
|
|
||
| if 'domains' in refresh_token: # delegated token with domain restrictions | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ik weet dat RUFF nogal opinionated is, maar ik vind de twee if-statements duidelijker dan de gecombineerde. De comment vond ik ook beter staan na de |
||
| if redirect_uri_comp.netloc not in refresh_token['domains']: | ||
| logger.error(f"{redirect_uri} is not an allowed domain for this refresh token") | ||
| return bad_request('', f"{redirect_uri} is not an allowed domain for this refresh token") | ||
| # delegated token with domain restrictions | ||
| if 'domains' in refresh_token and redirect_uri_comp.netloc not in refresh_token['domains']: | ||
| logger.error(f"{redirect_uri} is not an allowed domain for this refresh token") | ||
| return bad_request('', f"{redirect_uri} is not an allowed domain for this refresh token") | ||
|
|
||
| try: | ||
| access_token = access_token_from_refresh_token( | ||
| refresh_token, | ||
| redirect_uri_comp.netloc | ||
| redirect_uri_comp.netloc, | ||
| ) | ||
| except BadRequest as e: | ||
| return bad_request('', e) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| import json | ||
|
|
||
| from utils import bad_request, NotLoggedIn, BadRequest, \ | ||
| InternalServerError, internal_server_error, get_refresh_token, get_domains, \ | ||
| access_token_from_refresh_token | ||
| from aws_lambda_powertools import Logger | ||
| from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
|
||
| from utils import ( | ||
| BadRequest, | ||
| InternalServerError, | ||
| NotLoggedIn, | ||
| access_token_from_refresh_token, | ||
| bad_request, | ||
| get_domains, | ||
| get_refresh_token, | ||
| internal_server_error, | ||
| ) | ||
|
|
||
| logger = Logger() | ||
|
|
||
| @logger.inject_lambda_context | ||
|
|
@@ -25,10 +33,8 @@ def handler(event, context: LambdaContext) -> dict: | |
| except InternalServerError as e: | ||
| return internal_server_error('', e) | ||
|
|
||
| if 'domains' in refresh_token: # delegated token with domain restrictions | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dit vind het origineel hier ook duidelijker dan de ruff-versie |
||
| domains = refresh_token['domains'] | ||
| else: | ||
| domains = get_domains() | ||
| # delegated token with domain restrictions | ||
| domains = refresh_token['domains'] if 'domains' in refresh_token else get_domains() | ||
|
|
||
| access_tokens = {} | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is het de bedoeling om dit stukje logging te verliezen? Ik zie dezelfde change op nog plaatsen