你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
此包包含 Azure StorageManagement 客户端的异态 SDK(在 Node.js 和浏览器中运行)。
Azure 存储管理 API。
Source code | Package (NPM) | API reference documentation | Samples
Getting started
当前支持的环境
- Node.js的 LTS 版本
- 最新版本的 Safari、Chrome、Edge 和 Firefox。
See our support policy for more details.
Prerequisites
安装 @azure/arm-storage
包
使用 npm
以下命令安装适用于 JavaScript 的 Azure StorageManagement 客户端库:
npm install @azure/arm-storage
创建和验证 StorageManagementClient
若要创建用于访问 Azure StorageManagement API 的客户端对象,需要 endpoint
Azure StorageManagement 资源和 A credential
. Azure StorageManagement 客户端可以使用 Azure Active Directory 凭据进行身份验证。
You can find the endpoint for your Azure StorageManagement resource in the Azure Portal.
You can authenticate with Azure Active Directory using a credential from the @azure/identity library or an existing AAD Token.
To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, please install the @azure/identity
package:
npm install @azure/identity
还需要 注册新的 AAD 应用程序,并通过向服务主体分配合适的角色来授予对 Azure StorageManagement 的访问权限 (注意:角色 "Owner"
等角色不会授予必要的权限)。
For more information about how to create an Azure AD Application check out this guide.
使用 Node.js 和类似 Node 的环境,可以使用 DefaultAzureCredential
类对客户端进行身份验证。
import { StorageManagementClient } from "@azure/arm-storage";
import { DefaultAzureCredential } from "@azure/identity";
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new StorageManagementClient(new DefaultAzureCredential(), subscriptionId);
对于浏览器环境,请使用 InteractiveBrowserCredential
包中的 @azure/identity
进行身份验证。
import { InteractiveBrowserCredential } from "@azure/identity";
import { StorageManagementClient } from "@azure/arm-storage";
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const client = new StorageManagementClient(credential, subscriptionId);
JavaScript Bundle
若要在浏览器中使用此客户端库,首先需要使用捆绑程序。 For details on how to do this, please refer to our bundling documentation.
Key concepts
StorageManagementClient
StorageManagementClient
是开发人员使用 Azure StorageManagement 客户端库的主要接口。 探索此客户端对象上的方法,了解可以访问的 Azure StorageManagement 服务的不同功能。
Troubleshooting
Logging
启用日志记录可能有助于发现有关故障的有用信息。 若要查看 HTTP 请求和响应的日志,请将 AZURE_LOG_LEVEL
环境变量设置为 info
。 或者,可以通过在运行时调用 setLogLevel
以下项 @azure/logger
来启用日志记录:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
有关如何启用日志的更详细说明,可以查看 @azure/记录器包文档。
Next steps
Please take a look at the samples directory for detailed examples on how to use this library.
Contributing
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.