From 052f912eef8d5768670bfd41a226f79fdf44bb4e Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 14:01:52 +0200 Subject: [PATCH 01/28] Add Azure Function Baseline --- .vscode/extensions.json | 6 ++ .vscode/launch.json | 12 +++ .vscode/settings.json | 9 +++ .vscode/tasks.json | 33 ++++++++ code/function/.funcignore | 8 ++ code/function/.gitignore | 135 +++++++++++++++++++++++++++++++ code/function/function_app.py | 25 ++++++ code/function/getting_started.md | 48 +++++++++++ code/function/host.json | 15 ++++ code/function/requirements.txt | 5 ++ 10 files changed, 296 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 code/function/.funcignore create mode 100644 code/function/.gitignore create mode 100644 code/function/function_app.py create mode 100644 code/function/getting_started.md create mode 100644 code/function/host.json create mode 100644 code/function/requirements.txt diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..3f63eb9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions", + "ms-python.python" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4508b45 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Python Functions", + "type": "python", + "request": "attach", + "port": 9091, + "preLaunchTask": "func: host start" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f48aa7d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "azureFunctions.deploySubpath": "code\\function", + "azureFunctions.scmDoBuildDuringDeployment": true, + "azureFunctions.pythonVenv": ".venv", + "azureFunctions.projectLanguage": "Python", + "azureFunctions.projectRuntime": "~4", + "debug.internalConsoleOptions": "neverOpen", + "azureFunctions.projectLanguageModel": 2 +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..07bb5a6 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,33 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "func", + "label": "func: host start", + "command": "host start", + "problemMatcher": "$func-python-watch", + "isBackground": true, + "dependsOn": "pip install (functions)", + "options": { + "cwd": "${workspaceFolder}/code\\function" + } + }, + { + "label": "pip install (functions)", + "type": "shell", + "osx": { + "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" + }, + "windows": { + "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt" + }, + "linux": { + "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" + }, + "problemMatcher": [], + "options": { + "cwd": "${workspaceFolder}/code\\function" + } + } + ] +} \ No newline at end of file diff --git a/code/function/.funcignore b/code/function/.funcignore new file mode 100644 index 0000000..9966315 --- /dev/null +++ b/code/function/.funcignore @@ -0,0 +1,8 @@ +.git* +.vscode +__azurite_db*__.json +__blobstorage__ +__queuestorage__ +local.settings.json +test +.venv \ No newline at end of file diff --git a/code/function/.gitignore b/code/function/.gitignore new file mode 100644 index 0000000..7685fc4 --- /dev/null +++ b/code/function/.gitignore @@ -0,0 +1,135 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don’t work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Azure Functions artifacts +bin +obj +appsettings.json +local.settings.json + +# Azurite artifacts +__blobstorage__ +__queuestorage__ +__azurite_db*__.json +.python_packages \ No newline at end of file diff --git a/code/function/function_app.py b/code/function/function_app.py new file mode 100644 index 0000000..10273b5 --- /dev/null +++ b/code/function/function_app.py @@ -0,0 +1,25 @@ +import azure.functions as func +import logging + +app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) + +@app.route(route="HttpTrigger") +def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse: + logging.info('Python HTTP trigger function processed a request.') + + name = req.params.get('name') + if not name: + try: + req_body = req.get_json() + except ValueError: + pass + else: + name = req_body.get('name') + + if name: + return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.") + else: + return func.HttpResponse( + "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", + status_code=200 + ) \ No newline at end of file diff --git a/code/function/getting_started.md b/code/function/getting_started.md new file mode 100644 index 0000000..d20aeea --- /dev/null +++ b/code/function/getting_started.md @@ -0,0 +1,48 @@ +# Getting Started with Azure Functions in Python + + +## Python Programming Model V2 + +The new programming model in Azure Functions Python delivers an experience that aligns with Python development principles, and subsequently with commonly used Python frameworks. + +The improved programming model requires fewer files than the default model, and specifically eliminates the need for a configuration file (`function.json`). Instead, triggers and bindings are represented in the `function_app.py` file as decorators. Moreover, functions can be logically organized with support for multiple functions to be stored in the same file. Functions within the same function application can also be stored in different files, and be referenced as blueprints. + +In addition to the [documentation](https://docs.microsoft.com/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level), hints are available in code editors that support type checking with PYI files. + +To learn more about the new programming model for Azure Functions in Python, see [Programming Models in Azure Functions](https://aka.ms/functions-programming-models). + +## Notes + +- Mix and match of Functions written in the V1 programming model and the V2 programming model in the same Function App will not be supported. +- At this time, the main functions file must be named `function_app.py`. + +To learn more about the new programming model for Azure Functions in Python, see the [Azure Functions Python developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level). + +## Getting Started + +Project Structure + +The main project folder () can contain the following files: + +* *function_app.py*: Functions along with their triggers and bindings are defined here. +* *local.settings.json*: Used to store app settings and connection strings when running locally. This file doesn't get published to Azure. +* *requirements.txt*: Contains the list of Python packages the system installs when publishing to Azure. +* *host.json*: Contains configuration options that affect all functions in a function app instance. This file does get published to Azure. Not all options are supported when running locally. +* *blueprint.py*: (Optional) Functions that are defined in a separate file for logical organization and grouping, that can be referenced in `function_app.py`. +* *.vscode/*: (Optional) Contains store VSCode configuration. +* *.venv/*: (Optional) Contains a Python virtual environment used by local development. +* *Dockerfile*: (Optional) Used when publishing your project in a custom container. +* *tests/*: (Optional) Contains the test cases of your function app. +* *.funcignore*: (Optional) Declares files that shouldn't get published to Azure. Usually, this file contains `.vscode/` to ignore your editor setting, `.venv/` to ignore local Python virtual environment, `tests/` to ignore test cases, and `local.settings.json` to prevent local app settings being published. + +## Developing your first Python function using VS Code + +If you have not already, please checkout our [quickstart](https://aka.ms/fxpythonquickstart) to get you started with Azure Functions developments in Python. + +## Publishing your function app to Azure + +For more information on deployment options for Azure Functions, please visit this [guide](https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python#publish-the-project-to-azure). + +## Next Steps + +To learn more specific guidance on developing Azure Functions with Python, please visit [Azure Functions Developer Python Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level). \ No newline at end of file diff --git a/code/function/host.json b/code/function/host.json new file mode 100644 index 0000000..9df9136 --- /dev/null +++ b/code/function/host.json @@ -0,0 +1,15 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[4.*, 5.0.0)" + } +} \ No newline at end of file diff --git a/code/function/requirements.txt b/code/function/requirements.txt new file mode 100644 index 0000000..85267c5 --- /dev/null +++ b/code/function/requirements.txt @@ -0,0 +1,5 @@ +# DO NOT include azure-functions-worker in this file +# The Python Worker is managed by Azure Functions platform +# Manually managing azure-functions-worker may cause unexpected issues + +azure-functions \ No newline at end of file From 25a7f2853955caf2a25cb56c41478434946ff146 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 14:01:58 +0200 Subject: [PATCH 02/28] Update tf config --- code/infra/terraform.tf | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/infra/terraform.tf b/code/infra/terraform.tf index ef727c6..9d58753 100644 --- a/code/infra/terraform.tf +++ b/code/infra/terraform.tf @@ -37,9 +37,6 @@ provider "azurerm" { recover_soft_deleted_keys = true recover_soft_deleted_secrets = true } - network { - relaxed_locking = true - } resource_group { prevent_deletion_if_contains_resources = true } From d6d078fd973b4629749a8e8af9e40aa0525bd812 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 14:22:44 +0200 Subject: [PATCH 03/28] lint --- .pre-commit-config.yaml | 9 +++++ .vscode/extensions.json | 2 +- .vscode/launch.json | 22 +++++------ .vscode/settings.json | 16 ++++---- .vscode/tasks.json | 64 ++++++++++++++++---------------- code/function/.funcignore | 2 +- code/function/.gitignore | 2 +- code/function/function_app.py | 20 ++++++---- code/function/getting_started.md | 14 +++---- code/function/host.json | 2 +- code/function/requirements.txt | 2 +- 11 files changed, 84 insertions(+), 71 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 978da8d..35370ec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,15 @@ repos: - id: check-yaml - id: pretty-format-json args: ["--indent", "2", "--autofix", "--no-sort-keys"] + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["--profile", "black", "--filter-files"] + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black - repo: local hooks: - id: terraform-fmt diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 3f63eb9..cbbad0f 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,4 +3,4 @@ "ms-azuretools.vscode-azurefunctions", "ms-python.python" ] -} \ No newline at end of file +} diff --git a/.vscode/launch.json b/.vscode/launch.json index 4508b45..0e43bd3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,12 +1,12 @@ { - "version": "0.2.0", - "configurations": [ - { - "name": "Attach to Python Functions", - "type": "python", - "request": "attach", - "port": 9091, - "preLaunchTask": "func: host start" - } - ] -} \ No newline at end of file + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Python Functions", + "type": "python", + "request": "attach", + "port": 9091, + "preLaunchTask": "func: host start" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index f48aa7d..562fbbf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,9 @@ { - "azureFunctions.deploySubpath": "code\\function", - "azureFunctions.scmDoBuildDuringDeployment": true, - "azureFunctions.pythonVenv": ".venv", - "azureFunctions.projectLanguage": "Python", - "azureFunctions.projectRuntime": "~4", - "debug.internalConsoleOptions": "neverOpen", - "azureFunctions.projectLanguageModel": 2 -} \ No newline at end of file + "azureFunctions.deploySubpath": "code\\function", + "azureFunctions.scmDoBuildDuringDeployment": true, + "azureFunctions.pythonVenv": ".venv", + "azureFunctions.projectLanguage": "Python", + "azureFunctions.projectRuntime": "~4", + "debug.internalConsoleOptions": "neverOpen", + "azureFunctions.projectLanguageModel": 2 +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 07bb5a6..0bbf25a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,33 +1,33 @@ { - "version": "2.0.0", - "tasks": [ - { - "type": "func", - "label": "func: host start", - "command": "host start", - "problemMatcher": "$func-python-watch", - "isBackground": true, - "dependsOn": "pip install (functions)", - "options": { - "cwd": "${workspaceFolder}/code\\function" - } - }, - { - "label": "pip install (functions)", - "type": "shell", - "osx": { - "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" - }, - "windows": { - "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt" - }, - "linux": { - "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" - }, - "problemMatcher": [], - "options": { - "cwd": "${workspaceFolder}/code\\function" - } - } - ] -} \ No newline at end of file + "version": "2.0.0", + "tasks": [ + { + "type": "func", + "label": "func: host start", + "command": "host start", + "problemMatcher": "$func-python-watch", + "isBackground": true, + "dependsOn": "pip install (functions)", + "options": { + "cwd": "${workspaceFolder}/code\\function" + } + }, + { + "label": "pip install (functions)", + "type": "shell", + "osx": { + "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" + }, + "windows": { + "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt" + }, + "linux": { + "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" + }, + "problemMatcher": [], + "options": { + "cwd": "${workspaceFolder}/code\\function" + } + } + ] +} diff --git a/code/function/.funcignore b/code/function/.funcignore index 9966315..f1110d3 100644 --- a/code/function/.funcignore +++ b/code/function/.funcignore @@ -5,4 +5,4 @@ __blobstorage__ __queuestorage__ local.settings.json test -.venv \ No newline at end of file +.venv diff --git a/code/function/.gitignore b/code/function/.gitignore index 7685fc4..74fc765 100644 --- a/code/function/.gitignore +++ b/code/function/.gitignore @@ -132,4 +132,4 @@ local.settings.json __blobstorage__ __queuestorage__ __azurite_db*__.json -.python_packages \ No newline at end of file +.python_packages diff --git a/code/function/function_app.py b/code/function/function_app.py index 10273b5..64f8e0e 100644 --- a/code/function/function_app.py +++ b/code/function/function_app.py @@ -1,25 +1,29 @@ -import azure.functions as func import logging +import azure.functions as func + app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) + @app.route(route="HttpTrigger") def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse: - logging.info('Python HTTP trigger function processed a request.') + logging.info("Python HTTP trigger function processed a request.") - name = req.params.get('name') + name = req.params.get("name") if not name: try: req_body = req.get_json() except ValueError: pass else: - name = req_body.get('name') + name = req_body.get("name") if name: - return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.") + return func.HttpResponse( + f"Hello, {name}. This HTTP triggered function executed successfully." + ) else: return func.HttpResponse( - "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", - status_code=200 - ) \ No newline at end of file + "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", + status_code=200, + ) diff --git a/code/function/getting_started.md b/code/function/getting_started.md index d20aeea..81aca9a 100644 --- a/code/function/getting_started.md +++ b/code/function/getting_started.md @@ -1,9 +1,9 @@ # Getting Started with Azure Functions in Python - + ## Python Programming Model V2 -The new programming model in Azure Functions Python delivers an experience that aligns with Python development principles, and subsequently with commonly used Python frameworks. +The new programming model in Azure Functions Python delivers an experience that aligns with Python development principles, and subsequently with commonly used Python frameworks. The improved programming model requires fewer files than the default model, and specifically eliminates the need for a configuration file (`function.json`). Instead, triggers and bindings are represented in the `function_app.py` file as decorators. Moreover, functions can be logically organized with support for multiple functions to be stored in the same file. Functions within the same function application can also be stored in different files, and be referenced as blueprints. @@ -28,21 +28,21 @@ The main project folder () can contain the following files: * *local.settings.json*: Used to store app settings and connection strings when running locally. This file doesn't get published to Azure. * *requirements.txt*: Contains the list of Python packages the system installs when publishing to Azure. * *host.json*: Contains configuration options that affect all functions in a function app instance. This file does get published to Azure. Not all options are supported when running locally. -* *blueprint.py*: (Optional) Functions that are defined in a separate file for logical organization and grouping, that can be referenced in `function_app.py`. +* *blueprint.py*: (Optional) Functions that are defined in a separate file for logical organization and grouping, that can be referenced in `function_app.py`. * *.vscode/*: (Optional) Contains store VSCode configuration. * *.venv/*: (Optional) Contains a Python virtual environment used by local development. * *Dockerfile*: (Optional) Used when publishing your project in a custom container. * *tests/*: (Optional) Contains the test cases of your function app. * *.funcignore*: (Optional) Declares files that shouldn't get published to Azure. Usually, this file contains `.vscode/` to ignore your editor setting, `.venv/` to ignore local Python virtual environment, `tests/` to ignore test cases, and `local.settings.json` to prevent local app settings being published. - + ## Developing your first Python function using VS Code If you have not already, please checkout our [quickstart](https://aka.ms/fxpythonquickstart) to get you started with Azure Functions developments in Python. ## Publishing your function app to Azure - + For more information on deployment options for Azure Functions, please visit this [guide](https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python#publish-the-project-to-azure). ## Next Steps - -To learn more specific guidance on developing Azure Functions with Python, please visit [Azure Functions Developer Python Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level). \ No newline at end of file + +To learn more specific guidance on developing Azure Functions with Python, please visit [Azure Functions Developer Python Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level). diff --git a/code/function/host.json b/code/function/host.json index 9df9136..06d01bd 100644 --- a/code/function/host.json +++ b/code/function/host.json @@ -12,4 +12,4 @@ "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*, 5.0.0)" } -} \ No newline at end of file +} diff --git a/code/function/requirements.txt b/code/function/requirements.txt index 85267c5..bdb8fc5 100644 --- a/code/function/requirements.txt +++ b/code/function/requirements.txt @@ -2,4 +2,4 @@ # The Python Worker is managed by Azure Functions platform # Manually managing azure-functions-worker may cause unexpected issues -azure-functions \ No newline at end of file +azure-functions From e14f552a9fe9e7adf0db2b25797c0d5c4436aa12 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 15:46:19 +0200 Subject: [PATCH 04/28] Remove role assignment to UAI --- code/infra/roleassignments.tf | 6 ------ 1 file changed, 6 deletions(-) diff --git a/code/infra/roleassignments.tf b/code/infra/roleassignments.tf index 30b92b7..83ee9e6 100644 --- a/code/infra/roleassignments.tf +++ b/code/infra/roleassignments.tf @@ -1,9 +1,3 @@ -resource "azurerm_role_assignment" "role_assignment_key_vault_uai" { - scope = azurerm_key_vault.key_vault.id - role_definition_name = "Key Vault Crypto Service Encryption User" - principal_id = azurerm_user_assigned_identity.user_assigned_identity.principal_id -} - resource "azurerm_role_assignment" "role_assignment_storage_function" { scope = azurerm_storage_account.storage.id role_definition_name = "Storage Blob Data Owner" From 3dbf6a5f8f056428e8e170b0401656b41bc0b55c Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 15:49:39 +0200 Subject: [PATCH 05/28] Remmove identity from storage --- code/infra/storage.tf | 6 ------ 1 file changed, 6 deletions(-) diff --git a/code/infra/storage.tf b/code/infra/storage.tf index 84ee20b..f8f62b7 100644 --- a/code/infra/storage.tf +++ b/code/infra/storage.tf @@ -3,12 +3,6 @@ resource "azurerm_storage_account" "storage" { location = var.location resource_group_name = azurerm_resource_group.app_rg.name tags = var.tags - identity { - type = "UserAssigned" - identity_ids = [ - azurerm_user_assigned_identity.user_assigned_identity.id - ] - } access_tier = "Hot" account_kind = "StorageV2" From 071df835523e4c15e5598fd4e5e4eb7207b2068f Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 15:51:54 +0200 Subject: [PATCH 06/28] Remove dependency from storage --- code/infra/storage.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/code/infra/storage.tf b/code/infra/storage.tf index f8f62b7..a4e0437 100644 --- a/code/infra/storage.tf +++ b/code/infra/storage.tf @@ -46,10 +46,6 @@ resource "azurerm_storage_account" "storage" { } sftp_enabled = false shared_access_key_enabled = false - - depends_on = [ - azurerm_role_assignment.role_assignment_key_vault_uai - ] } resource "azurerm_storage_management_policy" "storage_management_policy" { From 0969820bc6e135646543822cfa9a4fcdace857aa Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 16:23:36 +0200 Subject: [PATCH 07/28] Add core function structure based on fastapi --- code/function/{.gitkeep => api/__init__.py} | 0 code/function/api/v1/__init__.py | 0 code/function/api/v1/api_v1.py | 8 +++ code/function/api/v1/endpoints/heartbeat.py | 15 ++++++ code/function/api/v1/endpoints/sample.py | 20 +++++++ code/function/core/__init__.py | 0 code/function/core/config.py | 15 ++++++ code/function/core/messages.py | 14 +++++ code/function/function_app.py | 59 +++++++++++---------- code/function/models/__init__.py | 0 code/function/models/heartbeat.py | 5 ++ code/function/models/sample.py | 9 ++++ code/function/requirements.txt | 4 +- code/function/utils.py | 22 ++++++++ 14 files changed, 143 insertions(+), 28 deletions(-) rename code/function/{.gitkeep => api/__init__.py} (100%) create mode 100644 code/function/api/v1/__init__.py create mode 100644 code/function/api/v1/api_v1.py create mode 100644 code/function/api/v1/endpoints/heartbeat.py create mode 100644 code/function/api/v1/endpoints/sample.py create mode 100644 code/function/core/__init__.py create mode 100644 code/function/core/config.py create mode 100644 code/function/core/messages.py create mode 100644 code/function/models/__init__.py create mode 100644 code/function/models/heartbeat.py create mode 100644 code/function/models/sample.py create mode 100644 code/function/utils.py diff --git a/code/function/.gitkeep b/code/function/api/__init__.py similarity index 100% rename from code/function/.gitkeep rename to code/function/api/__init__.py diff --git a/code/function/api/v1/__init__.py b/code/function/api/v1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/function/api/v1/api_v1.py b/code/function/api/v1/api_v1.py new file mode 100644 index 0000000..ef75054 --- /dev/null +++ b/code/function/api/v1/api_v1.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter +from function.api.v1.endpoints import heartbeat, sample + +api_v1_router = APIRouter() +api_v1_router.include_router( + sample.router, prefix="/landingZone", tags=["sample"] +) +api_v1_router.include_router(heartbeat.router, prefix="/health", tags=["health"]) diff --git a/code/function/api/v1/endpoints/heartbeat.py b/code/function/api/v1/endpoints/heartbeat.py new file mode 100644 index 0000000..dd03420 --- /dev/null +++ b/code/function/api/v1/endpoints/heartbeat.py @@ -0,0 +1,15 @@ +from typing import Any + +from fastapi import APIRouter +from function.models.heartbeat import HearbeatResult +from function.utils import setup_logging + +logger = setup_logging(__name__) + +router = APIRouter() + + +@router.get("/heartbeat", response_model=HearbeatResult, name="heartbeat") +async def get_hearbeat() -> Any: + logger.info("Received Heartbeat Request") + return HearbeatResult(isAlive=True) diff --git a/code/function/api/v1/endpoints/sample.py b/code/function/api/v1/endpoints/sample.py new file mode 100644 index 0000000..cf726b4 --- /dev/null +++ b/code/function/api/v1/endpoints/sample.py @@ -0,0 +1,20 @@ +from typing import Any + +from fastapi import APIRouter +from function.models.sample import ( + SampleRequest, + SampleResponse, +) +from function.utils import setup_logging + +logger = setup_logging(__name__) + +router = APIRouter() + + +@router.post("/create", response_model=SampleResponse, name="create") +async def post_predict( + data: SampleRequest, +) -> SampleResponse: + logger.info(f"Received request: {data}") + return SampleResponse(output=f"Hello ${data.input}") diff --git a/code/function/core/__init__.py b/code/function/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/function/core/config.py b/code/function/core/config.py new file mode 100644 index 0000000..f6f33ac --- /dev/null +++ b/code/function/core/config.py @@ -0,0 +1,15 @@ +import logging + +from pydantic import BaseSettings + + +class Settings(BaseSettings): + PROJECT_NAME: str = "FunctionSample" + SERVER_NAME: str = "FunctionSample" + APP_VERSION: str = "v0.0.1" + API_V1_STR: str = "/v1" + LOGGING_LEVEL: int = logging.INFO + DEBUG: bool = False + + +settings = Settings() diff --git a/code/function/core/messages.py b/code/function/core/messages.py new file mode 100644 index 0000000..9741926 --- /dev/null +++ b/code/function/core/messages.py @@ -0,0 +1,14 @@ +from pydantic import BaseSettings + + +class Messages(BaseSettings): + # Base messages + NO_API_KEY = "No API key provided." + AUTH_REQ = "Authentication required." + HTTP_500_DETAIL = "Internal server error." + + # Templates + NO_VALID_PAYLOAD = "{} is not a valid payload." + + +messages = Messages() diff --git a/code/function/function_app.py b/code/function/function_app.py index 64f8e0e..9246e12 100644 --- a/code/function/function_app.py +++ b/code/function/function_app.py @@ -1,29 +1,34 @@ -import logging - import azure.functions as func +from fastapi import FastAPI +from function.api.v1.api_v1 import api_v1_router +from function.core.config import settings + + +def get_app() -> FastAPI: + app = FastAPI( + title=settings.PROJECT_NAME, + version=settings.APP_VERSION, + openapi_url="/openapi.json", + debug=settings.DEBUG, + ) + app.include_router(api_v1_router, prefix=settings.API_V1_STR) + return app + + +fastapi_app = get_app() + + +@fastapi_app.on_event("startup") +async def startup_event(): + pass + + +@fastapi_app.on_event("shutdown") +async def shutdown_event(): + pass + -app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) - - -@app.route(route="HttpTrigger") -def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse: - logging.info("Python HTTP trigger function processed a request.") - - name = req.params.get("name") - if not name: - try: - req_body = req.get_json() - except ValueError: - pass - else: - name = req_body.get("name") - - if name: - return func.HttpResponse( - f"Hello, {name}. This HTTP triggered function executed successfully." - ) - else: - return func.HttpResponse( - "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", - status_code=200, - ) +app = func.AsgiFunctionApp( + app=fastapi_app, + http_auth_level=func.AuthLevel.FUNCTION, +) diff --git a/code/function/models/__init__.py b/code/function/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/function/models/heartbeat.py b/code/function/models/heartbeat.py new file mode 100644 index 0000000..2fea18a --- /dev/null +++ b/code/function/models/heartbeat.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + + +class HearbeatResult(BaseModel): + isAlive: bool diff --git a/code/function/models/sample.py b/code/function/models/sample.py new file mode 100644 index 0000000..0ffa65f --- /dev/null +++ b/code/function/models/sample.py @@ -0,0 +1,9 @@ +from pydantic import BaseModel + + +class SampleRequest(BaseModel): + input: str + + +class SampleResponse(BaseModel): + output: str diff --git a/code/function/requirements.txt b/code/function/requirements.txt index bdb8fc5..6ba5be5 100644 --- a/code/function/requirements.txt +++ b/code/function/requirements.txt @@ -2,4 +2,6 @@ # The Python Worker is managed by Azure Functions platform # Manually managing azure-functions-worker may cause unexpected issues -azure-functions +azure-functions~=1.14.0 +fastapi~=0.96.0 +aiohttp~=3.8.4 diff --git a/code/function/utils.py b/code/function/utils.py new file mode 100644 index 0000000..a27ac01 --- /dev/null +++ b/code/function/utils.py @@ -0,0 +1,22 @@ +import logging +from logging import Logger + +from function.core.config import settings + + +def setup_logging(module) -> Logger: + """Setup logging and event handler. + RETURNS (Logger): The logger object to log activities. + """ + logger = logging.getLogger(module) + logger.setLevel(settings.LOGGING_LEVEL) + logger.propagate = False + + # Create stream handler + logger_stream_handler = logging.StreamHandler() + logger_stream_handler.setFormatter( + logging.Formatter("[%(asctime)s] [%(levelname)s] [%(module)-8.8s] %(message)s") + ) + + logger.addHandler(logger_stream_handler) + return logger From 715f37d35e9f9170a83f0d92d787d4d4f62cbed2 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 16:24:27 +0200 Subject: [PATCH 08/28] lint --- code/function/api/v1/api_v1.py | 4 +--- code/function/api/v1/endpoints/sample.py | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/code/function/api/v1/api_v1.py b/code/function/api/v1/api_v1.py index ef75054..329426e 100644 --- a/code/function/api/v1/api_v1.py +++ b/code/function/api/v1/api_v1.py @@ -2,7 +2,5 @@ from function.api.v1.endpoints import heartbeat, sample api_v1_router = APIRouter() -api_v1_router.include_router( - sample.router, prefix="/landingZone", tags=["sample"] -) +api_v1_router.include_router(sample.router, prefix="/landingZone", tags=["sample"]) api_v1_router.include_router(heartbeat.router, prefix="/health", tags=["health"]) diff --git a/code/function/api/v1/endpoints/sample.py b/code/function/api/v1/endpoints/sample.py index cf726b4..a04aa45 100644 --- a/code/function/api/v1/endpoints/sample.py +++ b/code/function/api/v1/endpoints/sample.py @@ -1,10 +1,7 @@ from typing import Any from fastapi import APIRouter -from function.models.sample import ( - SampleRequest, - SampleResponse, -) +from function.models.sample import SampleRequest, SampleResponse from function.utils import setup_logging logger = setup_logging(__name__) From e88406b8909a0dc088a4c88c0bce36944fc8f513 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 16:33:05 +0200 Subject: [PATCH 09/28] Deploy infrastructure --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index f1a9d92..33b782e 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -38,7 +38,7 @@ jobs: uses: ./.github/workflows/_terraformApplyTemplate.yml name: "Terraform Apply" needs: [terraform_plan_dev] - if: github.event_name == 'push' || github.event_name == 'release' + # if: github.event_name == 'push' || github.event_name == 'release' with: environment: "dev" terraform_version: "1.4.6" From 13e7370ee85ee6e766c6e5f965f72367d84dc6aa Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 16:57:30 +0200 Subject: [PATCH 10/28] Enable condition --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 33b782e..f1a9d92 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -38,7 +38,7 @@ jobs: uses: ./.github/workflows/_terraformApplyTemplate.yml name: "Terraform Apply" needs: [terraform_plan_dev] - # if: github.event_name == 'push' || github.event_name == 'release' + if: github.event_name == 'push' || github.event_name == 'release' with: environment: "dev" terraform_version: "1.4.6" From 7a87ccccc6a6c277cdd6a5e18b72586a5ed19562 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 16:57:42 +0200 Subject: [PATCH 11/28] Add python test --- .github/workflows/python.yml | 43 ++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + tests/test_main.py | 23 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 .github/workflows/python.yml create mode 100644 tests/test_main.py diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..356db05 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,43 @@ +name: Python - Lint and Test +on: + push: + branches: + - main + paths: + - "code/function/**" + - "tests/**" + - "requirements.txt" + - ".github/workflows/python.yml" + pull_request: + branches: + - main + paths: + - "code/function/**" + - "tests/**" + - "requirements.txt" + - ".github/workflows/python.yml" + +jobs: + lint: + name: Lint and Test + runs-on: ubuntu-latest + + steps: + # Setup Python 3.10 + - name: Setup Python 3.10 + id: python_setup + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + # Checkout repository + - name: Check Out Repository + id: checkout_repository + uses: actions/checkout@v3 + + # Run Python Tests + - name: Run Python Tests + id: python_test + run: | + pip install -r requirements.txt -q + python -m pytest diff --git a/requirements.txt b/requirements.txt index d3e5ff0..7643045 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ pre-commit~=3.3.2 +pytest~=7.3.1 diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..50f2f8d --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,23 @@ +import pytest +from fastapi.testclient import TestClient + +from code.function.core.config import settings +from code.function.main import app + + +@pytest.fixture(scope="module") +def client() -> TestClient: + return TestClient(app) + + +@pytest.mark.parametrize("version", ("v1",)) +def test_get_heartbeat(client, version): + # arrange + path = f"/corrector/{version}/heartbeat" + + # action + response = client.get(path) + + # assert + assert response.status_code == 200 + assert response.json() == {"isAlive": True} From 920a878001598c77d0f7683873139dba6d181b33 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:07:41 +0200 Subject: [PATCH 12/28] Update import --- tests/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 50f2f8d..b06b5e3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,8 +1,8 @@ import pytest from fastapi.testclient import TestClient -from code.function.core.config import settings -from code.function.main import app +from function.core.config import settings +from function.main import app @pytest.fixture(scope="module") From 828f97b9a84c82b3fe50d62b322ed7ebe6b60455 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:13:45 +0200 Subject: [PATCH 13/28] Add pytest ini file --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..3af855c --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +pythonpath = . code function From 59bf84081fd8b0b3ad9f3655067b010935367614 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:14:13 +0200 Subject: [PATCH 14/28] Remove gitkeep --- tests/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/.gitkeep diff --git a/tests/.gitkeep b/tests/.gitkeep deleted file mode 100644 index e69de29..0000000 From 2e6c71635ad03fa9a8047fadb7bed7bee1a4c929 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:14:17 +0200 Subject: [PATCH 15/28] lint --- tests/test_main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index b06b5e3..5db03ab 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,6 +1,5 @@ import pytest from fastapi.testclient import TestClient - from function.core.config import settings from function.main import app From 109383ccf769cc0c6daa599f42dc6e63019d9ee9 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:15:59 +0200 Subject: [PATCH 16/28] Update workflow --- .github/workflows/python.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 356db05..17265b3 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,4 +1,4 @@ -name: Python - Lint and Test +name: Python - Test on: push: branches: @@ -19,7 +19,7 @@ on: jobs: lint: - name: Lint and Test + name: Python Test runs-on: ubuntu-latest steps: @@ -39,5 +39,6 @@ jobs: - name: Run Python Tests id: python_test run: | + pip install -r ./code/function/requirements.txt -q pip install -r requirements.txt -q python -m pytest From db233b61d7145f9d3db32ee2f5738bae8456365b Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:17:34 +0200 Subject: [PATCH 17/28] Add missing library --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 7643045..16d3d4f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pre-commit~=3.3.2 pytest~=7.3.1 +httpx~=0.24.1 From 4b5893da8b5184f2c033acd4f381b78e1c5c7a1f Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:21:09 +0200 Subject: [PATCH 18/28] Update workflow --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 17265b3..fba1df9 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -41,4 +41,4 @@ jobs: run: | pip install -r ./code/function/requirements.txt -q pip install -r requirements.txt -q - python -m pytest + pytest From a0880574c22fa3138c4369e0b6e04c0bdb5c286e Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:25:09 +0200 Subject: [PATCH 19/28] Update imports --- tests/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 5db03ab..3b04893 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,7 +1,7 @@ import pytest from fastapi.testclient import TestClient -from function.core.config import settings -from function.main import app +from core.config import settings +from main import app @pytest.fixture(scope="module") From 8eb2561bcd18f92e3afe9b1928acd6ffa2c4a338 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:28:09 +0200 Subject: [PATCH 20/28] Update ini --- pytest.ini | 2 +- tests/test_main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest.ini b/pytest.ini index 3af855c..1ff3a7c 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -pythonpath = . code function +pythonpath = code/function diff --git a/tests/test_main.py b/tests/test_main.py index 3b04893..f6caf18 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,6 +1,6 @@ import pytest -from fastapi.testclient import TestClient from core.config import settings +from fastapi.testclient import TestClient from main import app From d94b6d30890aa3ea4aea9a75d1dd7e483034b890 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:29:40 +0200 Subject: [PATCH 21/28] Update import --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index f6caf18..47dcc5e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,7 +1,7 @@ import pytest from core.config import settings from fastapi.testclient import TestClient -from main import app +from function_app import app @pytest.fixture(scope="module") From ea975bdeb058b6101f5baaa0229c79485d367190 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:31:17 +0200 Subject: [PATCH 22/28] Update pytonpath --- pytest.ini | 2 +- tests/test_main.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pytest.ini b/pytest.ini index 1ff3a7c..1d9b4af 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -pythonpath = code/function +pythonpath = code diff --git a/tests/test_main.py b/tests/test_main.py index 47dcc5e..d968be2 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,7 +1,7 @@ import pytest -from core.config import settings from fastapi.testclient import TestClient -from function_app import app +from function.core.config import settings +from function.function_app import app @pytest.fixture(scope="module") From 9e2e4dcc00f721d331360da4380500a1bdc927f8 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:35:17 +0200 Subject: [PATCH 23/28] Update dependencies --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 16d3d4f..591d116 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ pre-commit~=3.3.2 pytest~=7.3.1 httpx~=0.24.1 +azure-functions-worker~=1.1.9 From 766ecabd23cca9b73835bd82d589e71b333c2b28 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:45:35 +0200 Subject: [PATCH 24/28] Remove lib --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 591d116..16d3d4f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ pre-commit~=3.3.2 pytest~=7.3.1 httpx~=0.24.1 -azure-functions-worker~=1.1.9 From 4a2d79b74ddd2b4ac1f45f90d4547d9792ea8c69 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 20:55:46 +0200 Subject: [PATCH 25/28] Switch to Anonymous --- code/function/function_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/function/function_app.py b/code/function/function_app.py index 9246e12..fe89a11 100644 --- a/code/function/function_app.py +++ b/code/function/function_app.py @@ -30,5 +30,5 @@ async def shutdown_event(): app = func.AsgiFunctionApp( app=fastapi_app, - http_auth_level=func.AuthLevel.FUNCTION, + http_auth_level=func.AuthLevel.ANONYMOUS, ) From 156707ceedcec21aa306ee3074b1d82bd1fe2b07 Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 21:17:40 +0200 Subject: [PATCH 26/28] Update test --- tests/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index d968be2..9c132ba 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,12 +1,12 @@ import pytest from fastapi.testclient import TestClient from function.core.config import settings -from function.function_app import app +from function.function_app import fastapi_app @pytest.fixture(scope="module") def client() -> TestClient: - return TestClient(app) + return TestClient(fastapi_app) @pytest.mark.parametrize("version", ("v1",)) From fdc204ce8accdbf9504d80af93bf211a3c47219d Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 21:21:23 +0200 Subject: [PATCH 27/28] Update path in test --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 9c132ba..17fbd6c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -12,7 +12,7 @@ def client() -> TestClient: @pytest.mark.parametrize("version", ("v1",)) def test_get_heartbeat(client, version): # arrange - path = f"/corrector/{version}/heartbeat" + path = f"/health/{version}/heartbeat" # action response = client.get(path) From b5e42314e2759371c78393d101fc6652f7c5915b Mon Sep 17 00:00:00 2001 From: Marvin Buss Date: Fri, 9 Jun 2023 21:24:23 +0200 Subject: [PATCH 28/28] Update path --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 17fbd6c..86e67e6 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -12,7 +12,7 @@ def client() -> TestClient: @pytest.mark.parametrize("version", ("v1",)) def test_get_heartbeat(client, version): # arrange - path = f"/health/{version}/heartbeat" + path = f"/{version}/health/heartbeat" # action response = client.get(path)