Skip to content

docs: add identity-based sample #78

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

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
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
37 changes: 28 additions & 9 deletions azurefunctions-extensions-bindings-blob/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Azure Functions Extensions Bindings Blob library for Python
This library allows Blob Trigger and Blob Input bindings in Python Function Apps to recognize and bind to client types from the
Azure Storage Blob sdk.
Azure Storage Blob SDK.

Blob client types can be generated from:

* Blob Triggers
* Blob Input

[Source code](https://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob)
[Source code](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob)
|
[Package (PyPi)](https://pypi.org/project/azurefunctions-extensions-bindings-blob/)
| API reference documentation
| Product documentation
| [Samples](hhttps://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples)
| [Developer Reference](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=get-started%2Casgi%2Capplication-level&pivots=python-mode-decorators#sdk-type-bindings-preview)
| [Samples](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples)


## Getting started
Expand Down Expand Up @@ -75,6 +75,21 @@ def blob_input(req: func.HttpRequest, client: blob.BlobClient):
f"Blob content head: {client.download_blob(encoding="utf-8").read(size=1)}")
```

### Using Identity-Based Connections
Currently, creating a client through a connection string or through the storage account's blob service account URL is
supported. Credentials are not yet supported.

To use an identity, you define settings under a common prefix that maps to the `connection` property in the trigger
and binding configuration. The suffix needed depends on if it will be used by a Blob input binding or Blob trigger.

| Binding Type | Environment Variable Template | Example Value |
|--------------|--------------------------------------------|------------------------------------------------------|
| Blob Input | `<CONNECTION_NAME_PREFIX>__serviceUri` | https://<storage_account_name>.blob.core.windows.net |
| Blob Trigger | `<CONNECTION_NAME_PREFIX>__blobServiceUri` | https://<storage_account_name>.blob.core.windows.net |

Please note that when using a client type for Blob Trigger, the `<CONNECTION_NAME_PREFIX>__queueServiceUri` is not required.
For more information on using identity-based connections, please reference the documentation for [Identity-based connections with Blobs](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=python-v2%2Cisolated-process%2Cnodejs-v4&pivots=programming-language-python#identity-based-connections).

## Troubleshooting
### General
The SDK-types raise exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md).
Expand All @@ -85,19 +100,23 @@ This list can be used for reference to catch thrown exceptions. To get the speci

### More sample code

Get started with our [Blob samples](hhttps://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples).
Get started with our [Blob samples](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples).

Several samples are available in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Storage Blobs:

* [blob_samples_blobclient](https://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples/blob_samples_blobclient) - Examples for using the BlobClient type:
* [blob_samples_blobclient](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_blobclient) - Examples for using the BlobClient type:
* From BlobTrigger
* From BlobInput

* [blob_samples_containerclient](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_containerclient) - Examples for using the ContainerClient type:
* From BlobTrigger
* From BlobInput

* [blob_samples_containerclient](https://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples/blob_samples_containerclient) - Examples for using the ContainerClient type:
* [blob_samples_storagestreamdownloader](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_storagestreamdownloader) - Examples for using the StorageStreamDownloader type:
* From BlobTrigger
* From BlobInput

* [blob_samples_storagestreamdownloader](https://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples/blob_samples_storagestreamdownloader) - Examples for using the StorageStreamDownloader type:
* [blob_samples_identity](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_identity) - Examples for using the BlobClient type using identity-based connections:
* From BlobTrigger
* From BlobInput

Expand Down
12 changes: 8 additions & 4 deletions azurefunctions-extensions-bindings-blob/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ These are code samples that show common scenario operations with the Azure Funct
These samples relate to the Azure Storage Blob client library being used as part of a Python Function App. For
examples on how to use the Azure Storage Blob client library, please see [Azure Storage Blob samples](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob/samples)

* [blob_samples_blobclient](https://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples/blob_samples_blobclient) - Examples for using the BlobClient type:
* [blob_samples_blobclient](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_blobclient) - Examples for using the BlobClient type:
* From BlobTrigger
* From BlobInput

* [blob_samples_containerclient](https://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples/blob_samples_containerclient) - Examples for using the ContainerClient type:
* [blob_samples_containerclient](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_containerclient) - Examples for using the ContainerClient type:
* From BlobTrigger
* From BlobInput

* [blob_samples_storagestreamdownloader](https://github.com/Azure/azure-functions-python-extensions/tree/main/azurefunctions-extensions-bindings-blob/samples/blob_samples_storagestreamdownloader) - Examples for using the StorageStreamDownloader type:
* [blob_samples_storagestreamdownloader](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_storagestreamdownloader) - Examples for using the StorageStreamDownloader type:
* From BlobTrigger
* From BlobInput

* [blob_samples_identity](https://github.com/Azure/azure-functions-python-extensions/tree/dev/azurefunctions-extensions-bindings-blob/samples/blob_samples_identity) - Examples for using the BlobClient type using identity-based connections:
* From BlobTrigger
* From BlobInput

Expand Down Expand Up @@ -63,6 +67,6 @@ based on the type of function you wish to execute.

## Next steps

Visit the [SDK-type bindings in Python reference documentation]() to learn more about how to use SDK-type bindings in a Python Function App and the
Visit the [SDK-type bindings in Python reference documentation](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=get-started%2Casgi%2Capplication-level&pivots=python-mode-decorators#sdk-type-bindings-preview) to learn more about how to use SDK-type bindings in a Python Function App and the
[API reference documentation](https://aka.ms/azsdk-python-storage-blob-ref) to learn more about
what you can do with the Azure Storage Blob client library.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding: utf-8

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

import logging

import azure.functions as func
import azurefunctions.extensions.bindings.blob as blob

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

"""
FOLDER: blob_samples_managed_identity
DESCRIPTION:
These samples demonstrate how to obtain a BlobClient from a Blob Trigger
or Blob Input function app binding using Identity-based connections.

Please note that the appropriate permissions must still be assigned
to the identity in order to execute properly.

USAGE:
Set the environment variables with your own values and assign the
required permissions before running the sample:
1) AccountUrl - the storage account's blob service account URL

Set PATH/TO/BLOB to the path to the blob you want to trigger or serve as
input to the function.
"""


@app.blob_trigger(arg_name="client", path="PATH/TO/BLOB", connection="AccountUrl")
def blob_trigger(client: blob.BlobClient):
logging.info(
f"Python blob trigger function using identity-based connections processed blob \n"
f"Properties: {client.get_blob_properties()}\n"
f"Blob content head: {client.download_blob().read(size=1)}"
)


@app.route(route="file")
@app.blob_input(arg_name="client", path="PATH/TO/BLOB", connection="AccountUrl")
def blob_input(req: func.HttpRequest, client: blob.BlobClient):
logging.info(
f"Python blob input function using identity-based connections processed blob \n"
f"Properties: {client.get_blob_properties()}\n"
f"Blob content head: {client.download_blob().read(size=1)}"
)
return "ok"
Original file line number Diff line number Diff line change
@@ -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)"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AccountUrl__serviceUri": "https://<storage_account_name>.blob.core.windows.net",
"AccountUrl____blobServiceUri": "https://<storage_account_name>.blob.core.windows.net"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 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
azurefunctions-extensions-bindings-blob
2 changes: 2 additions & 0 deletions eng/templates/official/jobs/blob-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
PYTHON_VERSION: '3.10'
python311:
PYTHON_VERSION: '3.11'
python312:
PYTHON_VERSION: '3.12'

steps:
- task: UsePythonVersion@0
Expand Down
Loading