diff --git a/Api/.config/dotnet-tools.json b/Api/.config/dotnet-tools.json new file mode 100644 index 0000000..517f9b3 --- /dev/null +++ b/Api/.config/dotnet-tools.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "isRoot": true, + "tools": {} +} \ No newline at end of file diff --git a/Api/.dockerignore b/Api/.dockerignore new file mode 100644 index 0000000..4d72b4f --- /dev/null +++ b/Api/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/Api/.gitignore b/Api/.gitignore new file mode 100644 index 0000000..6fb5e51 --- /dev/null +++ b/Api/.gitignore @@ -0,0 +1,3 @@ +obj/ +bin/ +.vs/ \ No newline at end of file diff --git a/Api/Api.csproj b/Api/Api.csproj new file mode 100644 index 0000000..4dda03a --- /dev/null +++ b/Api/Api.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + aspnet-Api-50db7f4c-1c75-467a-a923-a5477d7decc4 + Linux + . + + + + + + + + + + + + diff --git a/Api/Api.csproj.user b/Api/Api.csproj.user new file mode 100644 index 0000000..96e63d6 --- /dev/null +++ b/Api/Api.csproj.user @@ -0,0 +1,9 @@ + + + + https + + + ProjectDebugger + + \ No newline at end of file diff --git a/Api/Api.http b/Api/Api.http new file mode 100644 index 0000000..3e2645b --- /dev/null +++ b/Api/Api.http @@ -0,0 +1,6 @@ +@Api_HostAddress = http://localhost:5012 + +GET {{Api_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Api/Api.sln b/Api/Api.sln new file mode 100644 index 0000000..5339c98 --- /dev/null +++ b/Api/Api.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36301.6 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "Api.csproj", "{EC86C676-06E8-4011-A4E3-5118543F4728}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EC86C676-06E8-4011-A4E3-5118543F4728}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC86C676-06E8-4011-A4E3-5118543F4728}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC86C676-06E8-4011-A4E3-5118543F4728}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC86C676-06E8-4011-A4E3-5118543F4728}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A7800B0A-84E4-432A-9E11-6EF3987291FC} + EndGlobalSection +EndGlobal diff --git a/Api/Controllers/WeatherForecastController.cs b/Api/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..b9e1680 --- /dev/null +++ b/Api/Controllers/WeatherForecastController.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Identity.Web.Resource; + +namespace Api.Controllers +{ + //[Authorize] + [ApiController] + [Route("[controller]")] + //[RequiredScope(RequiredScopesConfigurationKey = "AzureAd:Scopes")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Api/Dockerfile b/Api/Dockerfile new file mode 100644 index 0000000..0ed5132 --- /dev/null +++ b/Api/Dockerfile @@ -0,0 +1,30 @@ +# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["Api.csproj", "."] +RUN dotnet restore "./Api.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "./Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Api.dll"] \ No newline at end of file diff --git a/Api/Program.cs b/Api/Program.cs new file mode 100644 index 0000000..4afb419 --- /dev/null +++ b/Api/Program.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.Identity.Abstractions; +using Microsoft.Identity.Web; +using Microsoft.Identity.Web.Resource; + +namespace Api +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + //builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + // .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd")); + + builder.Services.AddControllers(); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + + app.MapControllers(); + + app.Run(); + } + } +} diff --git a/Api/Properties/launchSettings.json b/Api/Properties/launchSettings.json new file mode 100644 index 0000000..a25d3fd --- /dev/null +++ b/Api/Properties/launchSettings.json @@ -0,0 +1,42 @@ +{ + "profiles": { + "https": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7145;http://localhost:5012" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:60760", + "sslPort": 44315 + } + } +} \ No newline at end of file diff --git a/Api/WeatherForecast.cs b/Api/WeatherForecast.cs new file mode 100644 index 0000000..cc42c03 --- /dev/null +++ b/Api/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Api +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Api/appsettings.Development.json b/Api/appsettings.Development.json new file mode 100644 index 0000000..ff66ba6 --- /dev/null +++ b/Api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Api/appsettings.json b/Api/appsettings.json new file mode 100644 index 0000000..760e771 --- /dev/null +++ b/Api/appsettings.json @@ -0,0 +1,23 @@ +{ +/* +The following identity settings need to be configured +before the project can be successfully executed. +For more info see https://aka.ms/dotnet-template-ms-identity-platform +*/ + "AzureAd": { + "Instance": "https://login.microsoftonline.com/", + "Domain": "qualified.domain.name", + "TenantId": "22222222-2222-2222-2222-222222222222", + "ClientId": "11111111-1111-1111-11111111111111111", + + "Scopes": "access_as_user", + "CallbackPath": "/signin-oidc" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Api/core b/Api/core new file mode 100644 index 0000000..e10e7da Binary files /dev/null and b/Api/core differ