Integración de Azure Blob Storage con el conector de servicio
Artículo
En esta página se muestran los tipos de autenticación admitidos, los tipos de cliente y el código de ejemplo de Azure Blob Storage mediante service Conectar or. Esta página también muestra los nombres y valores predeterminados de las variables de entorno o la configuración de Spring Boot que se obtiene al crear la conexión de servicio.
Servicios de proceso admitidos
Service Conectar or se puede usar para conectar los siguientes servicios de proceso a Azure Blob Storage:
Azure App Service
Azure Functions
Azure Container Apps
Azure Spring Apps
Tipos de autenticación y tipos de cliente admitidos
En la tabla siguiente se muestran las combinaciones de métodos de autenticación y clientes que se admiten para conectar el servicio de proceso a Azure Blob Storage mediante service Conectar or. Un valor "Sí" indica que se admite la combinación, mientras que "No" indica que no se admite.
Tipo de cliente
Identidad administrada asignada por el sistema
Identidad administrada asignada por el usuario
Secreto/cadena de conexión
Entidad de servicio
.NET
Sí
Sí
Sí
Sí
Java
Sí
Sí
Sí
Sí
Java: Spring Boot
No
No
Sí
No
Node.js
Sí
Sí
Sí
Sí
Python
Sí
Sí
Sí
Sí
Go
Sí
Sí
Sí
Sí
None
Sí
Sí
Sí
Sí
Esta tabla indica claramente que se admiten todas las combinaciones de tipos de cliente y métodos de autenticación, excepto el tipo de cliente Java - Spring Boot, que solo admite el método Secret/cadena de conexión. Todos los demás tipos de cliente pueden usar cualquiera de los métodos de autenticación para conectarse a Azure Blob Storage mediante service Conectar or.
Nombres de variables de entorno predeterminados o propiedades de aplicación y código de ejemplo
Consulte los detalles de conexión y el código de ejemplo de las tablas siguientes, según el tipo de autenticación y el tipo de cliente de la conexión, para conectar los servicios de proceso a Azure Blob Storage. Puede obtener más información sobre la convención de nomenclatura de variables de entorno de Service Connector.
Identidad administrada asignada por el sistema
Para las variables de entorno predeterminadas y el código de ejemplo de otro tipo de autenticación, elija entre el principio de la documentación.
Puede usar azure-identity para autenticarse a través de la identidad administrada o la entidad de servicio. Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
Instalar dependencias
dotnet add package Azure.Identity
Este es el código de ejemplo para conectarse a Blob Storage mediante la identidad administrada o la entidad de servicio.
using Azure.Identity;
using Azure.Storage.Blobs;
// get Blob endpoint
var blobEndpoint = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines according to the authentication type.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var blobServiceClient = new BlobServiceClient(
new Uri(blobEndpoint),
credential);
Agregue las siguientes dependencias al archivo pom.xml:
Autentíquese mediante azure-identity y obtenga la dirección URL del punto de conexión de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
String url = System.getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines according to the authentication type.
// for system managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_STORAGEBLOB_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("<AZURE_STORAGEBLOB_CLIENTID>"))
// .clientSecret(System.getenv("<AZURE_STORAGEBLOB_CLIENTSECRET>"))
// .tenantId(System.getenv("<AZURE_STORAGEBLOB_TENANTID>"))
// .build();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(url)
.credential(defaultCredential)
.buildClient();
El tipo de autenticación no se admite para Spring Boot.
Autentíquese mediante azure-identity la biblioteca y obtenga la dirección URL del punto de conexión de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
from azure.storage.blob import BlobServiceClient
import os
account_url = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
# Uncomment the following lines according to the authentication type.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
blob_service_client = BlobServiceClient(account_url, credential=cred)
Autentíquese a través de azure-identity la biblioteca. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
import os
# Uncomment the following lines according to the authentication type.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
En el archivo de configuración, agregue las siguientes líneas. Para más información, consulte django-storages[azure].
# in your setting file, eg. settings.py
AZURE_CUSTOM_DOMAIN = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
AZURE_ACCOUNT_NAME = AZURE_CUSTOM_DOMAIN.split('.')[0].removeprefix('https://')
AZURE_TOKEN_CREDENTIAL = cred # this is the cred acquired from above step.
Instale las dependencias.
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
En el código, autentíquese a través de azidentity la biblioteca. Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
account_endpoint = os.Getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT")
// Uncomment the following lines according to the authentication type.
// for system-assigned managed identity
// cred, err := azidentity.NewDefaultAzureCredential(nil)
// for user-assigned managed identity
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// azidentity.ManagedIdentityCredentialOptions.ID := clientid
// options := &azidentity.ManagedIdentityCredentialOptions{ID: clientid}
// cred, err := azidentity.NewManagedIdentityCredential(options)
// for service principal
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// tenantid := os.Getenv("AZURE_STORAGEBLOB_TENANTID")
// clientsecret := os.Getenv("AZURE_STORAGEBLOB_CLIENTSECRET")
// cred, err := azidentity.NewClientSecretCredential(tenantid, clientid, clientsecret, &azidentity.ClientSecretCredentialOptions{})
if err != nil {
// error handling
}
client, err := azblob.NewBlobServiceClient(account_endpoint, cred, nil)
}
Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Autentíquese a través de @azure/identity la biblioteca. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { BlobServiceClient } = require("@azure/storage-blob");
const account_url = process.env.AZURE_STORAGEBLOB_RESOURCEENDPOINT;
// Uncomment the following lines according to the authentication type.
// for system assigned managed identity
// const credential = new DefaultAzureCredential();
// for user assigned managed identity
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_STORAGEBLOB_TENANTID;
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const clientSecret = process.env.AZURE_STORAGEBLOB_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const blobServiceClient = new BlobServiceClient(account_url, credential);
Para otros lenguajes, puede usar la dirección URL de la cuenta de Azure Blob Storage y otras propiedades que Service Conectar or establece en las variables de entorno para conectarse a Azure Blob Storage. Para más información sobre las variables de entorno, consulte Integración de Azure Blob Storage con Service Conectar or.
Identidad administrada asignada por el usuario
Para las variables de entorno predeterminadas y el código de ejemplo de otro tipo de autenticación, elija entre el principio de la documentación.
Puede usar azure-identity para autenticarse a través de la identidad administrada o la entidad de servicio. Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
Instalar dependencias
dotnet add package Azure.Identity
Este es el código de ejemplo para conectarse a Blob Storage mediante la identidad administrada o la entidad de servicio.
using Azure.Identity;
using Azure.Storage.Blobs;
// get Blob endpoint
var blobEndpoint = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines according to the authentication type.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var blobServiceClient = new BlobServiceClient(
new Uri(blobEndpoint),
credential);
Agregue las siguientes dependencias al archivo pom.xml:
Autentíquese mediante azure-identity y obtenga la dirección URL del punto de conexión de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
String url = System.getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines according to the authentication type.
// for system managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_STORAGEBLOB_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("<AZURE_STORAGEBLOB_CLIENTID>"))
// .clientSecret(System.getenv("<AZURE_STORAGEBLOB_CLIENTSECRET>"))
// .tenantId(System.getenv("<AZURE_STORAGEBLOB_TENANTID>"))
// .build();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(url)
.credential(defaultCredential)
.buildClient();
El tipo de autenticación no se admite para Spring Boot.
Autentíquese mediante azure-identity la biblioteca y obtenga la dirección URL del punto de conexión de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
from azure.storage.blob import BlobServiceClient
import os
account_url = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
# Uncomment the following lines according to the authentication type.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
blob_service_client = BlobServiceClient(account_url, credential=cred)
Autentíquese a través de azure-identity la biblioteca. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
import os
# Uncomment the following lines according to the authentication type.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
En el archivo de configuración, agregue las siguientes líneas. Para más información, consulte django-storages[azure].
# in your setting file, eg. settings.py
AZURE_CUSTOM_DOMAIN = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
AZURE_ACCOUNT_NAME = AZURE_CUSTOM_DOMAIN.split('.')[0].removeprefix('https://')
AZURE_TOKEN_CREDENTIAL = cred # this is the cred acquired from above step.
Instale las dependencias.
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
En el código, autentíquese a través de azidentity la biblioteca. Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
account_endpoint = os.Getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT")
// Uncomment the following lines according to the authentication type.
// for system-assigned managed identity
// cred, err := azidentity.NewDefaultAzureCredential(nil)
// for user-assigned managed identity
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// azidentity.ManagedIdentityCredentialOptions.ID := clientid
// options := &azidentity.ManagedIdentityCredentialOptions{ID: clientid}
// cred, err := azidentity.NewManagedIdentityCredential(options)
// for service principal
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// tenantid := os.Getenv("AZURE_STORAGEBLOB_TENANTID")
// clientsecret := os.Getenv("AZURE_STORAGEBLOB_CLIENTSECRET")
// cred, err := azidentity.NewClientSecretCredential(tenantid, clientid, clientsecret, &azidentity.ClientSecretCredentialOptions{})
if err != nil {
// error handling
}
client, err := azblob.NewBlobServiceClient(account_endpoint, cred, nil)
}
Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Autentíquese a través de @azure/identity la biblioteca. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { BlobServiceClient } = require("@azure/storage-blob");
const account_url = process.env.AZURE_STORAGEBLOB_RESOURCEENDPOINT;
// Uncomment the following lines according to the authentication type.
// for system assigned managed identity
// const credential = new DefaultAzureCredential();
// for user assigned managed identity
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_STORAGEBLOB_TENANTID;
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const clientSecret = process.env.AZURE_STORAGEBLOB_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const blobServiceClient = new BlobServiceClient(account_url, credential);
Para otros lenguajes, puede usar la dirección URL de la cuenta de Azure Blob Storage y otras propiedades que Service Conectar or establece en las variables de entorno para conectarse a Azure Blob Storage. Para más información sobre las variables de entorno, consulte Integración de Azure Blob Storage con Service Conectar or.
Cadena de conexión
Para las variables de entorno predeterminadas y el código de ejemplo de otro tipo de autenticación, elija entre el principio de la documentación.
Obtenga el cadena de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or.
Instalar dependencias
dotnet add package Azure.Storage.Blob
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using System;
// get Blob connection string
var connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CONNECTIONSTRING");
// Create a BlobServiceClient object
var blobServiceClient = new BlobServiceClient(connectionString);
Agregue las siguientes dependencias al archivo pom.xml:
Consulte Carga de un archivo en Azure Blob Storage y configuración de la aplicación spring. Service Conectar or agrega las propiedades de configuración a Spring Apps. Se proporcionan dos conjuntos de propiedades de configuración según la versión de Spring Cloud Azure (por debajo de la versión 4.0 y posteriores a la 4.0). Para más información sobre los cambios de biblioteca de Spring Cloud Azure, consulte guía de migración de Azure de Spring Cloud.
Instalación de dependencias
pip install azure-storage-blob
Obtenga el cadena de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or.
from azure.storage.blob import BlobServiceClient
import os
connection_str = os.getenv('AZURE_STORAGEBLOB_CONNECTIONSTRING')
blob_service_client = BlobServiceClient.from_connection_string(connection_str)
Instale las dependencias.
pip install django-storages[azure]
Configure y configure el back-end de Azure Blob Storage en el archivo de configuración de Django según corresponda a la versión de django. Para más información, consulte django-storages[azure].
En el archivo de configuración, agregue las siguientes líneas.
# in your setting file, eg. settings.py
AZURE_CONNECTION_STRING = os.getenv('AZURE_STORAGEBLOB_CONNECTIONSTRING')
Instale las dependencias.
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
Obtenga el cadena de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or.
Para otros lenguajes, puede usar la dirección URL de la cuenta de Azure Blob Storage y otras propiedades que Service Conectar or establece en las variables de entorno para conectarse a Azure Blob Storage. Para más información sobre las variables de entorno, consulte Integración de Azure Blob Storage con Service Conectar or.
Entidad de servicio
Para las variables de entorno predeterminadas y el código de ejemplo de otro tipo de autenticación, elija entre el principio de la documentación.
Puede usar azure-identity para autenticarse a través de la identidad administrada o la entidad de servicio. Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
Instalar dependencias
dotnet add package Azure.Identity
Este es el código de ejemplo para conectarse a Blob Storage mediante la identidad administrada o la entidad de servicio.
using Azure.Identity;
using Azure.Storage.Blobs;
// get Blob endpoint
var blobEndpoint = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines according to the authentication type.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_STORAGEBLOB_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var blobServiceClient = new BlobServiceClient(
new Uri(blobEndpoint),
credential);
Agregue las siguientes dependencias al archivo pom.xml:
Autentíquese mediante azure-identity y obtenga la dirección URL del punto de conexión de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
String url = System.getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT");
// Uncomment the following lines according to the authentication type.
// for system managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_STORAGEBLOB_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("<AZURE_STORAGEBLOB_CLIENTID>"))
// .clientSecret(System.getenv("<AZURE_STORAGEBLOB_CLIENTSECRET>"))
// .tenantId(System.getenv("<AZURE_STORAGEBLOB_TENANTID>"))
// .build();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(url)
.credential(defaultCredential)
.buildClient();
El tipo de autenticación no se admite para Spring Boot.
Autentíquese mediante azure-identity la biblioteca y obtenga la dirección URL del punto de conexión de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
from azure.storage.blob import BlobServiceClient
import os
account_url = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
# Uncomment the following lines according to the authentication type.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
blob_service_client = BlobServiceClient(account_url, credential=cred)
Autentíquese a través de azure-identity la biblioteca. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
import os
# Uncomment the following lines according to the authentication type.
# system assigned managed identity
# cred = ManagedIdentityCredential()
# user assigned managed identity
# managed_identity_client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
# service principal
# tenant_id = os.getenv('AZURE_STORAGEBLOB_TENANTID')
# client_id = os.getenv('AZURE_STORAGEBLOB_CLIENTID')
# client_secret = os.getenv('AZURE_STORAGEBLOB_CLIENTSECRET')
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
En el archivo de configuración, agregue las siguientes líneas. Para más información, consulte django-storages[azure].
# in your setting file, eg. settings.py
AZURE_CUSTOM_DOMAIN = os.getenv('AZURE_STORAGEBLOB_RESOURCEENDPOINT')
AZURE_ACCOUNT_NAME = AZURE_CUSTOM_DOMAIN.split('.')[0].removeprefix('https://')
AZURE_TOKEN_CREDENTIAL = cred # this is the cred acquired from above step.
Instale las dependencias.
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
go get "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
En el código, autentíquese a través de azidentity la biblioteca. Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
account_endpoint = os.Getenv("AZURE_STORAGEBLOB_RESOURCEENDPOINT")
// Uncomment the following lines according to the authentication type.
// for system-assigned managed identity
// cred, err := azidentity.NewDefaultAzureCredential(nil)
// for user-assigned managed identity
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// azidentity.ManagedIdentityCredentialOptions.ID := clientid
// options := &azidentity.ManagedIdentityCredentialOptions{ID: clientid}
// cred, err := azidentity.NewManagedIdentityCredential(options)
// for service principal
// clientid := os.Getenv("AZURE_STORAGEBLOB_CLIENTID")
// tenantid := os.Getenv("AZURE_STORAGEBLOB_TENANTID")
// clientsecret := os.Getenv("AZURE_STORAGEBLOB_CLIENTSECRET")
// cred, err := azidentity.NewClientSecretCredential(tenantid, clientid, clientsecret, &azidentity.ClientSecretCredentialOptions{})
if err != nil {
// error handling
}
client, err := azblob.NewBlobServiceClient(account_endpoint, cred, nil)
}
Obtenga la dirección URL del punto de conexión de Azure Blob Storage de la variable de entorno agregada por Service Conectar or. Autentíquese a través de @azure/identity la biblioteca. Al usar el código siguiente, quite la marca de comentario de la parte del fragmento de código para el tipo de autenticación que desea usar.
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
const { BlobServiceClient } = require("@azure/storage-blob");
const account_url = process.env.AZURE_STORAGEBLOB_RESOURCEENDPOINT;
// Uncomment the following lines according to the authentication type.
// for system assigned managed identity
// const credential = new DefaultAzureCredential();
// for user assigned managed identity
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const credential = new DefaultAzureCredential({
// managedIdentityClientId: clientId
// });
// for service principal
// const tenantId = process.env.AZURE_STORAGEBLOB_TENANTID;
// const clientId = process.env.AZURE_STORAGEBLOB_CLIENTID;
// const clientSecret = process.env.AZURE_STORAGEBLOB_CLIENTSECRET;
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const blobServiceClient = new BlobServiceClient(account_url, credential);
Para otros lenguajes, puede usar la dirección URL de la cuenta de Azure Blob Storage y otras propiedades que Service Conectar or establece en las variables de entorno para conectarse a Azure Blob Storage. Para más información sobre las variables de entorno, consulte Integración de Azure Blob Storage con Service Conectar or.
Pasos siguientes
Siga los tutoriales para obtener más información sobre Service Conectar or.
Próximamente: A lo largo de 2024 iremos eliminando gradualmente GitHub Issues como mecanismo de comentarios sobre el contenido y lo sustituiremos por un nuevo sistema de comentarios. Para más información, vea: https://aka.ms/ContentUserFeedback.