Skip to content
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
8 changes: 8 additions & 0 deletions Lab1-CreateYourFirstFunction/solution/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git*
.vscode
__azurite_db*__.json
__blobstorage__
__queuestorage__
local.settings.json
test
.venv
135 changes: 135 additions & 0 deletions Lab1-CreateYourFirstFunction/solution/.gitignore
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions Lab1-CreateYourFirstFunction/solution/function_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import azure.functions as func
import logging

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

@app.route(route="getNotes")
def getNotes(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
)
10 changes: 9 additions & 1 deletion Lab1-CreateYourFirstFunction/solution/host.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
}
8 changes: 4 additions & 4 deletions Lab1-CreateYourFirstFunction/solution/local.settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"IsEncrypted": true,
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",

"ConnectionStrings": {}
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
5 changes: 5 additions & 0 deletions Lab1-CreateYourFirstFunction/solution/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Uncomment to enable Azure Monitor OpenTelemetry
# Ref: aka.ms/functions-azure-monitor-python
# azure-monitor-opentelemetry

azure-functions
43 changes: 43 additions & 0 deletions Lab2-Create-Functions-with-MongoDB/solution/function_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os

import azure.functions as func
import pymongo
from bson.json_util import dumps
from bson.objectid import ObjectId


app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)


def _get_collection():
url = os.environ["MyDbConnection"]
client = pymongo.MongoClient(url)
database = client["lab2db"]
return database["notes"]


@app.route(route="getNotes", methods=["GET"])
def get_notes(req: func.HttpRequest) -> func.HttpResponse:
try:
result = _get_collection().find({})
return func.HttpResponse(dumps(result), mimetype="application/json", charset="utf-8")
except Exception:
return func.HttpResponse("could not connect to mongodb", status_code=400)


@app.route(route="getNote", methods=["GET"])
def get_note(req: func.HttpRequest) -> func.HttpResponse:
note_id = req.params.get("id")
if not note_id:
return func.HttpResponse("Please pass an id parameter in the query string.", status_code=400)

try:
query = {"_id": ObjectId(note_id)}
except Exception:
return func.HttpResponse("Invalid id format.", status_code=400)

try:
result = _get_collection().find_one(query)
return func.HttpResponse(dumps(result), mimetype="application/json", charset="utf-8")
except Exception:
return func.HttpResponse("Database connection error.", status_code=500)
27 changes: 0 additions & 27 deletions Lab2-Create-Functions-with-MongoDB/solution/getNote/__init__.py

This file was deleted.

20 changes: 0 additions & 20 deletions Lab2-Create-Functions-with-MongoDB/solution/getNote/function.json

This file was deleted.

24 changes: 0 additions & 24 deletions Lab2-Create-Functions-with-MongoDB/solution/getNotes/__init__.py

This file was deleted.

20 changes: 0 additions & 20 deletions Lab2-Create-Functions-with-MongoDB/solution/getNotes/function.json

This file was deleted.

Loading