using Azure.Core;
using Azure.Identity;
using Azure.Storage.Blobs;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Storage;
客户端库信息:
Azure.Identity:跨 Azure SDK 提供 Microsoft Entra 令牌身份验证支持,并且它是与 Azure 服务进行无密码连接所必需的。
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient
客户端库信息:
azure-identity:跨 Azure SDK 提供 Microsoft Entra 令牌身份验证支持,并且它是与 Azure 服务进行无密码连接所必需的。
public static async Task RegisterSRPInSubscription(SubscriptionResource subscription)
{
ResourceProviderResource resourceProvider =
await subscription.GetResourceProviderAsync("Microsoft.Storage");
// Check the registration state of the resource provider and register, if needed
if (resourceProvider.Data.RegistrationState == "NotRegistered")
resourceProvider.Register();
}
public void RegisterSRPInSubscription(AzureResourceManager armClient) {
// Check the registration state of the resource provider and register, if needed
if (armClient.providers().getByName("Microsoft.Storage").registrationState() == "NotRegistered")
armClient.providers().register("Microsoft.Storage");
}
async function registerSRPInSubscription(resourceMgmtClient /*: ResourceManagementClient*/) {
// Check the registration state of the resource provider and register, if needed
if (resourceMgmtClient.providers.get("Microsoft.Storage").registrationState == "NotRegistered")
resourceMgmtClient.providers.register("Microsoft.Storage");
}
def register_srp_in_subscription(self, resource_mgmt_client: ResourceManagementClient):
if (resource_mgmt_client.providers.get("Microsoft.Storage").registration_state == "NotRegistered"):
resource_mgmt_client.providers.register("Microsoft.Storage")
public static async Task<Uri> GetBlobServiceEndpoint(
string storageAccountName,
TokenCredential credential)
{
// TODO: replace with your subscription ID and resource group name
// You can locate your subscription ID on the Subscriptions blade
// of the Azure portal (https://portal.azure.cn)
const string subscriptionId = "<subscription-id>";
const string rgName = "<resource-group-name>";
ArmClient armClient = new(credential, subscriptionId, new ArmClientOptions { Environment = ArmEnvironment.AzureChina });
// Create a resource identifier, then get the subscription resource
ResourceIdentifier resourceIdentifier = new($"/subscriptions/{subscriptionId}");
SubscriptionResource subscription = armClient.GetSubscriptionResource(resourceIdentifier);
// Get a resource group
ResourceGroupResource resourceGroup = await subscription.GetResourceGroupAsync(rgName);
// Get a collection of storage account resources
StorageAccountCollection accountCollection = resourceGroup.GetStorageAccounts();
// Get the properties for the specified storage account
StorageAccountResource storageAccount = await accountCollection.GetAsync(storageAccountName);
// Return the primary endpoint for the blob service
return storageAccount.Data.PrimaryEndpoints.BlobUri;
}
// Create an instance of DefaultAzureCredential for authorization
TokenCredential credential = new DefaultAzureCredential();
// TODO: replace with your storage account name
string storageAccountName = "<storage-account-name>";
// Call out to our function that retrieves the blob service endpoint for the given storage account
Uri blobURI = await AccountProperties.GetBlobServiceEndpoint(storageAccountName, credential);
Console.WriteLine($"URI: {blobURI}");
// Now that we know the endpoint, create the client object
BlobServiceClient blobServiceClient = new(blobURI, credential);
// Do something with the storage account or its resources ...
String saName = "<storage-account-name>";
DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
AccountProperties accountProps = new AccountProperties();
String blobEndpoint = accountProps.GetBlobServiceEndpoint(saName, credential);
System.out.printf("URI: %s", blobEndpoint);
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(blobEndpoint)
.credential(credential)
.buildClient();
// Do something with the storage account or its resources ...
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential.
// See https://aka.ms/azsdk/js/identity/examples for more details.
const saName = "<storage-account-name>";
const credential = new DefaultAzureCredential();
// Call out to our function that retrieves the blob service endpoint for a storage account
const endpoint = await getBlobServiceEndpoint(saName, credential)
console.log(endpoint);
// Now that we know the endpoint, create the client object
const blobServiceClient = new BlobServiceClient(
endpoint,
credential);
// Do something with the storage account or its resources ...
storage_account_name = "<storage-account-name>"
credential = DefaultAzureCredential()
sample = BlobEndpointSample()
# Call out to our function that retrieves the blob service endpoint for a storage account
endpoint = sample.get_blob_service_endpoint(storage_account_name, credential)
print(f"URL: {endpoint}")
# Now that we know the endpoint, create the client object
blob_service_client = BlobServiceClient(account_url=endpoint, credential=credential)
# Do something with the storage account or its resources ...