Remove some invalid changes
This commit is contained in:
21
infra/core/security/keyvault-access.bicep
Normal file
21
infra/core/security/keyvault-access.bicep
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
param name string = 'add'
|
||||||
|
|
||||||
|
param keyVaultName string = ''
|
||||||
|
param permissions object = { secrets: [ 'get', 'list' ] }
|
||||||
|
param principalId string
|
||||||
|
|
||||||
|
resource keyVaultAccessPolicies 'Microsoft.KeyVault/vaults/accessPolicies@2022-07-01' = {
|
||||||
|
parent: keyVault
|
||||||
|
name: name
|
||||||
|
properties: {
|
||||||
|
accessPolicies: [ {
|
||||||
|
objectId: principalId
|
||||||
|
tenantId: subscription().tenantId
|
||||||
|
permissions: permissions
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
|
||||||
|
name: keyVaultName
|
||||||
|
}
|
||||||
@@ -52,17 +52,27 @@ module web './core/host/appservice.bicep' = {
|
|||||||
name: !empty(webServiceName) ? webServiceName : '${abbrs.webSitesAppService}web-${resourceToken}'
|
name: !empty(webServiceName) ? webServiceName : '${abbrs.webSitesAppService}web-${resourceToken}'
|
||||||
location: location
|
location: location
|
||||||
appServicePlanId: appServicePlan.outputs.id
|
appServicePlanId: appServicePlan.outputs.id
|
||||||
|
keyVaultName: keyVault.outputs.name
|
||||||
runtimeName: 'dotnetcore'
|
runtimeName: 'dotnetcore'
|
||||||
runtimeVersion: '6.0'
|
runtimeVersion: '6.0'
|
||||||
tags: union(tags, { 'azd-service-name': 'web' })
|
tags: union(tags, { 'azd-service-name': 'web' })
|
||||||
appSettings: {
|
appSettings: {
|
||||||
AZURE_CATALOG_CONNECTION_STRING_KEY: 'AZURE-SQL-CATALOG-CONNECTION-STRING'
|
AZURE_SQL_CATALOG_CONNECTION_STRING_KEY: 'AZURE-SQL-CATALOG-CONNECTION-STRING'
|
||||||
AZURE_IDENTITY_CONNECTION_STRING_KEY: 'AZURE-SQL-IDENTITY-CONNECTION-STRING'
|
AZURE_SQL_IDENTITY_CONNECTION_STRING_KEY: 'AZURE-SQL-IDENTITY-CONNECTION-STRING'
|
||||||
AZURE_KEY_VAULT_ENDPOINT: keyVault.outputs.endpoint
|
AZURE_KEY_VAULT_ENDPOINT: keyVault.outputs.endpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module apiKeyVaultAccess './core/security/keyvault-access.bicep' = {
|
||||||
|
name: 'api-keyvault-access'
|
||||||
|
scope: rg
|
||||||
|
params: {
|
||||||
|
keyVaultName: keyVault.outputs.name
|
||||||
|
principalId: web.outputs.identityPrincipalId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The application database: Catalog
|
// The application database: Catalog
|
||||||
module catalogDb './core/database/sqlserver/sqlserver.bicep' = {
|
module catalogDb './core/database/sqlserver/sqlserver.bicep' = {
|
||||||
name: 'sql-catalog'
|
name: 'sql-catalog'
|
||||||
@@ -122,8 +132,8 @@ module appServicePlan './core/host/appserviceplan.bicep' = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Data outputs
|
// Data outputs
|
||||||
output AZURE_SQL_CATALOG_CONNECTION_STRING string = catalogDb.outputs.connectionStringKey
|
output AZURE_SQL_CATALOG_CONNECTION_STRING_KEY string = catalogDb.outputs.connectionStringKey
|
||||||
output AZURE_SQL_IDENTITY_CONNECTION_STRING string = identityDb.outputs.connectionStringKey
|
output AZURE_SQL_IDENTITY_CONNECTION_STRING_KEY string = identityDb.outputs.connectionStringKey
|
||||||
output AZURE_SQL_CATALOG_DATABASE_NAME string = catalogDb.outputs.databaseName
|
output AZURE_SQL_CATALOG_DATABASE_NAME string = catalogDb.outputs.databaseName
|
||||||
output AZURE_SQL_IDENTITY_DATABASE_NAME string = identityDb.outputs.databaseName
|
output AZURE_SQL_IDENTITY_DATABASE_NAME string = identityDb.outputs.databaseName
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ using Microsoft.eShopWeb.Infrastructure.Data;
|
|||||||
using Microsoft.eShopWeb.Infrastructure.Identity;
|
using Microsoft.eShopWeb.Infrastructure.Identity;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Azure.Security.KeyVault.Secrets;
|
|
||||||
using Azure.Identity;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.Infrastructure;
|
namespace Microsoft.eShopWeb.Infrastructure;
|
||||||
|
|
||||||
@@ -14,11 +11,6 @@ public static class Dependencies
|
|||||||
public static void ConfigureServices(IConfiguration configuration, IServiceCollection services)
|
public static void ConfigureServices(IConfiguration configuration, IServiceCollection services)
|
||||||
{
|
{
|
||||||
var useOnlyInMemoryDatabase = false;
|
var useOnlyInMemoryDatabase = false;
|
||||||
string keyVaultUri = configuration["AZURE_KEY_VAULT_ENDPOINT"];
|
|
||||||
string catalogConnectionStringKey = configuration["AZURE_CATALOG_CONNECTION_STRING_KEY"];
|
|
||||||
string identityConnectionStringKey = configuration["AZURE_IDENTITY_CONNECTION_STRING_KEY"];
|
|
||||||
string catalogConnectionStringValue = GetSqlConnectString(keyVaultUri, catalogConnectionStringKey);
|
|
||||||
string identityConnectionStringValue = GetSqlConnectString(keyVaultUri, identityConnectionStringKey);
|
|
||||||
|
|
||||||
if (configuration["UseOnlyInMemoryDatabase"] != null)
|
if (configuration["UseOnlyInMemoryDatabase"] != null)
|
||||||
{
|
{
|
||||||
@@ -39,24 +31,11 @@ public static class Dependencies
|
|||||||
// Requires LocalDB which can be installed with SQL Server Express 2016
|
// Requires LocalDB which can be installed with SQL Server Express 2016
|
||||||
// https://www.microsoft.com/en-us/download/details.aspx?id=54284
|
// https://www.microsoft.com/en-us/download/details.aspx?id=54284
|
||||||
services.AddDbContext<CatalogContext>(c =>
|
services.AddDbContext<CatalogContext>(c =>
|
||||||
c.UseSqlServer(catalogConnectionStringValue));
|
c.UseSqlServer(configuration.GetConnectionString("CatalogConnection")));
|
||||||
|
|
||||||
// Add Identity DbContext
|
// Add Identity DbContext
|
||||||
services.AddDbContext<AppIdentityDbContext>(options =>
|
services.AddDbContext<AppIdentityDbContext>(options =>
|
||||||
options.UseSqlServer(identityConnectionStringValue));
|
options.UseSqlServer(configuration.GetConnectionString("IdentityConnection")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetSqlConnectString(string keyVaultUri, string connectionStringKey)
|
|
||||||
{
|
|
||||||
if (connectionStringKey == null)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
var secretClient = new SecretClient(new Uri(keyVaultUri), new ClientSecretCredential("<tenant_id>","<client_id>","<client_secret>"));
|
|
||||||
KeyVaultSecret secret = secretClient.GetSecret(connectionStringKey);
|
|
||||||
string secretValue = secret.Value;
|
|
||||||
return secretValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="6.1.0" />
|
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="6.1.0" />
|
||||||
<PackageReference Include="Azure.Identity" Version="1.5.0" />
|
|
||||||
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.4.0" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.8" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.8" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.8" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.8" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
|
||||||
|
|||||||
Reference in New Issue
Block a user