Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 14e2d3f

Browse files
Merge pull request #9 from foyzulkarim/poc/dockerize
Added docker compose for databases up and running
2 parents 25de3eb + f703fc4 commit 14e2d3f

File tree

8 files changed

+294
-23
lines changed

8 files changed

+294
-23
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,4 @@ dist
111111
/server/WebApplication2/WebApplication2/obj
112112
/server/WebApplication2/.vs/WebApplication2/v16
113113
/server/WebApplication2/WebApplication2/.config
114+
server/Server/.vs/Server/DesignTimeBuild/.dtbcache.v2

‎.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/server/AuthWebApplication/AuthWebApplication/bin/Debug/netcoreapp3.1/AuthWebApplication.dll",
13+
"program": "${workspaceFolder}/server/AuthWebApplication/AuthWebApplication/bin/Debug/net5.0/AuthWebApplication.dll",
1414
"args": [],
1515
"cwd": "${workspaceFolder}/server/AuthWebApplication/AuthWebApplication",
1616
"stopAtEntry": false,
@@ -32,7 +32,7 @@
3232
"request": "launch",
3333
"preLaunchTask": "build",
3434
// If you have changed target frameworks, make sure to update the program path.
35-
"program": "${workspaceFolder}/server/WebApplication2/WebApplication2/bin/Debug/netcoreapp3.1/WebApplication2.dll",
35+
"program": "${workspaceFolder}/server/WebApplication2/WebApplication2/bin/Debug/net5.0/WebApplication2.dll",
3636
"args": [],
3737
"cwd": "${workspaceFolder}/server/WebApplication2/WebApplication2",
3838
"stopAtEntry": false,

‎artifacts/docker/docker-compose.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: "3.8"
2+
services:
3+
mongo:
4+
image: mongo
5+
container_name: mongo
6+
ports:
7+
- "27017:27017"
8+
networks:
9+
- rbacnet
10+
volumes:
11+
- mongo_data:/data/db
12+
redis:
13+
image: "redis:alpine"
14+
container_name: redis
15+
command: redis-server --requirepass AwesomePassw0rd123
16+
ports:
17+
- "6379:6379"
18+
networks:
19+
- rbacnet
20+
volumes:
21+
- redis_data:/var/lib/redis
22+
mssql:
23+
image: "mcr.microsoft.com/mssql/server"
24+
container_name: mssql
25+
environment:
26+
SA_PASSWORD: "AwesomePassw0rd123"
27+
ACCEPT_EULA: "Y"
28+
ports:
29+
- "1433:1433"
30+
networks:
31+
- rbacnet
32+
volumes:
33+
- mssql_data
34+
networks:
35+
rbacnet:
36+
driver: bridge
37+
volumes:
38+
mongo_data:
39+
mssql_data:
40+
redis_data:

‎artifacts/scripts/resources.json

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
{
3+
"Id": "248a5b1e-f665-45a9-a862-bf7b46ac1c64",
4+
"Name": "link-permission-create",
5+
"IsPublic": "0",
6+
"ResourceType": 0
7+
},
8+
{
9+
"Id": "2d904481-fe93-46ba-ad2f-62c64c85555d",
10+
"Name": "/api/posts",
11+
"IsPublic": "0",
12+
"ResourceType": 1
13+
},
14+
{
15+
"Id": "3c3d88b1-eb6c-4a1a-b743-49c49ceb3f0c",
16+
"Name": "link-role-list",
17+
"IsPublic": "0",
18+
"ResourceType": 0
19+
},
20+
{
21+
"Id": "51b44c39-67f4-40bd-a9f2-260365ce096e",
22+
"Name": "link-post-create",
23+
"IsPublic": "0",
24+
"ResourceType": 0
25+
},
26+
{
27+
"Id": "52579306-0182-4b1c-b437-68c88903950b",
28+
"Name": "link-post-edit",
29+
"IsPublic": "0",
30+
"ResourceType": 0
31+
},
32+
{
33+
"Id": "6249ecae-9fb5-449c-a8a1-419882faaff5",
34+
"Name": "link-resource-create",
35+
"IsPublic": "0",
36+
"ResourceType": 0
37+
},
38+
{
39+
"Id": "62c675ae-d35a-4503-a5c0-2ea5232ab999",
40+
"Name": "link-resource-list",
41+
"IsPublic": "0",
42+
"ResourceType": 0
43+
},
44+
{
45+
"Id": "7d46e6d5-5d66-47f4-976f-7abbf1dc0a09",
46+
"Name": "link-role-create",
47+
"IsPublic": "0",
48+
"ResourceType": 0
49+
},
50+
{
51+
"Id": "9c9ed0e6-2546-42c4-8101-adb52e21174f",
52+
"Name": "link-posts",
53+
"IsPublic": "0",
54+
"ResourceType": 0
55+
},
56+
{
57+
"Id": "9f9c2b0d-7c80-486c-940d-e2974ce4f827",
58+
"Name": "link-post-delete",
59+
"IsPublic": "0",
60+
"ResourceType": 0
61+
},
62+
{
63+
"Id": "a294716d-ebf1-4bcf-8bfb-cbc00ce87c48",
64+
"Name": "link-user-create",
65+
"IsPublic": "0",
66+
"ResourceType": 0
67+
},
68+
{
69+
"Id": "a383da0d-c896-44d7-800a-2c100cf92910",
70+
"Name": "list-post-edit",
71+
"IsPublic": "0",
72+
"ResourceType": 0
73+
},
74+
{
75+
"Id": "a7072f00-b7ac-4e9e-a0fc-c9b308631c4d",
76+
"Name": "link-post-detail",
77+
"IsPublic": "0",
78+
"ResourceType": 0
79+
},
80+
{
81+
"Id": "aaa5922c-4aef-46cb-be8a-c672ae61fe08",
82+
"Name": "Foyzul Karim",
83+
"IsPublic": "0",
84+
"ResourceType": 0
85+
},
86+
{
87+
"Id": "cfa4a1a2-4f06-4d71-b6a6-46d063a861fd",
88+
"Name": "link-permission-list",
89+
"IsPublic": "0",
90+
"ResourceType": 0
91+
}
92+
]

‎server/AuthWebApplication/AuthWebApplication/Models/Db/DbInitializer.cs

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Threading.Tasks;
56
using Microsoft.AspNetCore.Identity;
67
using Microsoft.Extensions.Logging;
8+
using Newtonsoft.Json;
79

810
namespace AuthWebApplication.Models.Db
911
{
1012
public class DbInitializer
1113
{
1214
private const string SuperAdmin = "SuperAdmin";
1315

16+
public static void Initialize(SecurityDbContext context, UserManager<ApplicationUser> userManager,
17+
string password, ILogger<DbInitializer> dbInitializerLogger)
18+
{
19+
CreateRole(context, dbInitializerLogger, SuperAdmin);
20+
CreateDefaultUser(context, userManager, dbInitializerLogger, "Super Admin", "foyzulkarim@gmail.com",
21+
password, SuperAdmin).GetAwaiter()
22+
.GetResult();
23+
CreateResources(context, dbInitializerLogger);
24+
}
25+
1426
private static void CreateRole(SecurityDbContext context, ILogger<DbInitializer> logger, string role)
1527
{
1628
logger.LogInformation($"Create the role `{role}` for application");
17-
var any = context.ApplicationRoles.AsEnumerable().Any(x => string.Equals(x.Name, role, StringComparison.CurrentCultureIgnoreCase));
29+
var any = context.ApplicationRoles.AsEnumerable()
30+
.Any(x => string.Equals(x.Name, role, StringComparison.CurrentCultureIgnoreCase));
1831
if (!any)
1932
{
2033
var appRole = new ApplicationRole(role);
@@ -26,14 +39,17 @@ private static void CreateRole(SecurityDbContext context, ILogger<DbInitializer>
2639
}
2740
else
2841
{
29-
ApplicationException exception = new ApplicationException($"Default role `{role}` cannot be created");
42+
ApplicationException exception =
43+
new ApplicationException($"Default role `{role}` cannot be created");
3044
logger.LogError(exception, $"Exception occurred. {exception.Message}");
3145
throw exception;
3246
}
3347
}
3448
}
3549

36-
private static async Task<ApplicationUser> CreateDefaultUser(SecurityDbContext context, UserManager<ApplicationUser> userManager, ILogger<DbInitializer> logger, string displayName, string email, string password, string role)
50+
private static async Task<ApplicationUser> CreateDefaultUser(SecurityDbContext context,
51+
UserManager<ApplicationUser> userManager, ILogger<DbInitializer> logger, string displayName, string email,
52+
string password, string role)
3753
{
3854
logger.LogInformation($"Create default user with email `{email}` for application");
3955
ApplicationUser user = await userManager.FindByEmailAsync(email);
@@ -55,7 +71,8 @@ private static async Task<ApplicationUser> CreateDefaultUser(SecurityDbContext c
5571
}
5672
else
5773
{
58-
ApplicationException exception = new ApplicationException($"Default user `{email}` cannot be created");
74+
ApplicationException exception =
75+
new ApplicationException($"Default user `{email}` cannot be created");
5976
logger.LogError(exception, $"Exception occurred. {exception.Message}");
6077
throw exception;
6178
}
@@ -65,29 +82,54 @@ private static async Task<ApplicationUser> CreateDefaultUser(SecurityDbContext c
6582
return user;
6683
}
6784

68-
private static void AddRoleToApplicationUser(SecurityDbContext context, ILogger<DbInitializer> logger, ApplicationUser user, string role)
85+
private static void AddRoleToApplicationUser(SecurityDbContext context, ILogger<DbInitializer> logger,
86+
ApplicationUser user, string role)
6987
{
7088
var applicationRole = context.ApplicationRoles.First(x => x.Name == role);
71-
var userRole = context.ApplicationUserRoles.FirstOrDefault(x => x.UserId == user.Id && x.RoleId == applicationRole.Id);
89+
var userRole =
90+
context.ApplicationUserRoles.FirstOrDefault(x => x.UserId == user.Id && x.RoleId == applicationRole.Id);
7291
if (userRole == null)
7392
{
74-
ApplicationUserRole entity = new ApplicationUserRole() {RoleId = applicationRole.Id, UserId = user.Id};
93+
ApplicationUserRole entity = new ApplicationUserRole() {RoleId = applicationRole.Id, UserId = user.Id};
7594
context.ApplicationUserRoles.Add(entity);
7695
var saveChanges = context.SaveChanges();
7796
if (saveChanges == 0)
7897
{
79-
ApplicationException exception = new ApplicationException($"Adding role to user `{user.Email}` cannot be done");
98+
ApplicationException exception =
99+
new ApplicationException($"Adding role to user `{user.Email}` cannot be done");
80100
logger.LogError(exception, $"Exception occurred. {exception.Message}");
81101
throw exception;
82102
}
83103
}
84104
}
85-
86-
public static void Initialize(SecurityDbContext context, UserManager<ApplicationUser>userManager,stringpassword,ILogger<DbInitializer> dbInitializerLogger)
105+
106+
private static void CreateResources(SecurityDbContext context, ILogger<DbInitializer> logger)
87107
{
88-
CreateRole(context, dbInitializerLogger, SuperAdmin);
89-
CreateDefaultUser(context, userManager, dbInitializerLogger, "Super Admin", "foyzulkarim@gmail.com", password, SuperAdmin).GetAwaiter()
90-
.GetResult();
108+
var readAllText = File.ReadAllText("./Resources/resources.json");
109+
var resources = JsonConvert.DeserializeObject<List<ApplicationResource>>(readAllText);
110+
foreach (var resource in resources)
111+
{
112+
logger.LogInformation($"Create the resource `{resource.Name}` for application");
113+
var any = context.Resources.AsEnumerable()
114+
.Any(x => string.Equals(x.Name, resource.Name, StringComparison.CurrentCultureIgnoreCase));
115+
if (!any)
116+
{
117+
context.Resources.Add(resource);
118+
var i = context.SaveChanges();
119+
if (i > 0)
120+
{
121+
logger.LogDebug($"Created the resource `{resource.Name}` successfully");
122+
}
123+
else
124+
{
125+
ApplicationException exception =
126+
new ApplicationException($"Default resource `{resource.Name}` cannot be created");
127+
logger.LogError(exception, $"Exception occurred. {exception.Message}");
128+
throw exception;
129+
}
130+
}
131+
}
132+
91133
}
92134
}
93-
}
135+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
{
3+
"Id": "248a5b1e-f665-45a9-a862-bf7b46ac1c64",
4+
"Name": "link-permission-create",
5+
"IsPublic": "0",
6+
"ResourceType": 0
7+
},
8+
{
9+
"Id": "2d904481-fe93-46ba-ad2f-62c64c85555d",
10+
"Name": "/api/posts",
11+
"IsPublic": "0",
12+
"ResourceType": 1
13+
},
14+
{
15+
"Id": "3c3d88b1-eb6c-4a1a-b743-49c49ceb3f0c",
16+
"Name": "link-role-list",
17+
"IsPublic": "0",
18+
"ResourceType": 0
19+
},
20+
{
21+
"Id": "51b44c39-67f4-40bd-a9f2-260365ce096e",
22+
"Name": "link-post-create",
23+
"IsPublic": "0",
24+
"ResourceType": 0
25+
},
26+
{
27+
"Id": "52579306-0182-4b1c-b437-68c88903950b",
28+
"Name": "link-post-edit",
29+
"IsPublic": "0",
30+
"ResourceType": 0
31+
},
32+
{
33+
"Id": "6249ecae-9fb5-449c-a8a1-419882faaff5",
34+
"Name": "link-resource-create",
35+
"IsPublic": "0",
36+
"ResourceType": 0
37+
},
38+
{
39+
"Id": "62c675ae-d35a-4503-a5c0-2ea5232ab999",
40+
"Name": "link-resource-list",
41+
"IsPublic": "0",
42+
"ResourceType": 0
43+
},
44+
{
45+
"Id": "7d46e6d5-5d66-47f4-976f-7abbf1dc0a09",
46+
"Name": "link-role-create",
47+
"IsPublic": "0",
48+
"ResourceType": 0
49+
},
50+
{
51+
"Id": "9c9ed0e6-2546-42c4-8101-adb52e21174f",
52+
"Name": "link-posts",
53+
"IsPublic": "0",
54+
"ResourceType": 0
55+
},
56+
{
57+
"Id": "9f9c2b0d-7c80-486c-940d-e2974ce4f827",
58+
"Name": "link-post-delete",
59+
"IsPublic": "0",
60+
"ResourceType": 0
61+
},
62+
{
63+
"Id": "a294716d-ebf1-4bcf-8bfb-cbc00ce87c48",
64+
"Name": "link-user-create",
65+
"IsPublic": "0",
66+
"ResourceType": 0
67+
},
68+
{
69+
"Id": "a383da0d-c896-44d7-800a-2c100cf92910",
70+
"Name": "list-post-edit",
71+
"IsPublic": "0",
72+
"ResourceType": 0
73+
},
74+
{
75+
"Id": "a7072f00-b7ac-4e9e-a0fc-c9b308631c4d",
76+
"Name": "link-post-detail",
77+
"IsPublic": "0",
78+
"ResourceType": 0
79+
},
80+
{
81+
"Id": "aaa5922c-4aef-46cb-be8a-c672ae61fe08",
82+
"Name": "Foyzul Karim",
83+
"IsPublic": "0",
84+
"ResourceType": 0
85+
},
86+
{
87+
"Id": "cfa4a1a2-4f06-4d71-b6a6-46d063a861fd",
88+
"Name": "link-permission-list",
89+
"IsPublic": "0",
90+
"ResourceType": 0
91+
}
92+
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /