Skip to content

Commit ff6dacd

Browse files
committed
Added connection strings and Azure SDKs sections
1 parent 2ad112d commit ff6dacd

File tree

1 file changed

+106
-17
lines changed

1 file changed

+106
-17
lines changed

articles/storage/common/storage-use-azurite.md

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ When `--cert` is provided for a PFX file, you must provide a corresponding `--pw
321321
azurite --cert path/server.pfx --pwd pfxpassword
322322
```
323323

324+
For detailed information on creating PEM and PFX files, see [HTTPS Setup](https://github.com/Azure/Azurite/blob/master/README.md#https-setup).
325+
324326
### OAuth configuration
325327

326328
**Optional** Enable OAuth authentication for Azurite by using the `--oauth` switch.
@@ -336,7 +338,9 @@ Azurite supports basic authentication by specifying the `basic` parameter to the
336338

337339
## Authorization for tools and SDKs
338340

339-
Connect to Azurite from Azure Storage SDKs or tools, like [Azure Storage Explorer](https://azure.microsoft.com/features/storage-explorer/), by using any authentication strategy. Authentication is required. Azurite supports authorization with Shared Key and shared access signatures (SAS). Azurite also supports anonymous access to public containers.
341+
Connect to Azurite from Azure Storage SDKs or tools, like [Azure Storage Explorer](https://azure.microsoft.com/features/storage-explorer/), by using any authentication strategy. Authentication is required. Azurite supports authorization with OAuth, Shared Key, and shared access signatures (SAS). Azurite also supports anonymous access to public containers.
342+
343+
If you are using the Azure SDKs, start Azurite with the `--oauth basic` option.
340344

341345
### Well-known storage account and key
342346

@@ -345,10 +349,36 @@ Azurite accepts the same well-known account and key used by the legacy Azure sto
345349
* Account name: `devstoreaccount1`
346350
* Account key: `Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==`
347351

352+
### Custom storage accounts and keys
353+
354+
Azurite supports custom storage account names and keys by setting the `AZURITE_ACCOUNTS` environment variable in the following format: `account1:key1[:key2];account2:key1[:key2];...`.
355+
356+
For example, use a custom storage account that has one key:
357+
358+
```cmd
359+
set AZURITE_ACCOUNTS="account1:key1"
360+
```
361+
362+
```bash
363+
export AZURITE_ACCOUNTS="account1:key1"
364+
```
365+
366+
Or use multiple storage accounts with 2 keys each:
367+
368+
```cmd
369+
set AZURITE_ACCOUNTS="account1:key1:key2;account2:key1:key2"
370+
```
371+
372+
```bash
373+
export AZURITE_ACCOUNTS="account1:key1:key2;account2:key1:key2"
374+
```
375+
376+
Azurite refreshes custom account names and keys from the environment variable every minute by default. With this feature, you can dynamically rotate the account key, or add new storage accounts without restarting Azurite.
377+
348378
> [!NOTE]
349-
> In addition to SharedKey authentication, Azurite supports account and service SAS authentication. Anonymous access is also available when a container is set to allow public access.
379+
> The default `devstoreaccount1` storage account is disabled when you set custom storage accounts.
350380
351-
### Connection string
381+
### Connection strings
352382

353383
The easiest way to connect to Azurite from your application is to configure a connection string in your application's configuration file that references the shortcut *UseDevelopmentStorage=true*. Here's an example of a connection string in an *app.config* file:
354384

@@ -358,34 +388,93 @@ The easiest way to connect to Azurite from your application is to configure a co
358388
</appSettings>
359389
```
360390

361-
For more information, see [Configure Azure Storage connection strings](storage-configure-connection-string.md).
391+
#### HTTP Connection Strings
362392

363-
### Custom storage accounts and keys
393+
You can pass the following connection strings to the [Azure SDKs](https://aka.ms/azsdk) or tools, like Azure CLI 2.0 or Storage Explorer.
364394

365-
Azurite supports custom storage account names and keys by setting the `AZURITE_ACCOUNTS` environment variable in the following format: `account1:key1[:key2];account2:key1[:key2];...`.
395+
The full connection string is:
366396

367-
For example, use a custom storage account that has one key:
397+
```console
398+
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;
399+
```
400+
401+
To connect to the blob service only, the connection string is:
368402

369403
```console
370-
set AZURITE_ACCOUNTS="account1:key1"
404+
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
371405
```
372406

373-
Or use multiple storage accounts with 2 keys each:
407+
To connect to the queue service only, the connection string is:
374408

375409
```console
376-
set AZURITE_ACCOUNTS="account1:key1:key2;account2:key1:key2"
410+
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;
377411
```
378412

379-
Azurite refreshes custom account names and keys from the environment variable every minute by default. With this feature, you can dynamically rotate the account key, or add new storage accounts without restarting Azurite.
413+
#### HTTPS Connection Strings
380414

381-
> [!NOTE]
382-
> The default `devstoreaccount1` storage account is disabled when you set custom storage accounts.
415+
The full HTTPS connection string is:
383416

384-
> [!NOTE]
385-
> Update the connection string accordingly when using custom account names and keys.
417+
```console
418+
DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;
419+
```
386420

387-
> [!NOTE]
388-
> Use the `export` keyword to set environment variables in a Linux environment, use `set` in Windows.
421+
To use the blob service only, the HTTPS connection string is:
422+
423+
```console
424+
DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;
425+
```
426+
427+
To use the queue service only, the HTTPS connection string is:
428+
429+
```console
430+
DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;
431+
```
432+
433+
If you used `dotnet dev-certs` to generate your self-signed certificate, use the following connection string.
434+
435+
```console
436+
DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://localhost:10000/devstoreaccount1;QueueEndpoint=https://localhost:10001/devstoreaccount1;
437+
```
438+
439+
Update the connection string accordingly when using [custom storage accounts and keys](#custom-storage-accounts-and-keys).
440+
441+
For more information, see [Configure Azure Storage connection strings](storage-configure-connection-string.md).
442+
443+
### Azure SDKs
444+
445+
To use Azurite with the [Azure SDKs](https://aka.ms/azsdk), use OAuth and HTTPs options:
446+
447+
`azurite --oauth basic --cert certname.pem --key certname-key.pem`
448+
449+
#### Azure Blob Storage
450+
451+
You can then instantiate a BlobContainerClient, BlobServiceClient, or BlobClient.
452+
453+
```csharp
454+
// With container URL and DefaultAzureCredential
455+
var client = new BlobContainerClient(new Uri("https://127.0.0.1:10000/devstoreaccount1/container-name"), new DefaultAzureCredential());
456+
457+
// With connection string
458+
var client = new BlobContainerClient("DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;", "container-name");
459+
460+
// With account name and key
461+
var client = new BlobContainerClient(new Uri("https://127.0.0.1:10000/devstoreaccount1/container-name"), new StorageSharedKeyCredential("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="));
462+
```
463+
464+
#### Azure Queue Storage
465+
466+
You can also instantiate a QueueClient or QueueServiceClient.
467+
468+
```csharp
469+
// With queue URL and DefaultAzureCredential
470+
var client = new QueueClient(new Uri("https://127.0.0.1:10001/devstoreaccount1/queue-name"), new DefaultAzureCredential());
471+
472+
// With connection string
473+
var client = new QueueClient("DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;", "queue-name");
474+
475+
// With account name and key
476+
var client = new QueueClient(new Uri("https://127.0.0.1:10001/devstoreaccount1/queue-name"), new StorageSharedKeyCredential("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="));
477+
```
389478

390479
### Storage Explorer
391480

0 commit comments

Comments
 (0)