Skip to content

Commit

Permalink
compose working, turned off all TLS for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
glennc committed Oct 24, 2019
1 parent 223a8db commit 9b93e4d
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 34 deletions.
6 changes: 4 additions & 2 deletions src/BlazingPizza.Orders/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS build
#gRPC requires extra compat stuff to run on Alpine
RUN apk --no-cache add ca-certificates wget
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk
RUN apk add glibc-2.30-r0.apk
#Some more pacakges to generate dev cert.
#RUN apk add --no-cache openssl
WORKDIR /src
COPY ["BlazingPizza.Orders/BlazingPizza.Orders.csproj", "BlazingPizza.Orders/"]
COPY ["BlazingPizza.Shared/BlazingPizza.Shared.csproj", "BlazingPizza.Shared/"]
Expand All @@ -20,6 +20,8 @@ RUN dotnet build "BlazingPizza.Orders.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "BlazingPizza.Orders.csproj" -c Release -o /app/publish
#RUN openssl req -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -x509 -days 365 -subj "/C=US/O=BlazingPizza/OU=Orders"
#RUN openssl pkcs12 -export -out /app/publish/orders.p12 -in cert.pem -inkey key.pem -password pass:cryptic -nomac

FROM base AS final
WORKDIR /app
Expand Down
4 changes: 3 additions & 1 deletion src/BlazingPizza.Orders/Model/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public class Order
public Address DeliveryAddress { get; set; } = new Address();

public LatLong DeliveryLocation { get; set; }

public List<Pizza> Pizzas { get; set; } = new List<Pizza>();

public string TotalPrice { get; internal set; }

public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice());

public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00");
Expand Down
23 changes: 4 additions & 19 deletions src/BlazingPizza.Orders/OrdersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public OrdersController(OrdersService db)
_db = db;
}

[HttpGet("{userId}")]
[HttpGet("user/{userId}")]
public async Task<ActionResult<List<OrderWithStatus>>> GetOrders(string userId)
{
var orders = await _db.GetOrdersForUser(userId);

return orders.Select(o => OrderWithStatus.FromOrder(o)).ToList();
}

[HttpGet("{orderId}/{userId}")]
public async Task<ActionResult<OrderWithStatus>> GetOrderWithStatus(Guid orderId, string userId)
[HttpGet("{orderId}")]
public async Task<ActionResult<OrderWithStatus>> GetOrderWithStatus(Guid orderId)
{
Order order = await _db.GetOrder(orderId);

Expand All @@ -47,22 +47,7 @@ public async Task<ActionResult<Guid>> PlaceOrder(Order order)
order.DeliveryLocation = new LatLong(51.5001, -0.1239);
//TODO: Should we let MongoDB do this?
order.OrderId = Guid.NewGuid();

// Enforce existence of Pizza.SpecialId and Topping.ToppingId
// in the database - prevent the submitter from making up
// new specials and toppings
foreach (var pizza in order.Pizzas)
{
pizza.SpecialId = pizza.Special.Id;
pizza.Special = pizza.Special;

foreach (var topping in pizza.Toppings)
{
topping.ToppingId = topping.Topping.Id;
topping.Topping = null;
}
}

order.TotalPrice = order.GetFormattedTotalPrice();
await _db.SaveOrder(order);
return order.OrderId;
}
Expand Down
6 changes: 6 additions & 0 deletions src/BlazingPizza.Orders/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -22,6 +24,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(options =>
{
options.Listen(IPAddress.Any, 5555, o => o.Protocols = HttpProtocols.Http2);
});
webBuilder.UseStartup<Startup>();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/BlazingPizza.Orders/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();
//app.UseHttpsRedirection();

app.UseRouting();
app.UseAuthorization();
Expand Down
2 changes: 2 additions & 0 deletions src/BlazingPizza.Web/HttpClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Text;
Expand All @@ -24,6 +25,7 @@ public static async Task<T> PostJsonAsync<T>(this HttpClient client, string uri,
{
var request = new HttpRequestMessage(HttpMethod.Post, uri)
{
Version = HttpVersion.Version20,
Content = new StringContent(JsonSerializer.Serialize(data, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }), Encoding.UTF8, "application/json")
};

Expand Down
4 changes: 2 additions & 2 deletions src/BlazingPizza.Web/Pages/Checkout.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page "/checkout"
@page "/checkout/{Id}"
@page "/checkout/{Id:guid}"

@using Microsoft.Extensions.Caching.Distributed
@using System.Text.Json
Expand Down Expand Up @@ -42,7 +42,7 @@
</div>

@code {
bool isSubmitting;
bool isSubmitting;
[CascadingParameter] Task<AuthenticationState> AuthenticationStateTask { get; set; }
[Parameter] public Guid? Id { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/BlazingPizza.Web/Pages/MyOrders.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
var authState = await AuthenticationStateTask;
var client = HttpClientFactory.CreateClient("orders");

return await client.GetJsonAsync<List<OrderWithStatus>>($"orders/{authState.User.Identity.Name}");
return await client.GetJsonAsync<List<OrderWithStatus>>($"orders/user/{authState.User.Identity.Name}");
}
}
2 changes: 1 addition & 1 deletion src/BlazingPizza.Web/Pages/OrderDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

invalidOrder = false;
var client = HttpClientFactory.CreateClient("orders");
orderWithStatus = await client.GetJsonAsync<OrderWithStatus>($"orders/{OrderId}/{authState.User.Identity.Name}");
orderWithStatus = await client.GetJsonAsync<OrderWithStatus>($"orders/{OrderId}");
}
catch (Exception)
{
Expand Down
7 changes: 6 additions & 1 deletion src/BlazingPizza.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.Cookies;
Expand Down Expand Up @@ -31,6 +33,8 @@ public Startup(IConfiguration configuration)
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

services.AddResponseCompression(options =>
{
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
Expand Down Expand Up @@ -68,6 +72,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddHttpClient("orders", client =>
{
client.BaseAddress = new Uri(Configuration["Services:Orders"]);
client.DefaultRequestVersion = HttpVersion.Version20;
});

services.AddHttpClient("auth", client =>
Expand All @@ -77,7 +82,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddGrpcClient<OrderStatusClient>(c =>
{
c.Address = new Uri("https://localhost:57203");
c.Address = new Uri(Configuration["Services:Orders"]);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/BlazingPizza.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"Services": {
"Menu": "http://localhost:57201",
"Orders": "https://localhost:57203",
"Orders": "http://localhost:5555",
"Auth": "http://localhost:64589"
},
"AllowedHosts": "*",
Expand Down
16 changes: 11 additions & 5 deletions src/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ services:
- frontend
- backend
ports:
- "5000:80"
- "64590:80"
environment:
#TODO: We need TLS.
- "Services:Orders=http://orders"
- "Services:Orders=http://orders:5555"
- "Services:Menu=http://menu"
- "Services.Auth=http://auth"
# - "Authentication:Twitter:ConsumerKey=U9DbAaVcDPYO3RVFlDo4w"
Expand All @@ -26,8 +25,15 @@ services:
networks:
- backend
expose:
- 80
- 443
- 5555
environment:
- "Data:Connection=mongodb://mongo:27017"
mongo:
image: mongo
networks:
- backend
expose:
- 27017
menu:
build:
context: .
Expand Down

0 comments on commit 9b93e4d

Please sign in to comment.