Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,6 @@ ASALocalRun/
/app/Bookstore.Admin/wwwroot/images
/app/Bookstore.Customer/wwwroot/images
/app/Bookstore.Web/wwwroot/images
.kiro/
.apex/
/.workflow-state
10 changes: 10 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

</Project>
9 changes: 3 additions & 6 deletions app/Bookstore.Cdk/Bookstore.Cdk.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- TargetFramework, ImplicitUsings, Nullable, LangVersion inherited from Directory.Build.props -->
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RollForward>Major</RollForward>
</PropertyGroup>

<ItemGroup>
<!-- CDK Construct Library dependencies -->
<PackageReference Include="Amazon.CDK.Lib" Version="2.130.0" />
<PackageReference Include="Constructs" Version="10.1.*" />

<PackageReference Include="Amazon.CDK.Lib" Version="2.*" />
<PackageReference Include="Constructs" Version="10.*" />
<PackageReference Include="Amazon.Jsii.Analyzers" Version="*" PrivateAssets="all" />

</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions app/Bookstore.Cdk/EC2Artifacts/bobsbookstore.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
ErrorLog /var/log/httpd/bobsbookstore-error.log
CustomLog /var/log/httpd/bobsbookstore-custom.log common
SSLEngine On
SSLCertificateFile /etc/ssl/certs/localhost.crt
SSLProtocol -all +TLSv1.1 +TLSv1.2
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLHonorCipherOrder off
SSLCompression off
SSLSessionTickets on
Expand Down
39 changes: 24 additions & 15 deletions app/Bookstore.Cdk/EC2Artifacts/configure_ec2_web_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,47 @@ fi


# Install latest updates
yum update -y
dnf update -y

# Install .NET 10 runtime from Microsoft package feed
rpm -Uvh https://packages.microsoft.com/config/fedora/40/packages-microsoft-prod.rpm || true
dnf install -y aspnetcore-runtime-10.0

# Install Apache
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
dnf install -y httpd
systemctl start httpd
systemctl enable httpd

# Add TLS Support
sudo yum install -y mod_ssl
cd /etc/pki/tls/certs
sudo ./make-dummy-cert localhost.crt
dnf install -y mod_ssl

# Generate self-signed certificate (make-dummy-cert doesn't exist on AL2023)
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/pki/tls/private/localhost.key \
-out /etc/pki/tls/certs/localhost.crt \
-subj "/C=US/ST=State/L=City/O=BobsBookstore/CN=localhost"

cp $APACHE_SSL_CONFIG_FILE /etc/httpd/conf.d/ssl.conf

# Add Bookstore Admin App Virtual Host Config
cp $VIRTUAL_HOST_CONFIG /etc/httpd/conf.d/bobsbookstore.conf

# Restart Apache
sudo systemctl restart httpd
systemctl restart httpd

# Install bookstore admin app into the /var/www/bobsbookstore directory
mkdir -p /var/www/bobsbookstore
cp $SAMPLE_APP /var/www/bobsbookstore/bobsbookstore.zip
cd /var/www/bobsbookstore
unzip bobsbookstore.zip
rm bobsbookstore.zip
sudo usermod -a -G apache ec2-user
sudo chown ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
usermod -a -G apache ec2-user
chown ec2-user:apache /var/www
chmod 2775 /var/www && find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;

# Install the Kestrel Service
cp $KESTREL_SERVICE /etc/systemd/system/bobsbookstore.service
sudo systemctl enable bobsbookstore.service
sudo systemctl start bobsbookstore.service
sudo systemctl status bobsbookstore.service
systemctl enable bobsbookstore.service
systemctl start bobsbookstore.service
systemctl status bobsbookstore.service
2 changes: 1 addition & 1 deletion app/Bookstore.Cdk/EC2Artifacts/ssl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ SSLCertificateFile /etc/pki/tls/certs/localhost.crt
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
Expand Down
4 changes: 2 additions & 2 deletions app/Bookstore.Cdk/EC2ComputeStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal void UploadAssetsToS3()

this.WebAppAsset = new Asset(this, "WebAppAsset", new AssetProps
{
Path = "app/Bookstore.Web/bin/Release/net6.0/publish"
Path = "app/Bookstore.Web/bin/Release/net10.0/publish"
});
this.WebAppAsset.GrantRead(this.Ec2Role);

Expand All @@ -174,7 +174,7 @@ internal void CreateEc2Instance(EC2ComputeStackProps props)
{
var ami = MachineImage.Lookup(new LookupMachineImageProps
{
Name = "amzn2-x86_64-MATEDE_DOTNET-*",
Name = "al2023-ami-*-x86_64",
Owners = new[] { "amazon" }
});

Expand Down
23 changes: 9 additions & 14 deletions app/Bookstore.Data/Bookstore.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<!-- TargetFramework, ImplicitUsings, Nullable, LangVersion inherited from Directory.Build.props -->
Comment thread
dhelper marked this conversation as resolved.
Outdated
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.Rekognition" Version="3.7.1.21" />
<PackageReference Include="AWSSDK.S3" Version="3.7.8.13" />
<PackageReference Include="AWSSDK.SecretsManager" Version="3.7.1.4" />
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.3.0" />
<PackageReference Include="Microsoft.Build" Version="17.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.36" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.36">
<PackageReference Include="AWSSDK.Rekognition" Version="4.0.*" />
<PackageReference Include="AWSSDK.S3" Version="4.0.*" />
<PackageReference Include="AWSSDK.SecretsManager" Version="4.0.*" />
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="14.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="System.Linq.Expressions" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions app/Bookstore.Data/FileServices/LocalFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public LocalFileService(string webRootPath)

// The interface defines an async operation, however System.IO.File
// does not expose an async delete method.
public Task DeleteAsync(string filePath)
public Task DeleteAsync(string? filePath)
{
if (File.Exists(filePath)) File.Delete(filePath);
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) File.Delete(filePath);

return Task.CompletedTask;
}

public async Task<string> SaveAsync(Stream file, string filename)
public async Task<string?> SaveAsync(Stream? file, string? filename)
{
if (file == null) return null;

Expand Down
4 changes: 2 additions & 2 deletions app/Bookstore.Data/FileServices/S3FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public S3FileService(IConfiguration configuration, IAmazonS3 s3Client)
transferUtility = new TransferUtility(s3Client);
}

public async Task DeleteAsync(string filePath)
public async Task DeleteAsync(string? filePath)
{
if (string.IsNullOrWhiteSpace(filePath)) return;

Expand All @@ -33,7 +33,7 @@ public async Task DeleteAsync(string filePath)
await transferUtility.S3Client.DeleteObjectAsync(request);
}

public async Task<string> SaveAsync(Stream contents, string filename)
public async Task<string?> SaveAsync(Stream? contents, string? filename)
{
if (contents == null) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<bool> IsSafeAsync(Stream image)
Image = new Image { Bytes = memoryStream }
});

return !result.ModerationLabels.Any(x => BannedCategories.Contains(x.Name, StringComparer.OrdinalIgnoreCase));
return result.ModerationLabels is null || !result.ModerationLabels.Any(x => BannedCategories.Contains(x.Name, StringComparer.OrdinalIgnoreCase));
}
}
}
13 changes: 5 additions & 8 deletions app/Bookstore.Domain.Tests/Bookstore.Domain.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- TargetFramework, ImplicitUsings, Nullable, LangVersion inherited from Directory.Build.props -->
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.*">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.*">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 1 addition & 3 deletions app/Bookstore.Domain/Bookstore.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- TargetFramework, ImplicitUsings, Nullable, LangVersion inherited from Directory.Build.props -->
Comment thread
dhelper marked this conversation as resolved.
Outdated
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion app/Bookstore.Domain/IFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface IFileService
{
public Task<string> SaveAsync(Stream? contents, string? filename);
public Task<string?> SaveAsync(Stream? contents, string? filename);

public Task DeleteAsync(string? filePath);
}
Expand Down
18 changes: 9 additions & 9 deletions app/Bookstore.Web/Bookstore.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<!-- TargetFramework, ImplicitUsings, Nullable, LangVersion inherited from Directory.Build.props -->
Comment thread
dhelper marked this conversation as resolved.
Outdated
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="2.1.0" />
<PackageReference Include="AWS.Logger.AspNetCore" Version="3.3.0" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.2.87" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.36">
<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="7.*" />
<PackageReference Include="AWS.Logger.AspNetCore" Version="3.*" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="4.0.*" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.*" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions app/Bookstore.Web/Helpers/LocalAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class LocalAuthenticationHandler : AuthenticationHandler<AuthenticationSc
{
private const string UserId = "FB6135C7-1464-4A72-B74E-4B63D343DD09";

public LocalAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
public LocalAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder) : base(options, logger, encoder)
{
}

Expand All @@ -38,15 +38,15 @@ protected override async Task HandleChallengeAsync(AuthenticationProperties prop
Context.Response.Redirect(redirectUrl);
}

private async Task SaveCustomerDetailsAsync(HttpContext context, ClaimsIdentity identity)
private static async Task SaveCustomerDetailsAsync(HttpContext context, ClaimsIdentity identity)
{
var customerService = context.RequestServices.GetService<ICustomerService>();
var customerService = context.RequestServices.GetRequiredService<ICustomerService>();

var dto = new CreateOrUpdateCustomerDto(
identity.FindFirst("Sub").Value,
identity.Name,
identity.FindFirst("given_name").Value,
identity.FindFirst("family_name").Value);
identity.FindFirst("sub")!.Value,
identity.Name!,
identity.FindFirst("given_name")!.Value,
identity.FindFirst("family_name")!.Value);

await customerService.CreateOrUpdateCustomerAsync(dto);
}
Expand All @@ -56,4 +56,4 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
return Task.FromResult(AuthenticateResult.NoResult());
}
}
}
}
Loading
Loading