Skip to content

Commit

Permalink
Add: default credential instead of connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
antidoid committed Feb 4, 2024
1 parent 578bc41 commit d77264f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions qrCodeGenerator/function_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import azure.functions as func
from azure.storage.blob import BlobServiceClient
from azure.identity import DefaultAzureCredential

import qrcode
from qrcode.image.styledpil import StyledPilImage
Expand All @@ -22,18 +23,26 @@ def GenerateQRCode(req: func.HttpRequest) -> func.HttpResponse:
style = req.params.get('style') or req.get_json().get('style')
color = req.params.get('color') or req.get_json().get('color')

# return error response if url was not provided in the query param / req body
if not url:
return func.HttpResponse(
"Please pass a url on the query string or the request body",
status_code=400
)

try:
# Create a Managed Identity default credential
credential = DefaultAzureCredential()

# create a blob client
blobServiceClient = BlobServiceClient.from_connection_string(
conn_str=connectionString)
blobServiceClient = BlobServiceClient(
"https://qrcodegenerator998.blob.core.windows.net", credential)

# create the blob container client
containerName = 'qr-codes'
containerClient = blobServiceClient.get_container_client(containerName)

# create container if it doesn't already exists
if not containerClient.exists():
containerClient = blobServiceClient.create_container(containerName)

Expand Down
1 change: 1 addition & 0 deletions qrCodeGenerator/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
azure-storage-blob
qrcode[pil]
azure-functions
azure-identity

0 comments on commit d77264f

Please sign in to comment.