Skip to content

Latest commit

 

History

History
166 lines (127 loc) · 5.22 KB

README.md

File metadata and controls

166 lines (127 loc) · 5.22 KB

Keep track .NET solution

Build Status Quality Gate Status Coverage

Design

This design of API has been inspired by the Hexagonal Architecture.

NuGet Packages:

Requirements

  • .NET 7.0 SDK

  • MongoDB 7.0 database

    • Local server
    cd D:/Programs/mongodb-7.0/bin
    md log
    md data
    mongod --logpath log/mongod.log --dbpath data --port 27017
    docker run --name mongodb70 -d -p 27017:27017 mongo:7.0
    docker run --rm --link mongodb -v "$(pwd)/scripts":/home/scripts mongo:7.0 bash -c "mongo mongodb://mongodb:27017/keeptrack /home/scripts/mongo-create-index.js"

How to configure

API

Key Description Default value
Infrastructure:MongoDB:ConnectionString MongoDB connection string
Infrastructure:MongoDB:DatabaseName MongoDB connection string inventory

This values can be easily provided as environment variables (replace ":" by "__") or by configuration (json).

Template for src/Api/appsettings.Development.json:

{
  "Authentication": {
    "JwtBearer": {
      "Authority": "https://securetoken.google.com/<firebase-project-id>",
      "TokenValidation": {
        "Issuer": "https://securetoken.google.com/<firebase-project-id>",
        "Audience": "<firebase-project-id>"
      }
    }
  },
  "Infrastructure": {
    "MongoDB": {
      "ConnectionString": "mongodb://localhost:27017",
      "DatabaseName": "keeptrack"
    }
  },
  "Logging": {
    "LogLevel": {
      "KeepTrack": "Debug",
      "Withywoods": "Debug"
    }
  }
}

Blazor WebAssembly Firebase information

Create a file firebase.config.js in src/BlasorWebAssemblyApp/wwwroot:

export var firebaseConfig = {
  apiKey: "******",
  authDomain: "******.firebaseapp.com",
  databaseURL: "******.firebaseio.com",
  projectId: "******",
  storageBucket: "******.appspot.com",
  messagingSenderId: "******",
  appId: "1:******:web:******",
  measurementId: "******"
};

How to build

dotnet restore
dotnet build

How to debug

# run the API (https://localhost:5011/)
dotnet run --project src\Api

# run the Blazor WebAssembly web app (https://localhost:5021)
dotnet watch run --project src\BlazorWebAssemblyApp

How to test

For integration tests, to manage the configuration (secrets) you can create a file at the root directory called Local.runsettings or define them as environment variables:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <RunConfiguration>
    <EnvironmentVariables>
      <AllowedOrigins__0>http://localhost:4200</AllowedOrigins__0>
      <Infrastructure__MongoDB__ConnectionString>mongodb://localhost:27017</Infrastructure__MongoDB__ConnectionString>
      <Infrastructure__MongoDB__DatabaseName>keeptrack_integrationtests</Infrastructure__MongoDB__DatabaseName>
      <Authentication__JwtBearer__Authority></Authentication__JwtBearer__Authority>
      <Authentication__JwtBearer__TokenValidation__Issuer></Authentication__JwtBearer__TokenValidation__Issuer>
      <Authentication__JwtBearer__TokenValidation__Audience></Authentication__JwtBearer__TokenValidation__Audience>
      <Keeptrack__Production__Url>xxxx</Keeptrack__Production__Url>
      <Firebase__Application__Key>xxxx</Firebase__Application__Key>
      <Firebase__Username>xxxx</Firebase__Username>
      <Firebase__Password>xxxx</Firebase__Password>
    </EnvironmentVariables>
  </RunConfiguration>
</RunSettings>

And execute all tests (unit and integration ones):

dotnet test --settings Local.runsettings

How to deploy

  • Add the outbout IP to the MongoDB Atlas cluster
  • Add the application url to Firebase domains
  • Create web project in Firebase and grab ids to be set to environment.ts file
  • Create a GitHub OAuth application (firebase.google.com, github.com)
  • Add urls in Azure web app CORS page

How to operate

  • Backup MongoDB database
docker run --rm -it --workdir=/data --volume $(pwd):/data mongo:6.0 /bin/sh -c "mongodump --uri mongodb+srv://<USER>:<PASSWORD>@<CLUSTER>.<PROJECT>.mongodb.net/test"
  • Restore MongoDB database
docker run --rm -it --workdir=/data --volume $(pwd):/data mongo:6.0 /bin/sh -c "mongorestore --uri mongodb+srv://<USER>:<PASSWORD>@<CLUSTER>.<PROJECT>.mongodb.net"