Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/22/04/updates #9

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion .github/workflows/build-container-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: dotnet restore ${{ inputs.project_file }}

- name: build
run: dotnet build -c ${{ inputs.configuration }} ${{inputs.project_file }} --no-restore
run: dotnet build -c ${{ inputs.configuration }} ${{ inputs.project_file }} --no-restore

- name: test
run: dotnet test -c ${{ inputs.configuration }} ${{ inputs.project_test_file }} -l trx -v normal --no-build
Expand All @@ -52,9 +52,19 @@ jobs:
uses: docker/setup-buildx-action@v1

- name: docker build
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v2
with:
context: .
file: ./dockerfiles/${{ inputs.dockerfile }}
push: false
tags: gkama/${{ inputs.tag }}

- name: docker push
if: github.event_name == 'push'
uses: docker/build-push-action@v2
with:
context: .
file: ./dockerfiles/${{ inputs.dockerfile }}
push: true
tags: gkama/${{ inputs.tag }}
27 changes: 0 additions & 27 deletions .github/workflows/build-core.yml

This file was deleted.

27 changes: 0 additions & 27 deletions .github/workflows/build-email-core.yml

This file was deleted.

125 changes: 125 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: build-test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
terraform:
runs-on: ubuntu-latest
defaults:
run:
working-directory: Terraform
steps:
- name: checkout
uses: actions/checkout@v2

- name: setup terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.1.8
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

- name: terraform format
id: fmt
run: terraform fmt -check

- name: terraform init
id: init
run: terraform init

- name: terraform validate
id: validate
run: terraform validate

- name: terraform plan
id: plan
run: terraform plan

- name: update pull request
uses: actions/[email protected]
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`

<details><summary>Show Plan</summary>

\`\`\`\n
${process.env.PLAN}
\`\`\`

</details>

*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

build_core:
needs: terraform
uses: ./.github/workflows/build-base.yml
with:
configuration: release
project_file: KamaVerification.Core/KamaVerification.Core.csproj
project_test_file: KamaVerification.Tests/KamaVerification.Tests.csproj
output_path: app/publish

build_core_container:
needs: build_core
uses: ./.github/workflows/build-container-base.yml
with:
configuration: release
project_file: KamaVerification.Core/KamaVerification.Core.csproj
project_test_file: KamaVerification.Tests/KamaVerification.Tests.csproj
output_path: app/publish
dockerfile: kama-verification-core.dockerfile
tag: kama-verification:latest

build_email:
needs: terraform
uses: ./.github/workflows/build-base.yml
with:
configuration: release
project_file: KamaVerification.Email.Core/KamaVerification.Email.Core.csproj
project_test_file: KamaVerification.Email.Tests/KamaVerification.Email.Tests.csproj
output_path: app/publish

build_email_container:
needs: build_email
uses: ./.github/workflows/build-container-base.yml
with:
configuration: release
project_file: KamaVerification.Email.Core/KamaVerification.Email.Core.csproj
project_test_file: KamaVerification.Email.Tests/KamaVerification.Email.Tests.csproj
output_path: app/publish
dockerfile: kama-verification-email-core.dockerfile
tag: kama-verification-email:latest

build_data_migrations:
needs: terraform
uses: ./.github/workflows/build-base.yml
with:
configuration: debug
project_file: KamaVerification.Data.Migrations/KamaVerification.Data.Migrations.csproj

build_data_migrations_container:
needs: build_data_migrations
uses: ./.github/workflows/build-container-base.yml
with:
configuration: debug
project_file: KamaVerification.Data.Migrations/KamaVerification.Data.Migrations.csproj
dockerfile: kama-verification-data-migrations.dockerfile
tag: kama-verification-data-migrations:latest
69 changes: 0 additions & 69 deletions .github/workflows/terraform.yml

This file was deleted.

20 changes: 19 additions & 1 deletion KamaVerification.Core/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System.ComponentModel.DataAnnotations;
using KamaVerification.Data.Constants;

namespace KamaVerification.Core.Controllers
{
Expand All @@ -17,11 +18,28 @@ public CustomerController(ICustomerRepository repo)
_repo = repo;
}

[Authorize]
[HttpGet]
[Route("me")]
public async Task<IActionResult> GetAsync()
{
return Ok(await _repo.GetAsync());
}

[Authorize(Roles = Roles.Admin)]
[HttpGet]
[Route("{name}")]
public async Task<IActionResult> GetByNameAsync([FromRoute, Required] string name)
{
return Ok(await _repo.GetByNameAsync(name));
}

[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> AddAsync([FromBody, Required] CustomerDto dto)
{
return Ok(await _repo.AddAsync(dto));
if (dto.EmailConfig is null) return Ok(await _repo.AddAsync(dto.Name));
else return Ok(await _repo.AddAsync(dto));
}

[AllowAnonymous]
Expand Down
11 changes: 11 additions & 0 deletions KamaVerification.Core/Controllers/VerificationController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using KamaVerification.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace KamaVerification.Core.Controllers
{
Expand All @@ -22,5 +23,15 @@ public IActionResult GetCode()
{
return Ok(new { code = _repo.GenerateCode() });
}

[Authorize]
[HttpGet]
[Route("code/compare/{givencode}/{expectedcode}")]
public IActionResult CalculateDifference(
[FromRoute, Required] string givenCode,
[FromRoute, Required] string expectedCode)
{
return Ok(new { code = _repo.CalculateDifference(givenCode, expectedCode) });
}
}
}
7 changes: 7 additions & 0 deletions KamaVerification.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Text.Json.Serialization;
using KamaVerification.Data.Extensions;
using KamaVerification.Services;
using KamaVerification.Data.Dtos;
using KamaVerification.Data.Mappers;
using KamaVerification.Data.Options;
using KamaVerification.Data.Middlewares;

var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
Expand All @@ -12,6 +14,9 @@
services.AddScoped<ITokenRepository, TokenRepository>()
.AddScoped<IVerificationRepository, VerificationRepository>()
.AddScoped<ICustomerRepository, CustomerRepository>()
.AddScoped<ITenant, Tenant>()
.AddHttpContextAccessor()
.AddFluentValidators()
.AddDataConfiguration(config)
.AddJwtAuthentication(config)
.AddAutoMapper(typeof(CustomerProfile).Assembly);
Expand All @@ -31,8 +36,10 @@

var app = builder.Build();

app.UseCors(x => x.WithOrigins("*").AllowAnyHeader().AllowAnyMethod());
app.UseAuthentication();
app.UseAuthorization();
app.UseKamaVerificationExceptionMiddleware();
app.MapHealthChecks("/v1/health");
app.MapControllers();
app.Run();
Loading