Skip to content

Commit f43ae5a

Browse files
author
Carlos Cañizares Estévez
committed
Added identity service
2 parents a0c51d0 + b345bd5 commit f43ae5a

158 files changed

Lines changed: 44730 additions & 36 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build-images.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@ dotnet publish $webPathToJson -o $webPathToPub
2222
$webSPAPathToJson = $scriptPath + "\src\Web\WebSPA\eShopOnContainers.WebSPA\project.json"
2323
Write-Host "webSPAPathToJson is $webSPAPathToJson" -ForegroundColor Yellow
2424
$webSPAPathToPub = $scriptPath + "\pub\webSPA"
25+
#$webSPAPathToNpmBat = $scriptPath + "\src\Web\WebSPA\eShopOnContainers.WebSPA\buildspa.bat"
2526
Write-Host "webSPAPathToPub is $webSPAPathToPub" -ForegroundColor Yellow
2627

2728
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
2829
dotnet restore $webSPAPathToJson
2930
dotnet build $webSPAPathToJson
31+
#Start-Process "cmd.exe" "/c " + $webSPAPathToNpmBat
3032
dotnet publish $webSPAPathToJson -o $webSPAPathToPub
3133

34+
# *** identitySvc image ***
35+
$identitySvcPathToJson = $scriptPath + "\src\Services\Identity\eShopOnContainers.Identity\project.json"
36+
Write-Host "identitySvcPathToJson is $identitySvcPathToJson" -ForegroundColor Yellow
37+
$identitySvcPathToPub = $scriptPath + "\pub\identity"
38+
Write-Host "identitySvcPathToPub is $identitySvcPathToPub" -ForegroundColor Yellow
39+
40+
Write-Host "Restore Dependencies just in case as it is needed to run dotnet publish" -ForegroundColor Blue
41+
dotnet restore $identitySvcPathToJson
42+
dotnet build $identitySvcPathToJson
43+
dotnet publish $identitySvcPathToJson -o $identitySvcPathToPub
44+
3245

3346
#*** Catalog service image ***
3447
$catalogPathToJson = $scriptPath + "\src\Services\Catalog\Catalog.API\project.json"
@@ -63,8 +76,10 @@ dotnet restore $basketPathToJson
6376
dotnet build $basketPathToJson
6477
dotnet publish $basketPathToJson -o $basketPathToPub
6578

79+
#*** build docker images ***
6680
docker build -t eshop/web $webPathToPub
6781
docker build -t eshop/catalog.api $catalogPathToPub
6882
docker build -t eshop/ordering.api $orderingPathToPub
6983
docker build -t eshop/basket.api $basketPathToPub
7084
docker build -t eshop/webspa $webSPAPathToPub
85+
docker build -t eshop/identity $identitySvcPathToPub

docker-compose.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ services:
99
environment:
1010
- CatalogUrl=http://catalog.api
1111
- OrderingUrl=http://ordering.api
12+
- IdentityUrl=http://identity.service
13+
- BasketUrl=http://basket.api
1214
ports:
1315
- "5100:80"
1416
depends_on:
1517
- catalog.api
16-
- identity.data
18+
- identity.service
1719
- basket.api
1820

1921
webspa:
@@ -24,12 +26,14 @@ services:
2426
environment:
2527
- CatalogUrl=http://catalog.api
2628
- OrderingUrl=http://ordering.api
29+
- IdentityUrl=http://identity.service
30+
- BasketUrl=http://basket.api
2731
ports:
2832
- "5104:80"
2933
depends_on:
3034
- catalog.api
31-
- identity.data
3235
- basket.api
36+
- identity.service
3337

3438
catalog.api:
3539
image: eshop/catalog.api
@@ -56,10 +60,6 @@ services:
5660
- ConnectionString=Server=ordering.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
5761
ports:
5862
- "5102:80"
59-
# (Go to Production): For secured/final deployment, remove Ports mapping and
60-
# leave just the internal expose section
61-
# expose:
62-
# - "80"
6363
extra_hosts:
6464
- "CESARDLBOOKVHD:10.0.75.1"
6565
depends_on:
@@ -70,6 +70,17 @@ services:
7070
ports:
7171
- "5432:1433"
7272

73+
identity.service:
74+
image: eshop/identity
75+
environment:
76+
- Spa:http://webspa
77+
expose:
78+
- "80"
79+
ports:
80+
- "5105:80"
81+
depends_on:
82+
- identity.data
83+
7384
identity.data:
7485
image: microsoft/mssql-server-linux
7586
environment:
@@ -89,6 +100,7 @@ services:
89100
- "5103:80"
90101
depends_on:
91102
- basket.data
103+
- identity.service
92104

93105
basket.data:
94106
image: redis

src/Services/Basket/Basket.API/Controllers/BasketController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ public async Task<IActionResult> Get(string id)
3131

3232
// POST api/values
3333
[HttpPost]
34-
public void Post([FromBody]CustomerBasket value)
34+
public async Task<IActionResult> Post([FromBody]CustomerBasket value)
3535
{
36-
_repository.UpdateBasket(value);
36+
var basket = await _repository.UpdateBasket(value);
37+
38+
return Ok(basket);
3739
}
3840

3941
// DELETE api/values/5

src/Services/Basket/Basket.API/Model/IBasketRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
88
public interface IBasketRepository
99
{
1010
Task<CustomerBasket> GetBasket(string customerId);
11-
Task<bool> UpdateBasket(CustomerBasket basket);
11+
Task<CustomerBasket> UpdateBasket(CustomerBasket basket);
1212
Task<bool> DeleteBasket(string id);
1313
}
1414
}

src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,19 @@ public async Task<CustomerBasket> GetBasket(string customerId)
4444
return JsonConvert.DeserializeObject<CustomerBasket>(data);
4545
}
4646

47-
public async Task<bool> UpdateBasket(CustomerBasket basket)
47+
public async Task<CustomerBasket> UpdateBasket(CustomerBasket basket)
4848
{
4949
var database = await GetDatabase();
50-
return await database.StringSetAsync(basket.BuyerId, JsonConvert.SerializeObject(basket));
50+
51+
var created = await database.StringSetAsync(basket.BuyerId, JsonConvert.SerializeObject(basket));
52+
if (!created)
53+
{
54+
_logger.LogInformation("Problem persisting the item");
55+
return null;
56+
}
57+
58+
_logger.LogInformation("basket item persisted succesfully");
59+
return await GetBasket(basket.BuyerId);
5160
}
5261

5362
private async Task<IDatabase> GetDatabase()
@@ -64,3 +73,4 @@ private async Task<IDatabase> GetDatabase()
6473
}
6574
}
6675
}
76+

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
5656
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
5757
loggerFactory.AddDebug();
5858

59+
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
60+
{
61+
Authority = Configuration.GetValue("IdentityUrl", "http://localhost:5000"),
62+
ScopeName = "basket",
63+
RequireHttpsMetadata = false
64+
});
65+
5966
app.UseMvc();
6067
}
6168
}

src/Services/Basket/Basket.API/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"Microsoft": "Information"
88
}
99
},
10+
"identityUrl": "http://localhost:5105",
1011
"ConnectionString": "127.0.0.1"
1112
}

src/Services/Basket/Basket.API/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,20 @@ services:
1515

1616
basket.data:
1717
image: redis
18+
19+
identity.service:
20+
image: eshop/identity
21+
expose:
22+
- "80"
23+
ports:
24+
- "5105:80"
25+
depends_on:
26+
- identity.data
27+
28+
identity.data:
29+
image: microsoft/mssql-server-linux
30+
environment:
31+
- SA_PASSWORD=Pass@word
32+
- ACCEPT_EULA=Y
33+
ports:
34+
- "5433:1433"

src/Services/Basket/Basket.API/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"Microsoft.Extensions.Logging.Debug": "1.0.0",
1717
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
1818
"StackExchange.Redis": "1.1.608",
19-
"Newtonsoft.Json": "9.0.1"
19+
"Newtonsoft.Json": "9.0.1",
20+
"IdentityServer4.AccessTokenValidation": "1.0.1-rc3"
2021
},
2122
"tools": {
2223
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "wwwroot/lib"
3+
}

0 commit comments

Comments
 (0)