Skip to content

Commit a086bb9

Browse files
committed
Code sample cleanup
1 parent 2dd6206 commit a086bb9

File tree

1 file changed

+76
-91
lines changed

1 file changed

+76
-91
lines changed

articles/storage/common/multiple-identity-scenarios.md

Lines changed: 76 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Managed identities are most easily implemented in your application code through
3939

4040
## Connect an Azure-hosted app to multiple Azure services
4141

42-
You have been tasked with connecting an existing app to multiple Azure services and databases using passwordless connections. The application is an ASP.NET Core Web API hosted on Azure App Service, though the steps below apply to other Azure hosting environments as well, such as Azure Spring Apps, Virtual Machines, Container Apps, and AKS.
42+
Imagine you're tasked with connecting an existing app to multiple Azure services and databases using passwordless connections. The application is an ASP.NET Core Web API hosted on Azure App Service, though the steps below apply to other Azure hosting environments as well, such as Azure Spring Apps, Virtual Machines, Container Apps, and AKS.
4343

4444
This tutorial applies to the following architectures, though it can be adapted to many other scenarios as well through minimal configuration changes.
4545

@@ -94,34 +94,30 @@ You can also enable access to Azure resources for local development by assigning
9494

9595
#### [.NET](#tab/csharp)
9696

97-
In your project, add a reference to the `Azure.Identity` NuGet package. This library contains the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure libraries that are relevant to your app. For this example, the `Azure.Storage.Blobs` and `Azure.KeyVault.Keys` packages are added to connect to Blob Storage and Key Vault, respectively.
97+
1. In your project, add a reference to the `Azure.Identity` NuGet package. This library contains the necessary entities to implement `DefaultAzureCredential`. You can also add any other Azure libraries that are relevant to your app. For this example, the `Azure.Storage.Blobs` and `Azure.KeyVault.Keys` packages are added to connect to Blob Storage and Key Vault, respectively.
9898

99-
```dotnetcli
100-
dotnet add package Azure.Identity
101-
dotnet add package Azure.Storage.Blobs
102-
dotnet add package Azure.KeyVault.Keys
103-
```
104-
105-
At the top of your `Program.cs` file, add the following `using` statements:
106-
107-
```csharp
108-
using Azure.Identity;
109-
using Azure.Storage.Blobs;
110-
using Azure.Security.KeyVault.Keys;
111-
```
112-
113-
In the `Program.cs` file of your project, create instances of the necessary services your app will connect to. The following examples connect to Blob Storage and Service Bus using the corresponding service clients.
114-
115-
```csharp
116-
DefaultAzureCredential credential = new(credentialOptions);
99+
```dotnetcli
100+
dotnet add package Azure.Identity
101+
dotnet add package Azure.Messaging.ServiceBus
102+
dotnet add package Azure.Storage.Blobs
103+
```
117104
118-
BlobServiceClient blobServiceClient = new(
119-
new Uri("https://<your-storage-account>.blob.core.windows.net"),
120-
credential);
105+
1. In the `Program.cs` file of your project, instantiate service clients for the services your app will connect to. The following examples connect to Blob Storage and Service Bus using the corresponding service clients.
121106
122-
ServiceBusClient serviceBusClient = new("<your-namespace>", credential);
123-
var sender = serviceBusClient.CreateSender("producttracking");
124-
```
107+
```csharp
108+
using Azure.Identity;
109+
using Azure.Messaging.ServiceBus;
110+
using Azure.Storage.Blobs;
111+
112+
DefaultAzureCredential credential = new();
113+
114+
BlobServiceClient blobServiceClient = new(
115+
new Uri("https://<your-storage-account>.blob.core.windows.net"),
116+
credential);
117+
118+
ServiceBusClient serviceBusClient = new("<your-namespace>", credential);
119+
ServiceBusSender sender = serviceBusClient.CreateSender("producttracking");
120+
```
125121
126122
#### [Java](#tab/java)
127123
@@ -181,59 +177,57 @@ class Demo {
181177

182178
#### [Spring](#tab/spring)
183179

184-
In your project, you only need to add service dependencies you use. For this example, the `spring-cloud-azure-starter-storage-blob` and `spring-cloud-azure-starter-servicebus` dependencies are added in order to connect to Blob Storage and Key Vault.
185-
186-
```xml
187-
<dependencyManagement>
188-
<dependencies>
189-
<dependency>
190-
<groupId>com.azure.spring</groupId>
191-
<artifactId>spring-cloud-azure-dependencies</artifactId>
192-
<version>4.5.0</version>
193-
<type>pom</type>
194-
<scope>import</scope>
195-
</dependency>
196-
</dependencies>
197-
</dependencyManagement>
198-
<dependencies>
199-
<dependency>
200-
<groupId>com.azure.spring</groupId>
201-
<artifactId>spring-cloud-azure-starter-storage-blob</artifactId>
202-
</dependency>
203-
<dependency>
204-
<groupId>com.azure.spring</groupId>
205-
<artifactId>spring-cloud-azure-starter-servicebus</artifactId>
206-
</dependency>
207-
</dependencies>
208-
```
209-
210-
Create instances of the service clients for the services your app will connect to. The following examples connect to Blob Storage and Service Bus using the corresponding service clients.
211-
212-
```yaml
213-
spring:
214-
cloud:
215-
azure:
216-
servicebus:
217-
namespace: <service-bus-name>
218-
entity-name: <service-bus-entity-name>
219-
entity-type: <service-bus-entity-type>
220-
storage:
221-
blob:
222-
account-name: <storage-account-name>
223-
```
224-
225-
```java
226-
@Service
227-
public class ExampleService {
228-
229-
@Autowired
230-
private BlobServiceClient blobServiceClient;
231-
232-
@Autowired
233-
private ServiceBusSenderClient serviceBusSenderClient;
180+
1. In your project, you only need to add service dependencies you use. For this example, the `spring-cloud-azure-starter-storage-blob` and `spring-cloud-azure-starter-servicebus` dependencies are added in order to connect to Blob Storage and Key Vault.
181+
182+
```xml
183+
<dependencyManagement>
184+
<dependencies>
185+
<dependency>
186+
<groupId>com.azure.spring</groupId>
187+
<artifactId>spring-cloud-azure-dependencies</artifactId>
188+
<version>4.5.0</version>
189+
<type>pom</type>
190+
<scope>import</scope>
191+
</dependency>
192+
</dependencies>
193+
</dependencyManagement>
194+
<dependencies>
195+
<dependency>
196+
<groupId>com.azure.spring</groupId>
197+
<artifactId>spring-cloud-azure-starter-storage-blob</artifactId>
198+
</dependency>
199+
<dependency>
200+
<groupId>com.azure.spring</groupId>
201+
<artifactId>spring-cloud-azure-starter-servicebus</artifactId>
202+
</dependency>
203+
</dependencies>
204+
```
234205

235-
}
236-
```
206+
1. Create instances of the service clients for the services your app will connect to. The following examples connect to Blob Storage and Service Bus using the corresponding service clients.
207+
208+
```yaml
209+
spring:
210+
cloud:
211+
azure:
212+
servicebus:
213+
namespace: <service-bus-name>
214+
entity-name: <service-bus-entity-name>
215+
entity-type: <service-bus-entity-type>
216+
storage:
217+
blob:
218+
account-name: <storage-account-name>
219+
```
220+
221+
```java
222+
@Service
223+
public class ExampleService {
224+
@Autowired
225+
private BlobServiceClient blobServiceClient;
226+
227+
@Autowired
228+
private ServiceBusSenderClient serviceBusSenderClient;
229+
}
230+
```
237231

238232
#### [JavaScript](#tab/javascript)
239233

@@ -243,17 +237,13 @@ public class ExampleService {
243237
npm install --save @azure/identity @azure/storage-blob @azure/keyvault-keys
244238
```
245239

246-
1. At the top of your `index.js` file, add the following `import` statements to import the necessary service clients for the services your app will connect to:
240+
1. In the `index.js` file, create client objects for the Azure services your app will connect to. The following examples connect to Blob Storage and Key Vault using the corresponding service clients.
247241

248242
```javascript
249243
import { DefaultAzureCredential } from "@azure/identity";
250244
import { BlobServiceClient } from "@azure/storage-blob";
251245
import { KeyClient } from "@azure/keyvault-keys";
252-
```
253246

254-
1. Within the `index.js` file, create client objects for the Azure services your app will connect to. The following examples connect to Blob Storage and Key Vault using the corresponding service clients.
255-
256-
```javascript
257247
// Azure resource names
258248
const storageAccount = process.env.AZURE_STORAGE_ACCOUNT_NAME;
259249
const keyVaultName = process.env.AZURE_KEYVAULT_NAME;
@@ -403,7 +393,6 @@ Add the following to your code:
403393

404394
```java
405395
class Demo {
406-
407396
public static void main(String[] args) {
408397
// Get the first user-assigned managed identity ID to connect to shared storage
409398
String clientIdStorage = System.getenv("Managed_Identity_Client_ID_Storage");
@@ -551,17 +540,13 @@ public class ExampleService {
551540
npm install --save @azure/identity @azure/storage-blob @azure/cosmos mssql
552541
```
553542

554-
2. At the top of your `index.js` file, add the following `import` statements to import the necessary service clients for the services your app will connect to:
543+
1. In the `index.js` file, create client objects for the Azure services your app will connect to. The following examples connect to Blob Storage, Cosmos DB, and Azure SQL using the corresponding service clients.
555544

556545
```javascript
557546
import { DefaultAzureCredential } from "@azure/identity";
558547
import { BlobServiceClient } from "@azure/storage-blob";
559548
import { KeyClient } from "@azure/keyvault-keys";
560-
```
561549
562-
3. Within the `index.js` file, create client objects for the Azure services your app will connect to. The following examples connect to Blob Storage, Cosmos DB, and Azure SQL using the corresponding service clients.
563-
564-
```javascript
565550
// Get the first user-assigned managed identity client ID to connect to shared storage
566551
const clientIdStorage = process.env.MANAGED_IDENTITY_CLIENT_ID_STORAGE;
567552
@@ -573,13 +558,13 @@ public class ExampleService {
573558
const storageAccountName1 = process.env.AZURE_STORAGE_ACCOUNT_NAME_1;
574559
const storageAccountName2 = process.env.AZURE_STORAGE_ACCOUNT_NAME_2;
575560
576-
// First blob storage client that uses a managed identity
561+
// First Blob Storage client that uses a managed identity
577562
const blobServiceClient = new BlobServiceClient(
578563
`https://${storageAccountName1}.blob.core.windows.net`,
579564
credential
580565
);
581566
582-
// Second blob storage client that uses a managed identity
567+
// Second Blob Storage client that uses a managed identity
583568
const blobServiceClient2 = new BlobServiceClient(
584569
`https://${storageAccountName2}.blob.core.windows.net`,
585570
credential

0 commit comments

Comments
 (0)