Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
345c397
refactor: Remove unnecessary service
vyruz1986 Nov 5, 2023
00e012f
fix: Add readonly modified to logger
vyruz1986 Nov 5, 2023
958fccb
chore: Update .dockeringnore and move .editorconfig to repo root
vyruz1986 Nov 5, 2023
03d453f
feat: (wip) Added Blazor WASM Web project with PWA support, authentic…
vyruz1986 Nov 5, 2023
415b2c8
feat: (wip) Implemented API call to DoorRequest API
vyruz1986 Nov 5, 2023
539d784
chore: Add non-0 lock code for local debug config
vyruz1986 Nov 8, 2023
292da19
feat(Web): Get API url from configuration
vyruz1986 Nov 8, 2023
9eae0e4
feat: Get app title from configuration
vyruz1986 Nov 8, 2023
e6aa168
feat(Web): Show collapsed user menu on small screens
vyruz1986 Nov 8, 2023
3983ea2
feat(Web): Show loading spinner while app is loading
vyruz1986 Nov 8, 2023
fdc21b2
fix: Add Api configuration
vyruz1986 Nov 8, 2023
71b7c19
feat(Web): Finalized DoorControl page with online/offline UX and key …
vyruz1986 Nov 8, 2023
02d4c89
feat(web): Show user that login is required, instead of just redirect…
vyruz1986 Nov 8, 2023
6e4b5b2
feat(Web): Set page title to app title
vyruz1986 Nov 8, 2023
1603c13
ci(Web): Added Dockerfile and nginx config
vyruz1986 Nov 8, 2023
5d3c031
feat: Added health check endpoint to API
vyruz1986 Nov 10, 2023
2e9bc39
feat: Replaced connection check with regular pings to API health chec…
vyruz1986 Nov 10, 2023
3abe09a
fix: Revert API and Shared project back to .NET6
vyruz1986 Nov 10, 2023
fc64beb
Merge remote-tracking branch 'origin/master' into blazor-webapp
vyruz1986 Nov 10, 2023
621a88f
ci: Add web image build/push to github registry
vyruz1986 Nov 10, 2023
0d8135d
Merge remote-tracking branch 'origin/master' into blazor-webapp
vyruz1986 Nov 10, 2023
a67295e
fix: Simplify CORS config
vyruz1986 Nov 10, 2023
76269d8
ci: Split up api and web docker image build
vyruz1986 Nov 11, 2023
20312d5
ci: Use user-friendly name for build jobs, and only build on master
vyruz1986 Nov 11, 2023
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
21 changes: 13 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/charts
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/Dockerfile
**/Dockerfile.develop
**/docker-compose.yml
**/docker-compose.*.yml
**/*.dbmdl
**/*.jfm
**/secrets.dev.yaml
**/values.dev.yaml
**/.toolstarget
LICENSE
README.md
32 changes: 30 additions & 2 deletions WebApp/doorrequest/.editorconfig → .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async

# Code-block preferences
csharp_prefer_simple_using_statement = true
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = when_multiline:warning

# Expression-level preferences
csharp_prefer_simple_default_expression = true:warning
csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_inlined_variable_declaration = false
csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_prefer_index_operator = true:warning
Expand Down Expand Up @@ -264,3 +264,31 @@ dotnet_naming_style.generic_parameter_style.required_prefix = T
dotnet_naming_style.generic_parameter_style.required_suffix =
dotnet_naming_style.generic_parameter_style.word_separator =
dotnet_naming_style.generic_parameter_style.capitalization = pascal_case
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion

[*.{cs,vb}]
dotnet_style_coalesce_expression = true:warning
dotnet_style_null_propagation = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_object_initializer = true:warning
dotnet_style_collection_initializer = true:warning
dotnet_style_prefer_simplified_boolean_expressions = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:warning
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
22 changes: 14 additions & 8 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ on:
push:
branches: [master]

env:
REGISTRY: ghcr.io

jobs:
publish:
name: Publish ${{ matrix.image }}
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./API/DoorRequest.API/Dockerfile
image: ghcr.io/brixel/door-request-api
- dockerfile: ./Web/Dockerfile
image: ghcr.io/brixel/door-request-web
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -20,7 +26,7 @@ jobs:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install GitVersion
Expand All @@ -34,14 +40,14 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/brixel/door-request-api
images: ${{ matrix.image }}
tags: type=semver,pattern={{version}},value=${{ steps.gitversion.outputs.semVer }}
- name: Build and push
id: docker_build
- name: Build and push docker image
id: docker_build_api
uses: docker/build-push-action@v5
with:
context: .
push: true
file: API/DoorRequest.API/Dockerfile
file: ${{ matrix.dockerfile }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
20 changes: 12 additions & 8 deletions API/DoorRequest.API/Controllers/DoorRequestController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using DoorRequest.API.Config;
using System.Threading.Tasks;

using DoorRequest.API.Config;
using DoorRequest.API.Services;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;

using Shared.Authorization;

namespace DoorRequest.API.Controllers;

Expand All @@ -12,24 +16,24 @@ namespace DoorRequest.API.Controllers;
[Authorize]
public class DoorRequestController : ControllerBase
{
private readonly IDoorRequestService _doorRequestService;
private readonly IDoorService _doorService;
private readonly LockConfiguration _lockConfiguration;

public DoorRequestController(IDoorRequestService doorRequestService, IOptions<LockConfiguration> lockConfiguration)
public DoorRequestController(IDoorService doorService, IOptions<LockConfiguration> lockConfiguration)
{
_doorRequestService = doorRequestService;
_doorService = doorService ?? throw new System.ArgumentNullException(nameof(doorService));
_lockConfiguration = lockConfiguration.Value;
}

[HttpPost("open")]
[Authorize(Roles = Authorization.Roles.TwentyFourSevenAccess)]
[Authorize(Roles = Roles.TwentyFourSevenAccess)]
public async Task<bool> OpenDoorRequest()
{
return await _doorRequestService.OpenDoor();
return await _doorService.OpenDoor();
}

[HttpGet("code")]
[Authorize(Roles = Authorization.Roles.KeyVaultCodeAccess)]
[Authorize(Roles = Roles.KeyVaultCodeAccess)]
public int GetLockCode()
{
return _lockConfiguration.Code;
Expand Down
4 changes: 4 additions & 0 deletions API/DoorRequest.API/DoorRequest.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties appsettings_1development_1json__JsonSchema="jlgkcxgvknbm v,nmzl ,mznoo534oi5powsjddmg;dms" /></VisualStudio></ProjectExtensions>

</Project>
6 changes: 6 additions & 0 deletions API/DoorRequest.API/Health.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# For more info on HTTP files go to https://aka.ms/vs/httpfile
@rootUrl=https://localhost:5001

HEAD {{rootUrl}}/healthz

# HEAD {{rootUrl}}/healthz
30 changes: 15 additions & 15 deletions API/DoorRequest.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using DoorRequest.API.Authorization;
using System;
using System.IdentityModel.Tokens.Jwt;

using DoorRequest.API.Config;
using DoorRequest.API.Services;

using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
Expand All @@ -9,10 +12,11 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;

using Serilog;
using Serilog.Events;
using System;
using System.IdentityModel.Tokens.Jwt;

using Shared.Authorization;

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
Expand All @@ -33,6 +37,7 @@
builder.Services.AddSwaggerGen();

builder.Services.AddControllers();
builder.Services.AddHealthChecks();

var authOptions = builder.Configuration.GetSection(AuthenticationConfiguration.SectionName).Get<AuthenticationConfiguration>();

Expand Down Expand Up @@ -68,22 +73,12 @@
.Build();
});

builder.Services.AddCors(options =>
{
//TODO: Fix CORS
options.AddPolicy("CorsPolicy", builder =>
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});

builder.Services.AddOptions<DoorConfiguration>()
.Bind(builder.Configuration.GetSection(DoorConfiguration.SectionName))
.ValidateDataAnnotations()
.ValidateOnStart();

builder.Services.AddScoped<IBrixelOpenDoorClient, BrixelOpenDoorClient>();
builder.Services.AddScoped<IDoorRequestService, DoorRequestService>();
builder.Services.AddScoped<IDoorService, DoorService>();
builder.Services.Configure<LockConfiguration>(builder.Configuration.GetSection(nameof(LockConfiguration)));

var app = builder.Build();
Expand All @@ -96,12 +91,17 @@
}

app.UseHttpsRedirection();
app.UseCors("CorsPolicy");
app.UseCors(builder =>
//TODO: Fix CORS
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.MapHealthChecks("/healthz");

app.Run();
}
Expand Down
26 changes: 9 additions & 17 deletions API/DoorRequest.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63559",
"sslPort": 44300
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"DoorRequest.API": {
"commandName": "Project",
"launchUrl": "api/values",
Expand All @@ -37,5 +20,14 @@
"useSSL": true,
"sslPort": 44301
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63559",
"sslPort": 44300
}
}
}
21 changes: 0 additions & 21 deletions API/DoorRequest.API/Services/DoorRequestService.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using DoorRequest.API.Config;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MQTTnet;
using MQTTnet.Client;
Expand All @@ -11,12 +12,13 @@

namespace DoorRequest.API.Services;

public class BrixelOpenDoorClient : IBrixelOpenDoorClient
public class DoorService : IDoorService
{
private readonly string _topic;
private readonly MqttClientOptions _options;
private readonly ILogger<DoorService> _logger;

public BrixelOpenDoorClient(IOptions<DoorConfiguration> options)
public DoorService(IOptions<DoorConfiguration> options, ILogger<DoorService> logger)
{
_topic = options.Value.Topic;
var optionsBuilder = new MqttClientOptionsBuilder()
Expand Down Expand Up @@ -44,10 +46,12 @@ public BrixelOpenDoorClient(IOptions<DoorConfiguration> options)
}

_options = optionsBuilder.Build();
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
}

public async Task<bool> OpenDoor()
{
_logger.LogInformation("Sending request to open the door via MQTT");
using var mqttClient = new MqttFactory().CreateMqttClient();
await mqttClient.ConnectAsync(_options, CancellationToken.None);
var message = new MqttApplicationMessageBuilder()
Expand Down
8 changes: 0 additions & 8 deletions API/DoorRequest.API/Services/IBrixelOpenDoorClient.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DoorRequest.API.Services;

public interface IDoorRequestService
public interface IDoorService
{
Task<bool> OpenDoor();
}
Loading