Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ __azurite_*
*.bkp

src/tmp/*
.vscode/*.dictionary.*
src/.vs/*
.vscode/*.dictionary.*
7 changes: 2 additions & 5 deletions docs/workshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -1475,20 +1475,19 @@ var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(_connection
To use system-assigned identities, the code above needs to be replaced with:

```csharp
var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync(_managedIdentityPrincipalId!);
var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync();
var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions);
```

<div class="task" data-title="Task">

> - Update the code of the `GetDatabaseAsync` method in `src/catalog-api/RedisService.cs` to use system-assigned identity of the App Service Web App
> - Set the value of the `AZURE_MANAGED_IDENTITY_PRINCIPAL_ID` app setting to the system-assigned identity of the App Service Web App (`Object (principal) ID`)

</div>

<div class="tip" data-title="Tips">

> The variables `_hostname`, `_port`, and `_managedIdentityPrincipalId` were already defined in `src/catalog-api/RedisService.cs`
> The variables `_hostname` and `_port` were already defined in `src/catalog-api/RedisService.cs`

</div>

Expand All @@ -1506,8 +1505,6 @@ Afterwards, go to the **Identity** menu on your App Service resource, and copy t

![Managed identity of catalog-api](./assets/catalog-api-managed-identity.png)

Finally, go to the **Configuration** menu of your App Service resource and set the app setting `AZURE_MANAGED_IDENTITY_PRINCIPAL_ID` to the value of `Object (principal) ID`.

Validate the change by clicking **Ok**, then **Save** and you should be all set now.

</details>
Expand Down
5 changes: 1 addition & 4 deletions solutions/catalog-api/RedisService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.Azure.StackExchangeRedis;
using StackExchange.Redis;

public interface IRedisService {
Expand All @@ -11,7 +10,6 @@ public class RedisService : IRedisService
{
private IDatabase? _database = null;
private readonly string? _connectionString;
private readonly string? _managedIdentityPrincipalId;
private readonly string? _hostname;
private readonly string? _port;

Expand All @@ -22,7 +20,6 @@ public RedisService(IConfiguration configuration)
{
_ttl = TTL(configuration["AZURE_REDIS_TTL_IN_SECONDS"]);
_connectionString = configuration["AZURE_REDIS_CONNECTION_STRING"];
_managedIdentityPrincipalId = configuration["AZURE_MANAGED_IDENTITY_PRINCIPAL_ID"];
_port = configuration["AZURE_REDIS_PORT"];
_hostname = configuration["AZURE_REDIS_HOSTNAME"];
}
Expand All @@ -35,7 +32,7 @@ private async Task<IDatabase> GetDatabaseAsync() {
Console.WriteLine("Initializing Redis database connection");

// var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(_connectionString!, AzureCacheForRedis.ConfigureForAzure);
var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync(_managedIdentityPrincipalId!);
var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync();
var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions);

_database = connectionMultiplexer.GetDatabase();
Expand Down
3 changes: 1 addition & 2 deletions src/cache-refresh-func/CacheRefresh.Func.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Redis" Version="0.3.1-preview" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
3 changes: 1 addition & 2 deletions src/catalog-api/Catalog.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.3" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="1.1.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
</ItemGroup>

</Project>
3 changes: 0 additions & 3 deletions src/catalog-api/RedisService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.Azure.StackExchangeRedis;
using StackExchange.Redis;

public interface IRedisService {
Expand All @@ -11,7 +10,6 @@ public class RedisService : IRedisService
{
private IDatabase? _database = null;
private readonly string? _connectionString;
private readonly string? _managedIdentityPrincipalId;
private readonly string? _hostname;
private readonly string? _port;

Expand All @@ -22,7 +20,6 @@ public RedisService(IConfiguration configuration)
{
_ttl = TTL(configuration["AZURE_REDIS_TTL_IN_SECONDS"]);
_connectionString = configuration["AZURE_REDIS_CONNECTION_STRING"];
_managedIdentityPrincipalId = configuration["AZURE_MANAGED_IDENTITY_PRINCIPAL_ID"];
_port = configuration["AZURE_REDIS_PORT"];
_hostname = configuration["AZURE_REDIS_HOSTNAME"];
}
Expand Down
1 change: 0 additions & 1 deletion src/catalog-api/appsettings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"AZURE_COSMOS_CONNECTION_STRING": "YOUR_COSMOS_CONNECTION_STRING",
"AZURE_COSMOS_DATABASE": "catalogdb",
"AZURE_REDIS_CONNECTION_STRING":"YOUR_REDIS_CONNECTION_STRING",
"AZURE_MANAGED_IDENTITY_PRINCIPAL_ID": "MANAGED_IDENTITY_PRINCIPAL_ID_FOR_AAD_INTEGRATION",
"AZURE_REDIS_PORT": "OPTIONAL_REDIS_PORT_FOR_ADD_INTEGRATION",
"AZURE_REDIS_HOSTNAME": "REDIS_HOSTNAME_FOR_ADD_INTEGRATION",
"PRODUCT_LIST_CACHE_DISABLE":"0",
Expand Down
3 changes: 1 addition & 2 deletions src/history-func/History.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Redis" Version="0.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
1 change: 0 additions & 1 deletion src/history-func/HistoryStoreService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Text.Json;
using StackExchange.Redis;
using Microsoft.Azure.StackExchangeRedis;

namespace History.Api
{
Expand Down
1 change: 0 additions & 1 deletion terraform/app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ resource "azurerm_linux_web_app" "this" {
AZURE_REDIS_CONNECTION_STRING = azurerm_redis_cache.this.primary_connection_string
AZURE_REDIS_HOSTNAME = azurerm_redis_cache.this.hostname
AZURE_REDIS_PORT = azurerm_redis_cache.this.ssl_port
AZURE_MANAGED_IDENTITY_PRINCIPAL_ID = ""
PRODUCT_LIST_CACHE_DISABLE = "0"
SIMULATED_DB_LATENCY_IN_SECONDS = "2"
APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.this.instrumentation_key
Expand Down
3 changes: 0 additions & 3 deletions terraform/roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ resource "azurerm_cosmosdb_sql_role_assignment" "app_service" {
resource_group_name = local.resource_group_name
account_name = azurerm_cosmosdb_account.this.name
role_definition_id = azurerm_cosmosdb_sql_role_definition.this.id
principal_id = azurerm_linux_web_app.this.identity[0].principal_id
scope = azurerm_cosmosdb_account.this.id
}

Expand All @@ -30,14 +29,12 @@ resource "azurerm_cosmosdb_sql_role_assignment" "function_app_cache" {
resource_group_name = local.resource_group_name
account_name = azurerm_cosmosdb_account.this.name
role_definition_id = azurerm_cosmosdb_sql_role_definition.this.id
principal_id = azurerm_linux_function_app.func_cache.identity[0].principal_id
scope = azurerm_cosmosdb_account.this.id
}

resource "azurerm_cosmosdb_sql_role_assignment" "function_app_history" {
resource_group_name = local.resource_group_name
account_name = azurerm_cosmosdb_account.this.name
role_definition_id = azurerm_cosmosdb_sql_role_definition.this.id
principal_id = azurerm_linux_function_app.func_history.identity[0].principal_id
scope = azurerm_cosmosdb_account.this.id
}