diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml new file mode 100644 index 0000000..c209083 --- /dev/null +++ b/.github/workflows/build-images.yml @@ -0,0 +1,112 @@ +name: Build and push docker images + +on: + push: + branches: + - main + tags: + - "v*" + pull_request: + +jobs: + build-push: + runs-on: ubuntu-latest + + steps: + - id: checkout + uses: actions/checkout@v3 + + - id: setup-dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "6.0.x" + + - id: dotnet-test + run: dotnet test ./src /p:Configuration=Release --verbosity normal + + - id: buildx + uses: docker/setup-buildx-action@v2 + + - id: docker-meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/dlcs/request-logger + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,format=long + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - id: docker-cache + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - id: ghcr-login + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - id: docker_build + uses: docker/build-push-action@v4 + with: + context: ./src + file: src/RequestLogger/Dockerfile + builder: ${{ steps.buildx.outputs.name }} + tags: ${{ steps.docker-meta.outputs.tags }} + labels: ${{ steps.docker-meta.outputs.labels }} + push: true + + build-push-nginx: + runs-on: ubuntu-latest + + steps: + - id: checkout + uses: actions/checkout@v3 + + - id: buildx + uses: docker/setup-buildx-action@v2 + + - id: docker-meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/dlcs/request-logger-nginx + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,format=long + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - id: docker-cache + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - id: ghcr-login + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - id: docker_build + uses: docker/build-push-action@v4 + with: + context: ./nginx + file: nginx/nginx.Dockerfile + builder: ${{ steps.buildx.outputs.name }} + tags: ${{ steps.docker-meta.outputs.tags }} + labels: ${{ steps.docker-meta.outputs.labels }} + push: true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 64fddec..3a1901a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,399 +1,406 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.tlog -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio 6 auto-generated project file (contains which files were open etc.) -*.vbp - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) -*.dsw -*.dsp - -# Visual Studio 6 technical files -*.ncb -*.aps - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# Visual Studio History (VSHistory) files -.vshistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ - -# Windows Installer files from build outputs -*.cab -*.msi -*.msix -*.msm -*.msp - -# JetBrains Rider -*.sln.iml -*.idea/ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml +*.idea/ + +# Docker +*.env + +# Project specific +*.Development.json +*.Docker.json \ No newline at end of file diff --git a/README.md b/README.md index d2ff2bd..8798c61 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ # RequestLogger An API used to log all requests so that they can be reviewed at a later point + +### Local installation + +#### Docker + +This project makes use of entity framework code-first and a postgres SQL database. in order to run the application, the following steps must be followed. + +first there is a local docker compose file found in the `compose` directory. This can be run from that directory with the following command: + +```powershell +docker-compose -f docker-compose-local.yml up +``` +**Note:** the postgres container needs environment variables in a `.env` file. There's an example in the project under `.env-dist`, but it's reccomended to change the username and password to something more secure. + +This will run 4 containers. These are as follows: + +- [Nginx](https://hub.docker.com/_/nginx) + - The application is designed to run as a [mirror](http://nginx.org/en/docs/http/ngx_http_mirror_module.html) for the main application behind Nginx. This container is to mimic this behaviour +- [Mock Server](https://www.mock-server.com/#what-is-mockserver) + - This is to mock out a succesful response from all endpoints going through the initial `proxy_pass` from Nginx. it will always respond with `{"test": "test"}` +- [PostgreSQL](https://hub.docker.com/_/postgres) + - This is the database that holds all the request being logged by the request logger +- A built version of the Request Logger application + - This is built from the Dockerfile found in RequestLogger + +#### RequestLogger Settings + +by default, the application is set to use settings from the `appsettings.Docker.json` app settings file. If changes are made to this file after the containers are built, the command `docker-compose -f docker-compose-local.yml build` will need to be run from the `compose` folder. + +#### Entity Framework + +Once the docker containers are built, the database can be constructed by setting the `RunMigrations` value to `true` in the `appsettings` and the migrations will be run on startup. + +##### Adding migrations + +Migrations can be added with the following commaand being run from the `src` directory + +```powershell +dotnet ef migrations add -p .\Repository\ -s .\RequestLogger\ +``` \ No newline at end of file diff --git a/compose/.env-dist b/compose/.env-dist new file mode 100644 index 0000000..d16df0b --- /dev/null +++ b/compose/.env-dist @@ -0,0 +1,11 @@ +# PostgreSQL +# ------------------------------------------------------------------------------ +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_DB=postgres +POSTGRES_USER=postgres +POSTGRES_PASSWORD=rl_password + +# Request Logger +# ------------------------------------------------------------------------------- +ASPNETCORE_ENVIRONMENT=Docker \ No newline at end of file diff --git a/compose/docker-compose-local.yml b/compose/docker-compose-local.yml deleted file mode 100644 index 525b7f1..0000000 --- a/compose/docker-compose-local.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: '3' -name: request-logger - -services: - web: - image: nginx - container_name: nginx - volumes: - - ../src/nginx.conf:/etc/nginx/nginx.conf:ro - command: [nginx-debug, '-g', 'daemon off;'] - ports: - - "8080:80" - environment: - - NGINX_HOST=foobar.com - - NGINX_PORT=80 - networks: - - nginx.docker - - requestlogger: - container_name: request-logger - build: - context: ../src - dockerfile: RequestLogger\Dockerfile - networks: - - nginx.docker - - mockserver: - image: mockserver/mockserver:latest - container_name: mock-server - environment: - MOCKSERVER_WATCH_INITIALIZATION_JSON: "true" - MOCKSERVER_PROPERTY_FILE: /config/mockserver.properties - MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json - volumes: - - ../src/MockServerConfig/initializerJson.json:/config/initializerJson.json:ro - networks: - - nginx.docker - -networks: - nginx.docker: - name: nginx.docker \ No newline at end of file diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml new file mode 100644 index 0000000..3dd80da --- /dev/null +++ b/compose/docker-compose.yml @@ -0,0 +1,56 @@ +version: '3' +name: request-logger + +services: + web: + container_name: nginx + build: + context: ../nginx + dockerfile: nginx.Dockerfile + command: [nginx-debug, '-g', 'daemon off;'] + ports: + - "8080:8080" + environment: + - NGINX_HOST=foobar.com + - NGINX_PORT=80 + - EXTERNAL_PORT=8080 + - NGINX_PROXY_PASS_MIRROR_LOCATION=http://requestlogger + - NGINX_PROXY_PASS_LOCATION=http://mockserver:1080 + - SERVICE=DLCS-local + - NGINX_RESOLVER=127.0.0.11 + + requestlogger: + container_name: request-logger + build: + context: ../src + dockerfile: RequestLogger\Dockerfile + environment: + - ConnectionStrings__PostgreSQLConnection=Server=postgres;Port=5432;Database=${POSTGRES_DB};User Id=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}; + env_file: + - .env + + mockserver: + image: mockserver/mockserver:latest + container_name: mock-server + environment: + MOCKSERVER_WATCH_INITIALIZATION_JSON: "true" + MOCKSERVER_PROPERTY_FILE: /config/mockserver.properties + MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json + volumes: + - ../src/MockServerConfig/initializerJson.json:/config/initializerJson.json:ro + + postgres: + image: postgres:12.15 + container_name: postgres + hostname: postgres + ports: + - "5452:5432" + volumes: + - rl_postgres_data:/var/lib/postgresql/data + - rl_postgres_data_backups:/backups + env_file: + - .env + +volumes: + rl_postgres_data: {} + rl_postgres_data_backups: {} \ No newline at end of file diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh new file mode 100644 index 0000000..4e2ddd1 --- /dev/null +++ b/nginx/docker-entrypoint.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +set -eu + +envsubst '${EXTERNAL_PORT} ${NGINX_PROXY_PASS_LOCATION} ${NGINX_PROXY_PASS_MIRROR_LOCATION} ${SERVICE} ${NGINX_RESOLVER}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf + +exec "$@" \ No newline at end of file diff --git a/nginx/nginx.Dockerfile b/nginx/nginx.Dockerfile new file mode 100644 index 0000000..f3bdd15 --- /dev/null +++ b/nginx/nginx.Dockerfile @@ -0,0 +1,8 @@ +FROM nginx + +COPY ./nginx.default.conf /etc/nginx/conf.d/default.conf.template + +COPY docker-entrypoint.sh / +RUN chmod +x docker-entrypoint.sh +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/nginx.default.conf b/nginx/nginx.default.conf new file mode 100644 index 0000000..9ca01bc --- /dev/null +++ b/nginx/nginx.default.conf @@ -0,0 +1,28 @@ + +error_log /var/log/nginx/error.log; +access_log /var/log/nginx/access.log; + +server { + server_name ""; + # Docker resolver + resolver ${NGINX_RESOLVER}; + listen ${EXTERNAL_PORT}; + + location = /favicon.ico { + access_log off; + log_not_found off; + } + + location / { + mirror /mirror; + mirror_request_body on; + proxy_pass ${NGINX_PROXY_PASS_LOCATION}; + } + + location /mirror { + proxy_set_header X-Forwarded-For "$http_x_forwarded_for, $realip_remote_addr"; + proxy_set_header X-Service ${SERVICE}; + internal; + proxy_pass ${NGINX_PROXY_PASS_MIRROR_LOCATION}$request_uri; + } +} \ No newline at end of file diff --git a/src/Repository/Migrations/20230705100711_InitialCreate.Designer.cs b/src/Repository/Migrations/20230705100711_InitialCreate.Designer.cs new file mode 100644 index 0000000..acbc367 --- /dev/null +++ b/src/Repository/Migrations/20230705100711_InitialCreate.Designer.cs @@ -0,0 +1,80 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Repository; + +#nullable disable + +namespace Repository.Migrations +{ + [DbContext(typeof(RequestLoggerContext))] + [Migration("20230705100711_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.19") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Repository.Models.HttpRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Body") + .HasColumnType("jsonb") + .HasColumnName("body"); + + b.Property("Customer") + .HasColumnType("text") + .HasColumnName("customer"); + + b.Property("Headers") + .HasColumnType("jsonb") + .HasColumnName("headers"); + + b.Property("Path") + .IsRequired() + .HasColumnType("text") + .HasColumnName("path"); + + b.Property("QueryParams") + .HasColumnType("text") + .HasColumnName("query_params"); + + b.Property("RequestTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("request_time"); + + b.Property("Service") + .HasColumnType("text") + .HasColumnName("service"); + + b.Property("Verb") + .IsRequired() + .HasColumnType("text") + .HasColumnName("verb"); + + b.HasKey("Id") + .HasName("pk_requests"); + + b.ToTable("requests", (string)null); + + b.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Repository/Migrations/20230705100711_InitialCreate.cs b/src/Repository/Migrations/20230705100711_InitialCreate.cs new file mode 100644 index 0000000..345961f --- /dev/null +++ b/src/Repository/Migrations/20230705100711_InitialCreate.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Repository.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "requests", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + verb = table.Column(type: "text", nullable: false), + service = table.Column(type: "text", nullable: true), + customer = table.Column(type: "text", nullable: true), + path = table.Column(type: "text", nullable: false), + query_params = table.Column(type: "text", nullable: true), + body = table.Column(type: "jsonb", nullable: true), + headers = table.Column(type: "jsonb", nullable: true), + request_time = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_requests", x => x.id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "requests"); + } + } +} diff --git a/src/Repository/Migrations/RequestLoggerContextModelSnapshot.cs b/src/Repository/Migrations/RequestLoggerContextModelSnapshot.cs new file mode 100644 index 0000000..030c3e9 --- /dev/null +++ b/src/Repository/Migrations/RequestLoggerContextModelSnapshot.cs @@ -0,0 +1,78 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Repository; + +#nullable disable + +namespace Repository.Migrations +{ + [DbContext(typeof(RequestLoggerContext))] + partial class RequestLoggerContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.19") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Repository.Models.HttpRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Body") + .HasColumnType("jsonb") + .HasColumnName("body"); + + b.Property("Customer") + .HasColumnType("text") + .HasColumnName("customer"); + + b.Property("Headers") + .HasColumnType("jsonb") + .HasColumnName("headers"); + + b.Property("Path") + .IsRequired() + .HasColumnType("text") + .HasColumnName("path"); + + b.Property("QueryParams") + .HasColumnType("text") + .HasColumnName("query_params"); + + b.Property("RequestTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("request_time"); + + b.Property("Service") + .HasColumnType("text") + .HasColumnName("service"); + + b.Property("Verb") + .IsRequired() + .HasColumnType("text") + .HasColumnName("verb"); + + b.HasKey("Id") + .HasName("pk_requests"); + + b.ToTable("requests", (string)null); + + b.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Repository/Models/HttpRequest.cs b/src/Repository/Models/HttpRequest.cs new file mode 100644 index 0000000..3dcd746 --- /dev/null +++ b/src/Repository/Models/HttpRequest.cs @@ -0,0 +1,49 @@ +namespace Repository.Models; + +public class HttpRequest +{ + /// + /// Unique identifier for a request + /// + public int Id { get; set; } + + /// + /// The http verb associated with the request + /// + public string Verb { get; set; } = null!; + + /// + /// The calling service + /// + public string? Service { get; set; } + + /// + /// The customer calling the service + /// + public string? Customer { get; set; } + + /// + /// The HTTP path of the request + /// + public string Path { get; set; } = null!; + + /// + /// The query parameters on the request + /// + public string? QueryParams { get; set; } + + /// + /// The body of the request + /// + public string? Body { get; set; } + + /// + /// The headers associated with a request + /// + public string? Headers { get; set; } + + /// + /// The time the request was made + /// + public DateTime RequestTime { get; set; } +} \ No newline at end of file diff --git a/src/Repository/Repository.csproj b/src/Repository/Repository.csproj new file mode 100644 index 0000000..95f128e --- /dev/null +++ b/src/Repository/Repository.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/src/Repository/RequestLoggerContext.cs b/src/Repository/RequestLoggerContext.cs new file mode 100644 index 0000000..76723a5 --- /dev/null +++ b/src/Repository/RequestLoggerContext.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Repository.Models; + + +namespace Repository; + +public class RequestLoggerContext : DbContext +{ + /// + /// Context class for entity framework + /// + /// The db context options + public RequestLoggerContext(DbContextOptions options) + : base(options) + { + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(builder => + { + builder.HasKey(i => i.Id); + builder.HasAnnotation("Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + builder.Property(p => p.Body).HasColumnType("jsonb"); + builder.Property(p => p.Headers).HasColumnType("jsonb"); + }); + } + + public virtual DbSet Requests { get; set; } = null!; +} \ No newline at end of file diff --git a/src/Repository/RequestLoggerContextConfiguration.cs b/src/Repository/RequestLoggerContextConfiguration.cs new file mode 100644 index 0000000..89b5df5 --- /dev/null +++ b/src/Repository/RequestLoggerContextConfiguration.cs @@ -0,0 +1,58 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Serilog; + +namespace Repository; + +public static class RequestLoggerContextConfiguration +{ + private static readonly string ConnectionStringKey = "PostgreSQLConnection"; + private static readonly string RunMigrationsKey = "RunMigrations"; + + /// + /// Register and configure + /// + public static IServiceCollection AddRequestLoggerContext(this IServiceCollection services, + IConfiguration configuration) + => services + .AddDbContext(options => SetupOptions(configuration, options)); + private static void SetupOptions(IConfiguration configuration, + DbContextOptionsBuilder optionsBuilder) + => optionsBuilder + .UseNpgsql(configuration.GetConnectionString(ConnectionStringKey) ?? string.Empty) + .UseSnakeCaseNamingConvention(); + + /// + /// Run EF migrations if "RunMigrations" = true + /// + public static void TryRunMigrations(IConfiguration configuration) + { + if (configuration.GetValue(RunMigrationsKey, false)) + { + using var context = new RequestLoggerContext(GetOptionsBuilder(configuration).Options); + var pendingMigrations = context.Database.GetPendingMigrations().ToList(); + if (pendingMigrations.Count == 0) + { + Log.Information("No migrations to run"); + return; + } + + Log.Information("Running migrations: {Migrations}", string.Join(",", pendingMigrations)); + context.Database.Migrate(); + } + } + + /// + /// Get a new instantiated object + /// + public static RequestLoggerContext GetNewDbContext(IConfiguration configuration) + => new(GetOptionsBuilder(configuration).Options); + + private static DbContextOptionsBuilder GetOptionsBuilder(IConfiguration configuration) + { + var optionsBuilder = new DbContextOptionsBuilder(); + SetupOptions(configuration, optionsBuilder); + return optionsBuilder; + } +} \ No newline at end of file diff --git a/src/RequestLogger.Tests/Helpers/RequestLoggerAppBuilderFactory.cs b/src/RequestLogger.Tests/Helpers/RequestLoggerAppBuilderFactory.cs new file mode 100644 index 0000000..645f9b1 --- /dev/null +++ b/src/RequestLogger.Tests/Helpers/RequestLoggerAppBuilderFactory.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Configuration; + +namespace RequestLogger.Tests.Helpers; + +public class RequestLoggerAppBuilderFactory : WebApplicationFactory + where TStartup : class +{ + //private readonly Dictionary _configuration = new(); + + + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + var projectDir = Directory.GetCurrentDirectory(); + var configPath = Path.Combine(projectDir, "appsettings.Testing.json"); + + builder + .ConfigureAppConfiguration((context, conf) => + { + conf.AddJsonFile(configPath); + //conf.AddInMemoryCollection(_configuration); + }) + .UseEnvironment("Testing"); + } +} \ No newline at end of file diff --git a/src/RequestLogger.Tests/RequestLogger.Tests.csproj b/src/RequestLogger.Tests/RequestLogger.Tests.csproj new file mode 100644 index 0000000..dad0684 --- /dev/null +++ b/src/RequestLogger.Tests/RequestLogger.Tests.csproj @@ -0,0 +1,40 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + PreserveNewest + + + + diff --git a/src/RequestLogger.Tests/Unit/BlacklistServiceTests.cs b/src/RequestLogger.Tests/Unit/BlacklistServiceTests.cs new file mode 100644 index 0000000..9a5935d --- /dev/null +++ b/src/RequestLogger.Tests/Unit/BlacklistServiceTests.cs @@ -0,0 +1,141 @@ +using AutoFixture; +using FluentAssertions; +using Microsoft.Extensions.Options; +using RequestLogger.Dto; +using RequestLogger.Services; +using RequestLogger.Settings; + +namespace RequestLogger.Tests.Unit; + +public class BlacklistServiceTests +{ + private readonly BlacklistService _blacklistService; + private readonly Fixture _fixture; + + public BlacklistServiceTests() + { + var settings = new RequestLoggerSettings() + { + BlacklistSettings = new BlacklistSettings() + { + EndpointBlacklist = new List() + { + "/blacklist/path" + }, + HeaderBlacklist = new List() + { + "blacklist" + }, + BodyStorageBlacklist = new List() + { + "/blacklist/body" + }, + QueryParamBlacklist = new List() + { + "blacklist" + } + } + }; + + _blacklistService = new BlacklistService(Options.Create(settings)); + _fixture = new Fixture(); + } + + [Fact] + public void CheckBlacklist_ReturnsUnmodifiedObject_WhenCalledCorrectly() + { + // Arrange + var request = _fixture.Create(); + + // Act + var checkedBlacklist = _blacklistService.CheckBlacklist(request); + + //Assert + checkedBlacklist.DoNotStore.Should().BeFalse(); + checkedBlacklist.request?.Body.Should().Be(request.Body); + checkedBlacklist.request?.Headers.Should().Contain(request.Headers); + checkedBlacklist.request?.Path.Should().Be(request.Path); + checkedBlacklist.request?.QueryParams.Should().Contain(request.QueryParams); + } + + [Fact] + public void CheckBlacklist_ReturnsDoNotStoreAsTrue_WhenCalledWithBlacklistedPath() + { + // Arrange + var request = _fixture. + Build() + .With(r => r.Path, "/blacklist/path") + .Create(); + + // Act + var checkedBlacklist = _blacklistService.CheckBlacklist(request); + + //Assert + checkedBlacklist.DoNotStore.Should().BeTrue(); + checkedBlacklist.request.Should().BeNull(); + } + + [Fact] + public void CheckBlacklist_ReturnsWithoutHeader_WhenCalledWithBlacklistedHeader() + { + // Arrange + var headers = new Dictionary { { "blacklist", "whoCares" } }; + + var request = _fixture. + Build() + .With(r => r.Headers, headers) + .Create(); + + // Act + var checkedBlacklist = _blacklistService.CheckBlacklist(request); + + //Assert + checkedBlacklist.DoNotStore.Should().BeFalse(); + checkedBlacklist.request?.Body.Should().Be(request.Body); + checkedBlacklist.request?.Headers.Count.Should().Be(0); + checkedBlacklist.request?.Path.Should().Be(request.Path); + checkedBlacklist.request?.QueryParams.Should().Contain(request.QueryParams); + } + + [Fact] + public void CheckBlacklist_ReturnsWithRemovedBody_WhenCalledWithBlacklistedBodyStoragePath() + { + // Arrange + var request = _fixture. + Build() + .With(r => r.Path, "/blacklist/body") + .Create(); + + // Act + var checkedBlacklist = _blacklistService.CheckBlacklist(request); + + //Assert + checkedBlacklist.DoNotStore.Should().BeFalse(); + checkedBlacklist.request?.Body.Should().Be("{ \"jsonRemoved\": \"json\" }"); + checkedBlacklist.request?.Headers.Should().Contain(request.Headers); + checkedBlacklist.request?.Path.Should().Be(request.Path); + checkedBlacklist.request?.QueryParams.Should().Contain(request.QueryParams); + } + + [Fact] + public void CheckBlacklist_ReturnsWithRemovedQueryParam_WhenCalledWithBlacklistedQueryParam() + { + // Arrange + var queryParams = new Dictionary { { "blacklist", "whoCares" } }; + + var request = _fixture. + Build() + .With(r => r.QueryParams, queryParams) + .Create(); + + // Act + var checkedBlacklist = _blacklistService.CheckBlacklist(request); + + //Assert + checkedBlacklist.DoNotStore.Should().BeFalse(); + checkedBlacklist.request?.Body.Should().Be(request.Body); + checkedBlacklist.request?.Headers.Should().Contain(request.Headers); + checkedBlacklist.request?.Path.Should().Be(request.Path); + checkedBlacklist.request?.QueryParams?.Count.Should().Be(0); + } +} \ No newline at end of file diff --git a/src/RequestLogger.Tests/Unit/ProgramTests.cs b/src/RequestLogger.Tests/Unit/ProgramTests.cs new file mode 100644 index 0000000..1ba8678 --- /dev/null +++ b/src/RequestLogger.Tests/Unit/ProgramTests.cs @@ -0,0 +1,187 @@ +using System.Text.Json; +using FakeItEasy; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.DependencyInjection; +using Repository; +using RequestLogger.Dto; +using RequestLogger.Services; +using RequestLogger.Services.Interfaces; +using AutoFixture; +using FluentAssertions; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; +using RequestLogger.Tests.Helpers; + +#pragma warning disable CS8620 + +namespace RequestLogger.Tests.Unit; + +public class ProgramTests +{ + private readonly WebApplicationFactory _sut; + + public ProgramTests() + { + var root = new InMemoryDatabaseRoot(); + + _sut = new RequestLoggerAppBuilderFactory() + .WithWebHostBuilder(builder => builder.ConfigureServices(services => + { + var descriptor = services.SingleOrDefault( + d => d.ServiceType == + typeof(DbContextOptions)); + + services.Remove(descriptor!); + services.AddScoped(); + services.AddScoped(); + services.AddDbContext(x => x.UseInMemoryDatabase("Testing", root)); + })); + } + + [Fact] + public async Task Program_CallingGet_ReturnsResponse() + { + // Arrange + var client = _sut.CreateClient(); + + // Act + var response = await client.GetAsync("/stuff/"); + var responseBody = await response.Content.ReadAsStringAsync(); + + //Assert + response.Should().NotBeNull(); + response.IsSuccessStatusCode.Should().BeTrue(); + responseBody.Should().Contain("GET"); + } + + [Fact] + public async Task Program_MakingCall_ReturnsResponseFromDatabase() + { + // Arrange + var client = _sut.CreateClient(); + + + + // Act + var response = await client.GetAsync("/stuff/"); + + var responseContent = await response.Content.ReadAsStringAsync(); + var parsedContent = JsonSerializer.Deserialize(responseContent); + + //Assert + response.Should().NotBeNull(); + response.IsSuccessStatusCode.Should().BeTrue(); + parsedContent?.Customer.Should().BeNull(); + parsedContent?.Body.Should().BeNull(); + parsedContent?.Verb.Should().Be("GET"); + parsedContent?.QueryParams.Should().BeNull(); + } + + [Fact] + public async Task Program_MakingCall_ReturnsCustomerSuccessfully() + { + // Arrange + var client = _sut.CreateClient(); + + // Act + var response = await client.GetAsync("/stuff/customers/3425234"); + + var responseContent = await response.Content.ReadAsStringAsync(); + var parsedContent = JsonSerializer.Deserialize(responseContent); + + //Assert + response.Should().NotBeNull(); + response.IsSuccessStatusCode.Should().BeTrue(); + parsedContent?.Customer.Should().Be("3425234"); + parsedContent?.Body.Should().BeNull(); + parsedContent?.Verb.Should().Be("GET"); + parsedContent?.QueryParams.Should().BeNull(); + } + + [Fact] + public async Task Program_MakingCall_ReturnsQueryParamsSuccessfully() + { + // Arrange + var client = _sut.CreateClient(); + + // Act + var response = await client.GetAsync("/some/url/3425234?query=something"); + + var responseContent = await response.Content.ReadAsStringAsync(); + var parsedContent = JsonSerializer.Deserialize(responseContent); + + //Assert + response.Should().NotBeNull(); + response.IsSuccessStatusCode.Should().BeTrue(); + parsedContent?.Customer.Should().BeNull(); + parsedContent?.Body.Should().BeNull(); + parsedContent?.Verb.Should().Be("GET"); + parsedContent?.QueryParams.Should().ContainKey("query"); + } + + [Fact] + public async Task Program_MakingPostCall_ReturnsCorrectVerb() + { + // Arrange + var client = _sut.CreateClient(); + + // Act + var response = await client.PostAsync("/some/uri", new StringContent("")); + + var responseContent = await response.Content.ReadAsStringAsync(); + var parsedContent = JsonSerializer.Deserialize(responseContent); + + //Assert + response.Should().NotBeNull(); + response.IsSuccessStatusCode.Should().BeTrue(); + parsedContent?.Customer.Should().BeNull(); + parsedContent?.Body.Should().BeNull(); + parsedContent?.Verb.Should().Be("POST"); + parsedContent?.QueryParams.Should().BeNull(); + } + + [Fact] + public async Task Program_MakingPostCallWithJsonBody_ReturnsCorrectBody() + { + // Arrange + var client = _sut.CreateClient(); + var jsonBody = "{\"test\": \"test\"}"; + + // Act + var response = await client.PostAsync("/some/uri", new StringContent(jsonBody)); + + var responseContent = await response.Content.ReadAsStringAsync(); + var parsedContent = JsonSerializer.Deserialize(responseContent); + + //Assert + response.Should().NotBeNull(); + response.IsSuccessStatusCode.Should().BeTrue(); + parsedContent?.Customer.Should().BeNull(); + parsedContent?.Body.Should().Be(jsonBody); + parsedContent?.Verb.Should().Be("POST"); + parsedContent?.QueryParams.Should().BeNull(); + } + + [Fact] + public async Task Program_MakingPostCallWithInvalidJsonBody_ReturnsCorrectBody() + { + // Arrange + var client = _sut.CreateClient(); + var requestBody = "test"; + var jsonBody = "{ \"invalidJson\": \"test\" }"; + + // Act + var response = await client.PostAsync("/some/uri", new StringContent(requestBody)); + + var responseContent = await response.Content.ReadAsStringAsync(); + var parsedContent = JsonSerializer.Deserialize(responseContent); + + //Assert + response.Should().NotBeNull(); + response.IsSuccessStatusCode.Should().BeTrue(); + parsedContent?.Customer.Should().BeNull(); + parsedContent?.Body.Should().Be(jsonBody); + parsedContent?.Verb.Should().Be("POST"); + parsedContent?.QueryParams.Should().BeNull(); + } +} \ No newline at end of file diff --git a/src/RequestLogger.Tests/Unit/RequestLoggerServiceTests.cs b/src/RequestLogger.Tests/Unit/RequestLoggerServiceTests.cs new file mode 100644 index 0000000..e88e1b7 --- /dev/null +++ b/src/RequestLogger.Tests/Unit/RequestLoggerServiceTests.cs @@ -0,0 +1,64 @@ +using AutoFixture; +using FluentAssertions; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.Options; +using Repository; +using RequestLogger.Dto; +using RequestLogger.Services; +using RequestLogger.Settings; + +namespace RequestLogger.Tests.Unit; + +public class RequestLoggerServiceTests +{ + private readonly RequestLoggerService _requestLoggerService; + + private readonly RequestLoggerContext _requestLoggerContext; + + private readonly Fixture _fixture; + + public RequestLoggerServiceTests() + { + var root = new InMemoryDatabaseRoot(); + + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase("test", root).Options; + _requestLoggerContext = new RequestLoggerContext(options); + + _requestLoggerService = new RequestLoggerService(_requestLoggerContext, new BlacklistService(Options.Create(new RequestLoggerSettings()))); + _fixture = new Fixture(); + } + + [Fact] + public async Task WriteLogMessage_ReturnsLogMessage_WhenCalledCorrectly() + { + // Arrange + var request = _fixture.Create(); + + // Act + var response = await _requestLoggerService.WriteLogMessage(request); + + //Assert + response?.Body.Should().Be(request.Body); + response?.Verb.Should().Be(request.Verb); + response?.Customer.Should().Be(request.Customer); + } + + [Fact] + public async Task WriteLogMessage_ActuallyWritesToDatabase_WhenCalledCorrectly() + { + // Arrange + var request = _fixture.Create(); + + // Act + _ = await _requestLoggerService.WriteLogMessage(request); + + //Assert + var databaseItem = _requestLoggerContext.Requests.FirstOrDefault(r => r.Id == 1); + + databaseItem?.Body.Should().Be(request.Body); + databaseItem?.Verb.Should().Be(request.Verb); + databaseItem?.Customer.Should().Be(request.Customer); + } +} \ No newline at end of file diff --git a/src/RequestLogger.Tests/Usings.cs b/src/RequestLogger.Tests/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/src/RequestLogger.Tests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/src/RequestLogger.Tests/appsettings.Testing.json b/src/RequestLogger.Tests/appsettings.Testing.json new file mode 100644 index 0000000..f6e8c35 --- /dev/null +++ b/src/RequestLogger.Tests/appsettings.Testing.json @@ -0,0 +1,25 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "RequestLoggerSettings" : { + "BlacklistSettings" : { + "HeaderBlacklist": [ + "Blacklisted" + ], + "QueryParamBlacklist": [ + "blacklist" + ], + "EndpointBlacklist": [ + "/blacklist/test" + ], + "BodyStorageBlacklist": [ + "/blacklist/noBody" + ] + } + }, + "RunMigrations": false +} diff --git a/src/RequestLogger.sln b/src/RequestLogger.sln index 4b966d4..3c76ffa 100644 --- a/src/RequestLogger.sln +++ b/src/RequestLogger.sln @@ -2,6 +2,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RequestLogger", "RequestLogger\RequestLogger.csproj", "{84CD6D44-A4F7-4FBC-8961-0FB7BF2D2D35}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository", "Repository\Repository.csproj", "{760E0EFC-C21E-46BA-9A39-C6E1D72D012E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{39AFEA94-0387-4293-9046-6192B90B0D57}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RequestLogger.Tests", "RequestLogger.Tests\RequestLogger.Tests.csproj", "{18D1EA7C-7927-4449-B88D-A192326F11B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +18,16 @@ Global {84CD6D44-A4F7-4FBC-8961-0FB7BF2D2D35}.Debug|Any CPU.Build.0 = Debug|Any CPU {84CD6D44-A4F7-4FBC-8961-0FB7BF2D2D35}.Release|Any CPU.ActiveCfg = Release|Any CPU {84CD6D44-A4F7-4FBC-8961-0FB7BF2D2D35}.Release|Any CPU.Build.0 = Release|Any CPU + {760E0EFC-C21E-46BA-9A39-C6E1D72D012E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {760E0EFC-C21E-46BA-9A39-C6E1D72D012E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {760E0EFC-C21E-46BA-9A39-C6E1D72D012E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {760E0EFC-C21E-46BA-9A39-C6E1D72D012E}.Release|Any CPU.Build.0 = Release|Any CPU + {18D1EA7C-7927-4449-B88D-A192326F11B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18D1EA7C-7927-4449-B88D-A192326F11B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18D1EA7C-7927-4449-B88D-A192326F11B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18D1EA7C-7927-4449-B88D-A192326F11B2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {18D1EA7C-7927-4449-B88D-A192326F11B2} = {39AFEA94-0387-4293-9046-6192B90B0D57} EndGlobalSection EndGlobal diff --git a/src/RequestLogger/Controllers/WeatherForecastController.cs b/src/RequestLogger/Controllers/WeatherForecastController.cs deleted file mode 100644 index 86fa7fa..0000000 --- a/src/RequestLogger/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace RequestLogger.Controllers; - -[ApiController] -[Route("[controller]")] -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 = DateTime.Now.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } -} diff --git a/src/RequestLogger/Dto/Converters/RequestConverter.cs b/src/RequestLogger/Dto/Converters/RequestConverter.cs new file mode 100644 index 0000000..bf305ae --- /dev/null +++ b/src/RequestLogger/Dto/Converters/RequestConverter.cs @@ -0,0 +1,22 @@ +using System.Text.Json; +using HttpRequest = Repository.Models.HttpRequest; + +namespace RequestLogger.Dto.Converters; + +public static class RequestConverter +{ + public static HttpRequest ConvertRequest(Request request) + { + return new HttpRequest + { + Verb = request.Verb, + Service = request.Service, + Customer = request.Customer, + Path = request.Path, + QueryParams = request.QueryParams != null ? JsonSerializer.Serialize(request.QueryParams) : null, + Body = request.Body, + Headers = JsonSerializer.Serialize(request.Headers), + RequestTime = request.RequestTime + }; + } +} \ No newline at end of file diff --git a/src/RequestLogger/Dto/Request.cs b/src/RequestLogger/Dto/Request.cs new file mode 100644 index 0000000..f412eb7 --- /dev/null +++ b/src/RequestLogger/Dto/Request.cs @@ -0,0 +1,46 @@ +using System.Collections.Specialized; + +namespace RequestLogger.Dto; + +public class Request +{ + /// + /// The http verb associated with the request + /// + public string Verb { get; init; } = null!; + + /// + /// The calling service + /// + public string? Service { get; init; } + + /// + /// The customer calling the service + /// + public string? Customer { get; init; } + + /// + /// The HTTP path of the request + /// + public string Path { get; init; } = null!; + + /// + /// The query parameters on the request + /// + public Dictionary? QueryParams { get; init; } + + /// + /// The body of the request + /// + public string? Body { get; set; } + + /// + /// The headers associated with a request + /// + public Dictionary Headers { get; init; } = null!; + + /// + /// The time the request was made + /// + public DateTime RequestTime { get; init; } +} \ No newline at end of file diff --git a/src/RequestLogger/Program.cs b/src/RequestLogger/Program.cs index 30fba39..8840146 100644 --- a/src/RequestLogger/Program.cs +++ b/src/RequestLogger/Program.cs @@ -1,9 +1,17 @@ +using System.Text.Json; +using System.Web; +using HealthChecks.UI.Client; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.EntityFrameworkCore; +using Repository; +using RequestLogger.Dto; +using RequestLogger.Services; +using RequestLogger.Services.Interfaces; +using RequestLogger.Settings; using Serilog; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. - // remove default logging providers builder.Logging.ClearProviders(); // Serilog configuration @@ -11,14 +19,25 @@ .WriteTo.Console() .CreateLogger(); -// Register Serilog -builder.Logging.AddSerilog(logger); +Log.Logger = logger; +builder.Logging.AddSerilog(logger); +builder.Services.AddHttpContextAccessor(); builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.Configure(builder.Configuration.GetSection("RequestLoggerSettings")); + +builder.Services.AddRequestLoggerContext(builder.Configuration); + +builder.Services.AddHealthChecks().AddDbContextCheck(); + +builder.Services.AddScoped(); + +builder.Services.AddScoped(); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -28,25 +47,132 @@ app.UseSwaggerUI(); } +Log.Information("Request logger settings: {@Settings}", app.Configuration.GetSection("RequestLoggerSettings").Get()); + +RequestLoggerContextConfiguration.TryRunMigrations(builder.Configuration); + +app.UseRouting(); + app.UseHttpsRedirection(); app.UseAuthorization(); -app.Use(async (context, next) => +app.UseEndpoints(endpoints => +{ + endpoints.MapHealthChecks("/health", new HealthCheckOptions + { + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); +}); + +app.Run(async (context) => { context.Request.EnableBuffering(); context.Request.Body.Position = 0; - var rawRequestBody = await new StreamReader(context.Request.Body).ReadToEndAsync(); - Console.WriteLine(rawRequestBody); + var requestBody = await GetRequestBody(context); - await context.Response.WriteAsync("Ok"); - return; + using var scoped = app.Services.CreateScope(); - // This is never hit, but the code complains if it's not there - await next(context); + // gets the customer id from a path like somePath/customer//somePath + var customerId = TryGetCustomerId(context); + + var requestLoggerService = scoped.ServiceProvider.GetRequiredService(); + + // converts query string into a dictionary (if it has values) + var queryStringDictionary = BuildQueryStringDictionary(context); + + var service = TryGetServiceName(context); + + var request = new Request() + { + Verb = context.Request.Method, + Service = service, + Customer = customerId, + Path = context.Request.Path, + QueryParams = queryStringDictionary, + Body = requestBody, + Headers = context.Request.Headers.ToDictionary(a => a.Key, a => a.Value.ToString()), + RequestTime = DateTime.UtcNow + }; + + var requestCompleted = await requestLoggerService.WriteLogMessage(request); + + await SendResponse(requestCompleted, context); }); -app.MapControllers(); +async Task SendResponse(Request? request, HttpContext httpContext) +{ + try + { + await httpContext.Response.WriteAsync(JsonSerializer.Serialize(request)); + } + catch (Exception exception) + { + Log.Error(exception, "Error writing a response"); + } +} + +string TryGetServiceName(HttpContext httpContext) +{ + var s = httpContext.Request.Headers.TryGetValue("X-Service", out var header) + ? header.ToString() + : httpContext.Request.Host.Value; + return s; +} + +Dictionary? BuildQueryStringDictionary(HttpContext httpContext) +{ + var parsedQueryString = HttpUtility.ParseQueryString(httpContext.Request.QueryString.ToString()); + var dictionary = parsedQueryString.HasKeys() + ? parsedQueryString.AllKeys.ToDictionary(k => k!, k => parsedQueryString[k]!) + : null; + return dictionary; +} + +string? TryGetCustomerId(HttpContext httpContext) +{ + var s = httpContext.Request.Path.ToString().Split('/') + .SkipWhile(p => !p.Equals("customers", StringComparison.OrdinalIgnoreCase)).Skip(1).FirstOrDefault(); + return s; +} + +async Task GetRequestBody(HttpContext context) +{ + var requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync(); + + if (!requestBody.Equals(string.Empty)) + { + // just convert the body into minimal Json if it isn't Json + if (!IsJsonValid(requestBody)) + { + requestBody = $"{{ \"invalidJson\": \"{requestBody}\" }}"; + } + } + else + { + requestBody = null; + } + + return requestBody; +} + +bool IsJsonValid(string json) +{ + if (string.IsNullOrWhiteSpace(json)) + return false; + + try + { + using var jsonDoc = JsonDocument.Parse(json); + return true; + } + catch (JsonException) + { + return false; + } +} app.Run(); + +public partial class Program { } diff --git a/src/RequestLogger/RequestLogger.csproj b/src/RequestLogger/RequestLogger.csproj index 4061258..d5d944b 100644 --- a/src/RequestLogger/RequestLogger.csproj +++ b/src/RequestLogger/RequestLogger.csproj @@ -8,11 +8,23 @@ + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + - + + @@ -21,4 +33,8 @@ + + + + diff --git a/src/RequestLogger/Services/BlacklistService.cs b/src/RequestLogger/Services/BlacklistService.cs new file mode 100644 index 0000000..6530796 --- /dev/null +++ b/src/RequestLogger/Services/BlacklistService.cs @@ -0,0 +1,53 @@ +using System.Collections.Concurrent; +using Microsoft.Extensions.Options; +using RequestLogger.Dto; +using RequestLogger.Services.Interfaces; +using RequestLogger.Settings; + +namespace RequestLogger.Services; + +public class BlacklistService : IBlacklistService +{ + private const string BodyBlacklistJson = "{ \"jsonRemoved\": \"json\" }"; + + private readonly BlacklistSettings _settings; + + + + public BlacklistService(IOptions settings) + { + _settings = settings.Value.BlacklistSettings; + } + + public (bool DoNotStore, Request? request) CheckBlacklist(Request request) + { + bool doNotStore = false; + + if (_settings.EndpointBlacklist.Any(endpoint => request.Path.StartsWith(endpoint))) + { + doNotStore = true; + // just short circuit the response as nothing else matters + return (doNotStore, null); + } + + foreach (var header in _settings.HeaderBlacklist.Where(header => request.Headers.ContainsKey(header))) + { + request.Headers.Remove(header); + } + + if (request.QueryParams != null) + { + foreach (var queryParam in _settings.QueryParamBlacklist.Where(queryParam => request.QueryParams.ContainsKey(queryParam))) + { + request.QueryParams.Remove(queryParam); + } + } + + if (_settings.BodyStorageBlacklist.Any(body => request.Path.StartsWith(body))) + { + request.Body = BodyBlacklistJson; + } + + return (doNotStore, request); + } +} \ No newline at end of file diff --git a/src/RequestLogger/Services/Interfaces/IBlacklistService.cs b/src/RequestLogger/Services/Interfaces/IBlacklistService.cs new file mode 100644 index 0000000..e824396 --- /dev/null +++ b/src/RequestLogger/Services/Interfaces/IBlacklistService.cs @@ -0,0 +1,8 @@ +using RequestLogger.Dto; + +namespace RequestLogger.Services.Interfaces; + +public interface IBlacklistService +{ + (bool DoNotStore, Request? request) CheckBlacklist(Request request); +} \ No newline at end of file diff --git a/src/RequestLogger/Services/Interfaces/IRequestLoggerService.cs b/src/RequestLogger/Services/Interfaces/IRequestLoggerService.cs new file mode 100644 index 0000000..af16dc9 --- /dev/null +++ b/src/RequestLogger/Services/Interfaces/IRequestLoggerService.cs @@ -0,0 +1,8 @@ +using RequestLogger.Dto; + +namespace RequestLogger.Services.Interfaces; + +public interface IRequestLoggerService +{ + Task WriteLogMessage(Request request); +} \ No newline at end of file diff --git a/src/RequestLogger/Services/RequestLoggerService.cs b/src/RequestLogger/Services/RequestLoggerService.cs new file mode 100644 index 0000000..7e77f39 --- /dev/null +++ b/src/RequestLogger/Services/RequestLoggerService.cs @@ -0,0 +1,34 @@ +using Repository; +using RequestLogger.Dto; +using RequestLogger.Dto.Converters; +using RequestLogger.Services.Interfaces; + +namespace RequestLogger.Services; + +public class RequestLoggerService : IRequestLoggerService +{ + private readonly RequestLoggerContext _context; + private readonly IBlacklistService _blacklistService; + public RequestLoggerService(RequestLoggerContext context, IBlacklistService blacklistService) + { + _context = context; + _blacklistService = blacklistService; + } + + public async Task WriteLogMessage(Request request) + { + var (doNotStore, requestAfterBlacklist) = _blacklistService.CheckBlacklist(request); + + if (doNotStore) return requestAfterBlacklist; + + if (requestAfterBlacklist != null) + { + var httpRequest = RequestConverter.ConvertRequest(requestAfterBlacklist); + await _context.Requests.AddAsync(httpRequest); + } + + await _context.SaveChangesAsync(); + + return requestAfterBlacklist; + } +} \ No newline at end of file diff --git a/src/RequestLogger/Settings/BlacklistSettings.cs b/src/RequestLogger/Settings/BlacklistSettings.cs new file mode 100644 index 0000000..7ba32e5 --- /dev/null +++ b/src/RequestLogger/Settings/BlacklistSettings.cs @@ -0,0 +1,24 @@ +namespace RequestLogger.Settings; + +public class BlacklistSettings +{ + /// + /// Header blacklist + /// + public List HeaderBlacklist { get; init; } = new(); + + /// + /// Query parameter blacklist + /// + public List QueryParamBlacklist { get; init; } = new(); + + /// + /// Endpoint blacklist + /// + public List EndpointBlacklist { get; init; } = new(); + + /// + /// Request body blacklist + /// + public List BodyStorageBlacklist { get; set; } = new(); +} \ No newline at end of file diff --git a/src/RequestLogger/Settings/RequestLoggerSettings.cs b/src/RequestLogger/Settings/RequestLoggerSettings.cs new file mode 100644 index 0000000..5d9eba4 --- /dev/null +++ b/src/RequestLogger/Settings/RequestLoggerSettings.cs @@ -0,0 +1,9 @@ +namespace RequestLogger.Settings; + +public class RequestLoggerSettings +{ + /// + /// Settings related to configuring blacklists + /// + public BlacklistSettings BlacklistSettings { get; set; } = new(); +} \ No newline at end of file diff --git a/src/RequestLogger/WeatherForecast.cs b/src/RequestLogger/WeatherForecast.cs deleted file mode 100644 index d347c2d..0000000 --- a/src/RequestLogger/WeatherForecast.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace RequestLogger; - -public class WeatherForecast -{ - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } -} diff --git a/src/RequestLogger/appsettings.Development.json b/src/RequestLogger/appsettings.Development.json index 0c208ae..974bff8 100644 --- a/src/RequestLogger/appsettings.Development.json +++ b/src/RequestLogger/appsettings.Development.json @@ -4,5 +4,12 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - } + }, + "RequestLogger" : { + + }, + "ConnectionStrings": { + "PostgreSQLConnection": "Server=127.0.0.1;Port=5452;Database=postgres;User Id=postgres;Password=rl_password;" + }, + "RunMigrations": false } diff --git a/src/RequestLogger/appsettings.Docker.json b/src/RequestLogger/appsettings.Docker.json new file mode 100644 index 0000000..0e5883a --- /dev/null +++ b/src/RequestLogger/appsettings.Docker.json @@ -0,0 +1,27 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "RequestLoggerSettings" : { + "BlacklistSettings" : { + "HeaderBlacklist": [ + "Blacklisted" + ], + "QueryParamBlacklist": [ + "blacklist" + ], + "EndpointBlacklist": [ + "/blacklist/test" + ], + "BodyStorageBlacklist": [ + "/blacklist/noBody" + ] + } + }, + "ConnectionStrings": { + }, + "RunMigrations": true +} diff --git a/src/nginx.conf b/src/nginx.conf deleted file mode 100644 index 800cf1c..0000000 --- a/src/nginx.conf +++ /dev/null @@ -1,32 +0,0 @@ -events { -} -http { - - error_log /var/log/nginx/error.log; - access_log /var/log/nginx/access.log; - - server { - server_name ""; - # Docker resolver - resolver 127.0.0.11; - listen 80; - - location = /favicon.ico { - access_log off; - log_not_found off; - } - - location / { - mirror /mirror; - mirror_request_body on; - proxy_pass http://mockserver:1080; - #return 200 'some response!'; - # add_header Content-Type text/plain; - } - - location /mirror { - internal; - proxy_pass http://requestlogger$request_uri; - } - } -} \ No newline at end of file