Skip to content

Commit f47fbe7

Browse files
committed
Added an authenticated controller action. Docker-ized.
1 parent 903588e commit f47fbe7

13 files changed

+136
-6
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"dotnet-ef": {
6+
"version": "3.1.0",
7+
"commands": [
8+
"dotnet-ef"
9+
]
10+
}
11+
}
12+
}

PostmanDelivers.API/Controllers/EchoController.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Configuration;
4+
using System;
35
using System.Collections.Generic;
46

57
namespace PostmanDelivers.API.Controllers
@@ -8,11 +10,17 @@ namespace PostmanDelivers.API.Controllers
810
[ApiController]
911
public class EchoController : ControllerBase
1012
{
13+
IConfiguration _config;
14+
public EchoController(IConfiguration config)
15+
{
16+
_config = config;
17+
}
18+
1119
[HttpPost]
12-
[Authorize]
1320
[Consumes("application/x-www-form-urlencoded")]
1421
public ActionResult Post([FromForm] Dictionary<string, string> stringsToEcho)
1522
{
23+
stringsToEcho.Add("env", _config.GetValue<string>("APP_ENVIRONMENT") ?? "No environment configured");
1624
return Ok(stringsToEcho);
1725
}
1826
}

PostmanDelivers.API/Controllers/GameController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
23
using Microsoft.Extensions.Configuration;
34
using System.Collections.Generic;
45
using TikTakToe.Engine;
@@ -16,7 +17,7 @@ public GameController(IConfiguration config)
1617
}
1718

1819
[HttpPost]
19-
public ActionResult<Game> Post(string[] playerNames)
20+
public ActionResult<Game> Post([FromBody]string[] playerNames)
2021
{
2122
try
2223
{
@@ -32,6 +33,7 @@ public ActionResult<Game> Post(string[] playerNames)
3233
}
3334

3435
[HttpDelete]
36+
[Authorize]
3537
[Route("{id:int}")]
3638
public ActionResult Delete(int id)
3739
{

PostmanDelivers.API/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
3+
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
4+
WORKDIR /app
5+
EXPOSE 80
6+
EXPOSE 443
7+
8+
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
9+
WORKDIR /src
10+
COPY ["PostmanDelivers.API/PostmanDelivers.API.csproj", "PostmanDelivers.API/"]
11+
COPY ["TikTakToe.Engine/TikTakToe.Engine.csproj", "TikTakToe.Engine/"]
12+
RUN dotnet restore "PostmanDelivers.API/PostmanDelivers.API.csproj"
13+
COPY . .
14+
WORKDIR "/src/PostmanDelivers.API"
15+
RUN dotnet build "PostmanDelivers.API.csproj" -c Release -o /app/build
16+
17+
FROM build AS publish
18+
RUN dotnet publish "PostmanDelivers.API.csproj" -c Release -o /app/publish
19+
20+
FROM base AS final
21+
WORKDIR /app
22+
COPY --from=publish /app/publish .
23+
ENTRYPOINT ["dotnet", "PostmanDelivers.API.dll"]

PostmanDelivers.API/PostmanDelivers.API.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<UserSecretsId>44bf9484-c87a-4a81-a5dd-b74cfa9ba5b7</UserSecretsId>
7+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
78
</PropertyGroup>
89

910
<ItemGroup>
1011
<PackageReference Include="Microsoft.AspNetCore.App" />
1112
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="2.2.0" />
1213
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
14+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
1315
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
1416
</ItemGroup>
1517

1618
<ItemGroup>
1719
<ProjectReference Include="..\TikTakToe.Engine\TikTakToe.Engine.csproj" />
1820
</ItemGroup>
1921

22+
<ItemGroup>
23+
<None Update="data\GameDB.sqlite3">
24+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
</None>
26+
</ItemGroup>
27+
2028
</Project>

PostmanDelivers.API/Properties/launchSettings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121
"commandName": "Project",
2222
"launchUrl": "api/values",
2323
"environmentVariables": {
24-
"ASPNETCORE_ENVIRONMENT": "Development"
24+
"ASPNETCORE_ENVIRONMENT": "Development",
25+
"APP_ENVIRONMENT": "Debug"
2526
},
2627
"applicationUrl": "https://localhost:5001;http://localhost:5000"
28+
},
29+
"Docker": {
30+
"commandName": "Docker",
31+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values",
32+
"publishAllPorts": true,
33+
"useSSL": true
2734
}
2835
}
2936
}

PostmanDelivers.API/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
}
66
},
77
"AllowedHosts": "*",
8-
"ConnectionStr": "Data Source=C:\\ProgramData\\postmandeliversdata\\GameDB.sqlite3;Version=3;"
8+
"ConnectionStr": "Data Source=data/GameDB.sqlite3;Version=3;"
99
}
60 KB
Binary file not shown.

PostmanDelivers.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1111
ProjectSection(SolutionItems) = preProject
1212
.gitignore = .gitignore
1313
CustomScript.js = CustomScript.js
14+
data.json = data.json
1415
Database.sql = Database.sql
1516
Echo.postman_collection.json = Echo.postman_collection.json
17+
newman_script.txt = newman_script.txt
1618
Postman Delivers.postman_globals.json = Postman Delivers.postman_globals.json
1719
PostmandDelivers Azure.postman_environment.json = PostmandDelivers Azure.postman_environment.json
1820
PostmandDelivers HTTPS.postman_environment.json = PostmandDelivers HTTPS.postman_environment.json

0 commit comments

Comments
 (0)