Skip to content

Commit

Permalink
Merge pull request #1 from bradygaster/dev
Browse files Browse the repository at this point in the history
merging to master
  • Loading branch information
bradygaster authored Apr 18, 2020
2 parents 570a662 + b9d6cfe commit 8d11a63
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 29 deletions.
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Start/COVIDScreeningApi/COVIDScreeningApi/bin/Debug/netcoreapp3.1/COVIDScreeningApi.dll",
"args": [],
"cwd": "${workspaceFolder}/Start/COVIDScreeningApi/COVIDScreeningApi",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Start/COVIDScreeningApi/COVIDScreeningApi/COVIDScreeningApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Start/COVIDScreeningApi/COVIDScreeningApi/COVIDScreeningApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/Start/COVIDScreeningApi/COVIDScreeningApi/COVIDScreeningApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>5abc7992-35e1-4186-8994-bb96c4a7d0a4</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<OpenApiDocumentName>ScreeningApiV1</OpenApiDocumentName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Extensions.Configuration.Secrets" Version="1.0.0-preview.1" />
<PackageReference Include="Azure.Identity" Version="1.1.1" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.6.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.3.2" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@

namespace COVIDScreeningApi.Controllers
{
[Route("api/[controller]")]
[Route("[controller]")]
[ApiController]
public class PortsOfEntryController : ControllerBase
{
// GET: api/<PortsOfEntryController>
[HttpGet]
public IEnumerable<PortsOfEntry> Get()
{
return new List<PortsOfEntry>();
return new List<PortsOfEntry>(new PortsOfEntry[]
{
new PortsOfEntry { ItemsLabels = "Peace Arch Border", ItemsLatitudes = 49.001453, ItemsLongitudes = -122.736694},
new PortsOfEntry { ItemsLabels = "Jefferson County International Airport", ItemsLatitudes = 48.108032, ItemsLongitudes = -122.774895},
new PortsOfEntry { ItemsLabels = "Fairfield International Airport", ItemsLatitudes = 48.116325, ItemsLongitudes = -123.493484},
new PortsOfEntry { ItemsLabels = "Grant County International Airport", ItemsLatitudes = 47.189873, ItemsLongitudes = -119.323608},
new PortsOfEntry { ItemsLabels = "Spokane International Airport", ItemsLatitudes = 47.625526, ItemsLongitudes = -117.536163},
new PortsOfEntry { ItemsLabels = "Seattle Airport", ItemsLatitudes = 47.443760, ItemsLongitudes = -122.302202},
});
}

// GET api/<PortsOfEntryController>/5
Expand All @@ -38,11 +46,5 @@ public void Post([FromBody] PortsOfEntry value)
public void Put(int id, [FromBody] PortsOfEntry value)
{
}

// DELETE api/<PortsOfEntryController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace COVIDScreeningApi.Controllers
{
[Route("api/[controller]")]
[Route("[controller]")]
[ApiController]
public class RepresentativeDataController : ControllerBase
{
Expand Down Expand Up @@ -38,11 +38,5 @@ public void Post([FromBody] RepresentativeData value)
public void Put(int id, [FromBody] RepresentativeData value)
{
}

// DELETE api/<RepresentativeDataController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace COVIDScreeningApi.Controllers
{
[Route("api/[controller]")]
[Route("[controller]")]
[ApiController]
public class ScreeningDataTableController : ControllerBase
{
Expand Down Expand Up @@ -38,11 +38,5 @@ public void Post([FromBody] ScreeningDataTable value)
public void Put(int id, [FromBody] ScreeningDataTable value)
{
}

// DELETE api/<ScreeningDataTableController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
87 changes: 87 additions & 0 deletions Start/COVIDScreeningApi/COVIDScreeningApi/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<Project>

<PropertyGroup>
<!-- variable to persist if the customer has custom tools already -->
<ToolManifestExists>false</ToolManifestExists>
<!--
The docs reflect "v1" so most customers getting started with
Swashbuckle use "v1" as their "document name" and their version.
Swashbuckle will soon update the middlware to stop requiring the
OpenApiInfo parameter, and will default the document name and version
to "v1."
Customers will *always* be able to change this, so if possible,
we should interrogate the Startup.cs file. A sample from a
Startup.cs is below, with the value we'd need to pass into
DefaultSwaggerDocName highlighted.
services.AddSwaggerGen(config =>
{
config.SwaggerDoc("v1", // THIS PARAMETER SHOULD BE USED AS THE DefaultSwaggerDocName VALUE
new OpenApiInfo
{
Title = "COVIDScreeningApi",
Version = "v1"
});
});
For now we've given them an escape hatch in the form of the OpenApiDocumentName
property. In this project, the OpenApiDocumentName is used in the .csproj file
to define the Open API doc's doc name. This way, a customer can change the value we
pass to the Swashbuckle CLI.
In the case where they don't do this, we have a target in this file that informs
the customer what to do.
-->
<DefaultSwaggerDocName>v1</DefaultSwaggerDocName>
<OpenApiDocumentName>v1</OpenApiDocumentName>
</PropertyGroup>

<!-- ascertain if the customer already has any custom tools -->
<Target Name="CheckForManifestFile" AfterTargets="Build">
<CreateProperty Value="true" Condition="Exists('.config/dotnet-tools.json')">
<Output TaskParameter="Value" PropertyName="ToolManifestExists"/>
</CreateProperty>
</Target>

<!-- adds the Swashbuckle CLI so we can use it to build the Swagger file -->
<Target Name="InstallSwashbuckleCli" AfterTargets="CheckForManifestFile">
<!-- create the tool manifest if it doesn't exist already -->
<Exec Command="dotnet new tool-manifest &gt; swagger-log.txt" Condition="!$(ToolManifestExists)"/>
<!-- install the tool into the project tool manifest -->
<Exec Command="dotnet tool install Swashbuckle.AspNetCore.Cli &gt;&gt; swagger-log.txt"/>
</Target>

<!-- creates the swagger file -->
<Target Name="CreateSwaggerFile"
AfterTargets="InstallSwashbuckleCli">
<!-- create the swagger file -->
<Exec Command="dotnet swagger tofile --output $(OutputPath)swagger.json $(OutputPath)/$(MSBuildProjectName).dll $(DefaultSwaggerDocName) &gt;&gt; swagger-log.txt"
Condition="'$(DefaultSwaggerDocName)' == '$(OpenApiDocumentName)'" />
<Exec Command="dotnet swagger tofile --output $(OutputPath)swagger.json $(OutputPath)/$(MSBuildProjectName).dll $(OpenApiDocumentName) &gt;&gt; swagger-log.txt"
Condition="'$(DefaultSwaggerDocName)' != '$(OpenApiDocumentName)'" />
<OnError ExecuteTargets="InformCustomerHowToOverrideSwaggerDocName"/>
</Target>

<!--
In the case that the customer isn't using "v1" as the Open API doc,
we need to tell them how to mitigate it.
-->
<Target Name="InformCustomerHowToOverrideSwaggerDocName">
<Message Importance="High"
Text="Tell the customers how to unbreak themselves here by setting the 'OpenApiDocumentName' property in their .csproj file to override the default."/>
<CallTarget Targets="CleanUpAfterSwaggerGeneration"/>
</Target>

<!-- cleanup the Swashbuckle CLI dependencies -->
<Target Name="CleanUpAfterSwaggerGeneration" AfterTargets="CreateSwaggerFile">
<!-- uninstall the Swashbuckle CLI, as it is no longer needed -->
<Exec Command="dotnet tool uninstall Swashbuckle.AspNetCore.Cli &gt;&gt; swagger-log.txt" />
<!-- delete the log file of our swagger-file-creation process -->
<Delete Files="swagger-log.txt" />
<!-- remove the tool manifest if we created it -->
<RemoveDir Directories=".config" Condition="!$(ToolManifestExists)"/>
</Target>

</Project>
8 changes: 8 additions & 0 deletions Start/COVIDScreeningApi/COVIDScreeningApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Azure.Identity;

namespace COVIDScreeningApi
{
Expand All @@ -18,6 +19,13 @@ public static void Main(string[] args)

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
config.AddAzureKeyVault(
keyVaultEndpoint,
new DefaultAzureCredential());
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"launchUrl": "swagger/v1/swagger.json",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"VaultUri": "https://covid-api-vault.vault.azure.net/",
"AZURE_USERNAME": "bradyg@microsoft.com"
}
},
"COVIDScreeningApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"launchUrl": "swagger/v1/swagger.json",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"VaultUri": "https://covid-api-vault.vault.azure.net/",
"AZURE_USERNAME": "bradyg@microsoft.com"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
Expand All @@ -31,7 +35,11 @@
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast",
"publishAllPorts": true,
"useSSL": true
"useSSL": true,
"environmentVariables": {
"VaultUri": "https://covid-api-vault.vault.azure.net/",
"AZURE_USERNAME": "bradyg@microsoft.com"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dependencies": {
"secrets1": {
"type": "secrets",
"connectionId": "VaultUri"
},
"cosmosdb1": {
"type": "cosmosdb",
"connectionId": "covid-screening-db"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dependencies": {
"secrets1": {
"resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroup')]/providers/Microsoft.KeyVault/vaults/covid-api-vault",
"type": "secrets.keyVault",
"connectionId": "VaultUri",
"secretStore": null
},
"cosmosdb1": {
"resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroup')]/providers/Microsoft.DocumentDB/databaseAccounts/covid-screening-data",
"type": "cosmosdb.azure",
"connectionId": "covid-screening-db",
"secretStore": "AzureKeyVault"
}
}
}
Loading

0 comments on commit 8d11a63

Please sign in to comment.