diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..347f3ca --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,48 @@ +name: SonarCloud +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build and analyze + runs-on: windows-latest + steps: + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: "zulu" # Alternative distribution options are available. + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~\sonar\cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache SonarCloud scanner + id: cache-sonar-scanner + uses: actions/cache@v3 + with: + path: .\.sonar\scanner + key: ${{ runner.os }}-sonar-scanner + restore-keys: ${{ runner.os }}-sonar-scanner + - name: Install SonarCloud scanner + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' + shell: powershell + run: | + New-Item -Path .\.sonar\scanner -ItemType Directory + dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + shell: powershell + run: | + .\.sonar\scanner\dotnet-sonarscanner begin /k:"csimonapastore_BasicDotnetTemplate" /o:"csimonapastore-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" + dotnet build + .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" diff --git a/.vscode/launch.json b/.vscode/launch.json index cb403d8..0c8f3a7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,7 +21,13 @@ "ASPNETCORE_URLS": "https://localhost:5000;https://localhost:5001", "ASPNETCORE_DETAILEDERRORS": "1", "ASPNETCORE_SHUTDOWNTIMEOUTSECONDS": "3" - } + }, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)", + "uriFormat": "%s/swagger" + }, }, { "name": ".NET Core Attach", diff --git a/Models/Settings/AppSettings.cs b/Models/Settings/AppSettings.cs new file mode 100644 index 0000000..c837bbd --- /dev/null +++ b/Models/Settings/AppSettings.cs @@ -0,0 +1,9 @@ +namespace BasicDotnetTemplate.Models.Settings; + +public class AppSettings +{ +#nullable enable + public Settings? Settings { get; set; } + public PrivateSettings? PrivateSettings { get; set; } +#nullable disable +} \ No newline at end of file diff --git a/Models/Settings/DatabaseConnection.cs b/Models/Settings/DatabaseConnection.cs new file mode 100644 index 0000000..6eb5789 --- /dev/null +++ b/Models/Settings/DatabaseConnection.cs @@ -0,0 +1,10 @@ +namespace BasicDotnetTemplate.Models.Settings; + +public class DatabaseConnection +{ +#nullable enable + public string? SqlServer { get; set; } + public string? Postgres { get; set; } + public string? Mongodb { get; set; } +#nullable disable +} \ No newline at end of file diff --git a/Models/Settings/PrivateSettings.cs b/Models/Settings/PrivateSettings.cs new file mode 100644 index 0000000..8e1fc9b --- /dev/null +++ b/Models/Settings/PrivateSettings.cs @@ -0,0 +1,8 @@ +namespace BasicDotnetTemplate.Models.Settings; + +public class PrivateSettings +{ +#nullable enable + public DatabaseConnection? DatabaseConnection { get; set; } +#nullable disable +} \ No newline at end of file diff --git a/NLog.config b/NLog.config new file mode 100644 index 0000000..75181c3 --- /dev/null +++ b/NLog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Program.cs b/Program.cs index 685bf5e..06066cd 100644 --- a/Program.cs +++ b/Program.cs @@ -18,7 +18,11 @@ internal class Program // REGISTER SERVICES HERE builder.Services.AddSingleton(_configuration); - builder.Services.Configure(_configuration.GetSection("Settings")); + PrivateSettings privateSettings = new PrivateSettings(); + _configuration.GetSection("PrivateSettings").Bind(privateSettings); + + builder.Services.Configure(_configuration.GetSection("AppSettings")); + builder.Services.Configure(_configuration.GetSection("PrivateSettings")); builder.Services.AddAuthentication(); builder.Services.AddAuthorization(); @@ -27,16 +31,17 @@ internal class Program builder.Services.AddEndpointsApiExplorer(); - Settings settings = new Settings(); - _configuration.GetSection("Settings").Bind(settings); + AppSettings appSettings = new AppSettings(); + appSettings.PrivateSettings = privateSettings; + _configuration.GetSection("AppSettings").Bind(appSettings); builder.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { - Version = settings.Version, - Title = settings.Name, - Description = settings.Description, + Version = appSettings?.Settings?.Version, + Title = appSettings?.Settings?.Name, + Description = appSettings?.Settings?.Description, TermsOfService = new Uri("https://example.com/terms"), Contact = new OpenApiContact { diff --git a/appsettings.json b/appsettings.json index fb4fb5b..69b888a 100644 --- a/appsettings.json +++ b/appsettings.json @@ -1,7 +1,11 @@ { - "Settings": { - "Name": "BasicDotnetTemplate", - "Version": "v1.0", - "Description": "This template contains basic configuration for a .Net 8 backend" + "AppSettings" : + { + "Settings": { + "Name": "BasicDotnetTemplate", + "Version": "v1.0", + "Description": "This template contains basic configuration for a .Net 8 backend" + } } + } \ No newline at end of file diff --git a/wwwroot/swagger-ui/custom.css b/wwwroot/swagger-ui/custom.css index 446b157..d9059fe 100644 --- a/wwwroot/swagger-ui/custom.css +++ b/wwwroot/swagger-ui/custom.css @@ -3,7 +3,7 @@ } .topbar-wrapper .link:after { - content: 'Unoffical McLaren F1 API'; + /* content: 'Unoffical McLaren F1 API'; */ /* color: #fff; */ visibility: visible; display: block;