Azure FileShares client library for JavaScript - バージョン 1.0.0-beta.1

このパッケージには、FileSharesクライアント用の同型SDKが含まれており(Node.js とブラウザの両方で動作Azureます。

Azure File Shares Resource Provider API.

主要なリンク:

作業の開始

現在サポートされている環境

詳細はsupportポリシーをご覧ください。

前提条件

@azure/arm-fileshares パッケージをインストールする

JavaScript用のAzureファイルシェアクライアントライブラリをnpmでインストールしてください:

npm install @azure/arm-fileshares

FileSharesClient を作成して認証する

Azure FileShares APIにアクセスするクライアントオブジェクトを作成するには、Azure FileSharesリソースのendpointcredentialが必要です。 Azure FileSharesクライアントはAzure Active Directoryの認証情報を使用できます。 Azure FileSharesリソースのエンドポイントはAzure portalにあります。

Azure Active Directory認証は、@azure/identityライブラリの認証情報や、既存のAADトークン>で認証できます。

以下に示すDefaultAzureCredentialプロバイダー、またはAzure SDKに付属する他の認証情報提供者を使用するには、@azure/identityパッケージをインストールしてください:

npm install @azure/identity

また、新しいAADアプリケーションを登録し、適切な役割をサービスプリンシパルに割り当ててAzure FileSharesへのアクセスを許可する必要があります(注:"Owner"のようなロールは必要な権限を与えません)。

Azure ADアプリケーションの作成方法についての詳細は、このガイドをご覧ください。

Node.js とノードに似た環境を使用すると、DefaultAzureCredential クラスを使用してクライアントを認証できます。

import { FileSharesClient } from "@azure/arm-fileshares";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new FileSharesClient(new DefaultAzureCredential(), subscriptionId);

ブラウザ環境では、InteractiveBrowserCredentialパッケージの @azure/identity を使って認証します。

import { InteractiveBrowserCredential } from "@azure/identity";
import { FileSharesClient } from "@azure/arm-fileshares";

const credential = new InteractiveBrowserCredential({
  tenantId: "<YOUR_TENANT_ID>",
  clientId: "<YOUR_CLIENT_ID>",
});
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new FileSharesClient(credential, subscriptionId);

JavaScript バンドル

ブラウザーでこのクライアント ライブラリを使用するには、まず、バンドルを使用する必要があります。 これを行う方法の詳細については、バンドルドキュメントを参照してください。

主な概念

FileSharesクライアント

FileSharesClientは、Azure FileSharesクライアントライブラリを使用する開発者にとって主要なインターフェースです。 このクライアントオブジェクトのメソッドを探索して、アクセス可能なAzure FileSharesサービスのさまざまな機能を理解しましょう。

例示

ファイル共有を取得

import { FileSharesClient } from "@azure/arm-fileshares";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new FileSharesClient(new DefaultAzureCredential(), subscriptionId);
const result = await client.fileShares.get("myResourceGroup", "myFileShare");
console.log(result);

サブスクリプション別のリストファイルシェア

import { FileSharesClient } from "@azure/arm-fileshares";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new FileSharesClient(new DefaultAzureCredential(), subscriptionId);
const shares = [];
for await (const item of client.fileShares.listBySubscription()) {
  shares.push(item);
}
console.log(shares);

ファイル共有の作成または更新

import { FileSharesClient } from "@azure/arm-fileshares";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new FileSharesClient(new DefaultAzureCredential(), subscriptionId);
const result = await client.fileShares.createOrUpdate("myResourceGroup", "myFileShare", {
  properties: {
    mountName: "myfileshare",
    mediaTier: "SSD",
    redundancy: "Local",
    protocol: "NFS",
    provisionedStorageGiB: 8,
  },
  location: "westus",
});
console.log(result);

Troubleshooting

Logging

ログ記録を有効にすると、エラーに関する有用な情報を明らかにするのに役立つ場合があります。 HTTP 要求と応答のログを表示するには、AZURE_LOG_LEVEL 環境変数を infoに設定します。 または、setLogLevel@azure/logger を呼び出すことによって、実行時にログを有効にすることもできます。

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

ログを有効にする方法の詳細な手順については、 @azure/logger パッケージのドキュメントを参照してください。

次のステップ

このライブラリの使い方については、samplesディレクトリをご覧ください。

Contributing

このライブラリに投稿する場合は、コードをビルドしてテストする方法の詳細については、投稿ガイド を参照してください。

  • Microsoft Azure SDK for JavaScript の