Skip to content

Commit 6de80bc

Browse files
authored
Merge pull request #23 from THC-Software/kubernetes
Kubernetes
2 parents fa4f9ba + 5bd6fbb commit 6de80bc

14 files changed

+363
-65
lines changed

Application/Controllers/PlayOfferController.cs

+10-19
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public PlayOfferController(IMediator mediator)
2828
/// <response code="200">Returns a list of Play offers matching the query params</response>
2929
/// <response code="204">No Play offer with matching properties was found</response>
3030
[HttpGet]
31-
[Authorize]
31+
[Authorize(Roles = "MEMBER,ADMIN")]
3232
[Route("club")]
3333
[ProducesResponseType(typeof(IEnumerable<PlayOfferDto>), StatusCodes.Status200OK)]
3434
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status204NoContent)]
@@ -52,15 +52,15 @@ public async Task<ActionResult<IEnumerable<PlayOfferDto>>> GetByClubIdAsync()
5252
///<response code="200">Returns a list of Play offers matching the query params</response>
5353
///<response code="204">No Play offer with matching properties was found</response>
5454
[HttpGet]
55-
[Authorize]
55+
[Authorize(Roles = "MEMBER,ADMIN")]
5656
[Route("participant")]
5757
[ProducesResponseType(typeof(IEnumerable<PlayOffer>), StatusCodes.Status200OK)]
5858
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status204NoContent)]
5959
[Consumes("application/json")]
6060
[Produces("application/json")]
6161
public async Task<ActionResult<IEnumerable<PlayOfferDto>>> GetByParticipantIdAsync()
6262
{
63-
var participantId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
63+
var participantId = Guid.Parse(User.FindFirst("sub")!.Value);
6464
var result = await _mediator.Send(new GetPlayOffersByParticipantIdQuery(participantId));
6565

6666
if (result.Count() == 0)
@@ -77,7 +77,7 @@ public async Task<ActionResult<IEnumerable<PlayOfferDto>>> GetByParticipantIdAsy
7777
///<response code="200">Returns a List of Play offers with creator matching the query params</response>
7878
///<response code="204">No Play offers with matching creator was found</response>
7979
[HttpGet]
80-
[Authorize]
80+
[Authorize(Roles = "MEMBER,ADMIN")]
8181
[Route("search")]
8282
[ProducesResponseType(typeof(IEnumerable<PlayOffer>), StatusCodes.Status200OK)]
8383
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status204NoContent)]
@@ -112,17 +112,14 @@ public async Task<ActionResult<IEnumerable<PlayOfferDto>>> GetByCreatorNameAsync
112112
///<response code="400">Invalid Play Offer structure</response>
113113
///<response code="401">Only members can create Play Offers</response>
114114
[HttpPost]
115-
[Authorize]
115+
[Authorize(Roles = "MEMBER")]
116116
[ProducesResponseType(typeof(PlayOffer), StatusCodes.Status201Created)]
117117
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status400BadRequest)]
118118
[Consumes("application/json")]
119119
[Produces("application/json")]
120120
public async Task<ActionResult<PlayOffer>> Create(CreatePlayOfferDto createPlayOfferDto)
121121
{
122-
if (User.Claims.First(c => c.Type == "groups").Value != "MEMBER")
123-
return Unauthorized("Only members can create Play Offers!");
124-
125-
var creatorId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier)!.Value);
122+
var creatorId = Guid.Parse(User.FindFirst("sub")!.Value);
126123
var clubId = Guid.Parse(User.FindFirst("tennisClubId")!.Value);
127124

128125
Guid result;
@@ -147,17 +144,14 @@ public async Task<ActionResult<PlayOffer>> Create(CreatePlayOfferDto createPlayO
147144
///<response code="400">No Play Offer with matching id found</response>
148145
///<response code="401">Only creator can cancel Play Offers</response>
149146
[HttpDelete]
150-
[Authorize]
147+
[Authorize(Roles = "MEMBER")]
151148
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status200OK)]
152149
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status400BadRequest)]
153150
[Consumes("application/json")]
154151
[Produces("application/json")]
155152
public async Task<ActionResult> Delete(Guid playOfferId)
156153
{
157-
if (User.Claims.First(c => c.Type == "groups").Value != "MEMBER")
158-
return Unauthorized("Only members can cancel Play Offers!");
159-
160-
var memberId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier)!.Value);
154+
var memberId = Guid.Parse(User.FindFirst("sub")!.Value);
161155

162156
try
163157
{
@@ -184,18 +178,15 @@ public async Task<ActionResult> Delete(Guid playOfferId)
184178
///<response code="400">No playOffer with a matching playOfferId found</response>
185179
///<response code="401">Only members can join Play Offers</response>
186180
[HttpPost]
187-
[Authorize]
181+
[Authorize(Roles = "MEMBER")]
188182
[Route("join")]
189183
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status200OK)]
190184
[ProducesResponseType(typeof(ActionResult), StatusCodes.Status400BadRequest)]
191185
[Consumes("application/json")]
192186
[Produces("application/json")]
193187
public async Task<ActionResult> Join(JoinPlayOfferDto joinPlayOfferDto)
194188
{
195-
if (User.Claims.First(c => c.Type == "groups").Value != "MEMBER")
196-
return Unauthorized("Only members can join Play Offers!");
197-
198-
var memberId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier)!.Value);
189+
var memberId = Guid.Parse(User.FindFirst("sub")!.Value);
199190
try
200191
{
201192
await _mediator.Send(new JoinPlayOfferCommand(joinPlayOfferDto, memberId));

BasicAuthenticationHandler.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Security.Claims;
2+
using System.Text.Encodings.Web;
3+
using Microsoft.AspNetCore.Authentication;
4+
using Microsoft.Extensions.Options;
5+
6+
namespace PlayOfferService;
7+
8+
public class BasicAuthenticationHandler(
9+
IOptionsMonitor<AuthenticationSchemeOptions> options,
10+
ILoggerFactory logger,
11+
UrlEncoder encoder,
12+
ISystemClock clock)
13+
: AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder, clock)
14+
{
15+
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
16+
{
17+
var claims = new[] { new Claim(ClaimTypes.Name, "DummyUser") };
18+
var identity = new ClaimsIdentity(claims, Scheme.Name);
19+
var principal = new ClaimsPrincipal(identity);
20+
var ticket = new AuthenticationTicket(principal, Scheme.Name);
21+
22+
return Task.FromResult(AuthenticateResult.Success(ticket));
23+
}
24+
}

Deployment/pos-debezium.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: pos-debezium
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: pos-debezium
10+
template:
11+
metadata:
12+
labels:
13+
app: pos-debezium
14+
spec:
15+
containers:
16+
- name: pos-debezium
17+
image: debezium/server
18+
ports:
19+
- containerPort: 8080
20+
volumeMounts:
21+
- name: debezium-configmap
22+
mountPath: /debezium/conf
23+
imagePullPolicy: IfNotPresent
24+
volumes:
25+
- name: debezium-configmap
26+
configMap:
27+
name: debezium-configmap
28+
restartPolicy: Always
29+
---
30+
apiVersion: v1
31+
kind: Service
32+
metadata:
33+
name: pos-debezium
34+
spec:
35+
selector:
36+
app: pos-debezium
37+
ports:
38+
- protocol: TCP
39+
port: 8080
40+
targetPort: 8080
41+
---
42+
apiVersion: v1
43+
kind: ConfigMap
44+
metadata:
45+
name: debezium-configmap
46+
data:
47+
application.properties: |
48+
# source config (postgres)
49+
debezium.source.connector.class=io.debezium.connector.postgresql.PostgresConnector
50+
debezium.source.offset.storage.file.filename=data/offsets.dat
51+
debezium.source.offset.flush.interval.ms=0
52+
debezium.source.database.hostname=pos-postgres-write
53+
debezium.source.database.port=5432
54+
debezium.source.database.user=pos_user
55+
debezium.source.database.password=pos_password
56+
debezium.source.database.dbname=pos_write_db
57+
debezium.source.plugin.name=pgoutput
58+
debezium.source.topic.prefix=pos
59+
debezium.source.schema.include.list=public
60+
61+
# sink config (redis)
62+
debezium.sink.type=redis
63+
debezium.sink.redis.address=redis:6379
64+
#debezium.sink.redis.user=WE HAVE NO USER CONFIGURED SO WE COMMENT THIS
65+
#debezium.sink.redis.password=WE HAVE NO PASSWORD CONFIGURED SO WE COMMENT THIS
66+
67+
# disable logging in json, so we are actually able to read something
68+
quarkus.log.console.json=false

Deployment/pos-postgres-read.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: pos-postgres-read
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: pos-postgres-read
10+
template:
11+
metadata:
12+
labels:
13+
app: pos-postgres-read
14+
spec:
15+
containers:
16+
- name: pos-postgres-read
17+
image: debezium/postgres:16-alpine
18+
env:
19+
- name: POSTGRES_USER
20+
value: pos_user
21+
- name: POSTGRES_PASSWORD
22+
value: pos_password
23+
- name: POSTGRES_DB
24+
value: pos_read_db
25+
ports:
26+
- containerPort: 5432
27+
imagePullPolicy: IfNotPresent
28+
restartPolicy: Always
29+
---
30+
apiVersion: v1
31+
kind: Service
32+
metadata:
33+
name: pos-postgres-read
34+
spec:
35+
selector:
36+
app: pos-postgres-read
37+
ports:
38+
- protocol: TCP
39+
port: 5432
40+
targetPort: 5432

Deployment/pos-postgres-write.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: pos-postgres-write
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: pos-postgres-write
10+
template:
11+
metadata:
12+
labels:
13+
app: pos-postgres-write
14+
spec:
15+
containers:
16+
- name: pos-postgres-write
17+
image: debezium/postgres:16-alpine
18+
env:
19+
- name: POSTGRES_USER
20+
value: pos_user
21+
- name: POSTGRES_PASSWORD
22+
value: pos_password
23+
- name: POSTGRES_DB
24+
value: pos_write_db
25+
ports:
26+
- containerPort: 5432
27+
imagePullPolicy: IfNotPresent
28+
restartPolicy: Always
29+
---
30+
apiVersion: v1
31+
kind: Service
32+
metadata:
33+
name: pos-postgres-write
34+
spec:
35+
selector:
36+
app: pos-postgres-write
37+
ports:
38+
- protocol: TCP
39+
port: 5432
40+
targetPort: 5432

Deployment/pos-service.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: pos-service
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: pos-service
10+
template:
11+
metadata:
12+
labels:
13+
app: pos-service
14+
spec:
15+
containers:
16+
- name: pos-service
17+
image: lolgame99/webarch_playofferservice
18+
ports:
19+
- containerPort: 8080
20+
name: http
21+
- containerPort: 8081
22+
name: https
23+
imagePullPolicy: Always
24+
restartPolicy: Always
25+
---
26+
apiVersion: v1
27+
kind: Service
28+
metadata:
29+
name: pos-service
30+
spec:
31+
selector:
32+
app: pos-service
33+
ports:
34+
- protocol: TCP
35+
port: 8080
36+
targetPort: 8080
37+
name: http
38+
- protocol: TCP
39+
port: 8082
40+
targetPort: 8081
41+
name: https

Deployment/redis.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: redis
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: redis
10+
template:
11+
metadata:
12+
labels:
13+
app: redis
14+
spec:
15+
containers:
16+
- name: redis
17+
image: redis:7.0-alpine
18+
imagePullPolicy: IfNotPresent
19+
ports:
20+
- containerPort: 6379
21+
restartPolicy: Always
22+
---
23+
apiVersion: v1
24+
kind: Service
25+
metadata:
26+
name: redis
27+
spec:
28+
selector:
29+
app: redis
30+
ports:
31+
- protocol: TCP
32+
port: 6379
33+
targetPort: 6379

Domain/DbReadContext.cs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2424
modelBuilder.ApplyConfiguration(new BaseEventConfiguration());
2525

2626
// TODO: Remove before coop testing
27+
/*
2728
var testClub = new Club { Id = Guid.Parse("1fc64a89-9e63-4e9f-96f7-e2120f0ca6c3"), Name = "Test Club", Status = Status.ACTIVE };
2829
var testMemberIds = new List<Guid> { Guid.Parse("0033506d-2d59-40d3-b996-74a251091027"), Guid.Parse("ccc1c8fc-89b5-4026-b190-9d9e7e7bc18d") };
2930
@@ -49,5 +50,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4950
modelBuilder.Entity<Member>().HasData(testMember);
5051
}
5152
modelBuilder.Entity<PlayOffer>().HasData(testPlayOffer);
53+
*/
5254
}
5355
}

0 commit comments

Comments
 (0)