Skip to content

Commit 788744f

Browse files
authored
Merge pull request #618 from bcgov/yj
Yj
2 parents 6491a47 + f9f8792 commit 788744f

File tree

11 files changed

+252
-6
lines changed

11 files changed

+252
-6
lines changed

crunchydb/charts/crunchy-postgres/values.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fullnameOverride: strdss-db
22

33
# crunchyImage: # it's not necessary to specify an image as the images specified in the Crunchy Postgres Operator will be pulled by default
4-
crunchyImage: artifacts.developer.gov.bc.ca/bcgov-docker-local/crunchy-postgres-gis:ubi8-15.2-3.3-0 # use this image for POSTGIS
4+
crunchyImage: artifacts.developer.gov.bc.ca/bcgov-docker-local/crunchy-postgres-gis:ubi8-15.6-3.3-0 # use this image for POSTGIS
55
postgresVersion: 15
66
postGISVersion: '3.3' # use this version of POSTGIS. both crunchyImage and this property needs to have valid values for POSTGIS to be enabled.
77
imagePullPolicy: IfNotPresent
@@ -36,7 +36,6 @@ pgBackRest:
3636
repos:
3737
schedules:
3838
full: 0 8 * * *
39-
incremental: 0 0,4,12,16,20 * * *
4039
volume:
4140
accessModes: "ReadWriteOnce"
4241
storage: 64Mi

crunchydb/values-prod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ crunchy-postgres:
44
name: ha # high availability
55
replicas: 2
66
dataVolumeClaimSpec:
7-
storage: 20Gi
7+
storage: 25Gi
88
storageClassName: netapp-block-standard
99
requests:
1010
cpu: 20m

gateway/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# KONG API Service Portal Setup
2+
3+
The public API is accessible at
4+
5+
* DEV: https://dev.strdata.api.gov.bc.ca
6+
* UAT: https://test.strdata.api.gov.bc.ca
7+
* PROD: https://strdata.api.gov.bc.ca
8+
9+
API access is controlled via Kong, administered via the BC Gov API Programme Services API Gateway.
10+
**Kong configuration is not updated via Github Actions, and must be updated manually when there are changes.**
11+
12+
For an overview of the API Gateway update process, see:
13+
https://bcgov.github.io/aps-infra-platform/guides/owner-journey-v1/
14+
15+
16+
## Publication
17+
18+
### Prerequisites
19+
1. In the API Services Portal (https://api.gov.bc.ca/), the namespace strdata has already been created.
20+
2. In the namespace, authorization profile has been created as follows:
21+
* Flow: Client Credential Flow, using Client ID and Secret
22+
* Mode: Automatic
23+
* Client Mappers (Audience): gateway-awp
24+
25+
26+
### Publication
27+
28+
29+
1. Log into https://api.gov.bc.ca/
30+
2. Select the strdata namespace
31+
3. Create a service account with `GatewayConfig.Publish` scope and note down the client id and client secret
32+
4. Download the GWA CLI from https://github.com/bcgov/gwa-cli/releases
33+
5. In command prompt run the following commands (the first command create a .env file locally, which will need to be deleted if you need to create one for the other environment):
34+
35+
```sh
36+
gwa config set host api.gov.bc.ca
37+
gwa config set --namespace strdata
38+
39+
export SCID="<<client id>>"
40+
export SCSC="<<client secret>>"
41+
export SURL="https://authz.apps.gov.bc.ca/auth/realms/aps/protocol/openid-connect/token"
42+
43+
gwa login --client-id $SCID --client-secret $SCSC
44+
gwa pg strdata-{env}.yaml
45+
```
46+
5. (optional for Windows GWA) In command prompt of Windows run the following commands (the first command create a .env file locally, which will need to be deleted if you need to create one for the other environment):
47+
48+
```sh
49+
gwa config set host api.gov.bc.ca
50+
gwa config set --namespace strdata
51+
gwa login --client-id "<<client id>>" --client-secret "<<client secret>>"
52+
gwa pg strdata-{env}.yaml
53+
```
54+
6. Check the Gateway in the API Service Portal to make sure that the routes have been published
55+
7. Create a dataset if it doesn't exist.
56+
57+
https://bcgov.github.io/aps-infra-platform/guides/owner-journey-v1/#91-setup-your-draft-dataset
58+
59+
```
60+
{
61+
"name": "strdata-dataset",
62+
"license_title": "Open Government Licence - British Columbia",
63+
"security_class": "PUBLIC",
64+
"view_audience": "Public",
65+
"download_audience": "Public",
66+
"record_publish_date": "2024-09-11",
67+
"notes": "Short-Term Rental Data API Services",
68+
"title": "Short-Term Rental Data API Services",
69+
"tags": [
70+
"openapi",
71+
"standards"
72+
],
73+
"organization": "ministry-of-housing",
74+
"organizationUnit": "planning-and-land-use-management"
75+
}
76+
```
77+
78+
8. Create a product if it doesn't exist.
79+
80+
### Consumer Request & Approval
81+

gateway/strdata-dev.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
services:
2+
- name: strdata
3+
host: strdss-dev-backend.b0471a-dev.svc
4+
tags: [ns.strdata]
5+
port: 8080
6+
protocol: http
7+
retries: 0
8+
routes:
9+
- name: strdata
10+
tags: [ns.strdata]
11+
hosts:
12+
- dev.strdata.api.gov.bc.ca
13+
methods:
14+
- GET
15+
paths: [/api/organizations/types]
16+
strip_path: false
17+
https_redirect_status_code: 426
18+
path_handling: v0
19+
request_buffering: true
20+
response_buffering: true
21+
plugins:
22+
- name: jwt-keycloak
23+
tags: [ns.strdata]
24+
enabled: true
25+
config:
26+
allowed_iss: [https://loginproxy.gov.bc.ca/auth/realms/apigw, https://dev.loginproxy.gov.bc.ca/auth/realms/apigw, https://test.loginproxy.gov.bc.ca/auth/realms/apigw]
27+
allowed_aud: gateway-strdata
28+
run_on_preflight: true
29+
iss_key_grace_period: 10
30+
maximum_expiration: 0
31+
algorithm: RS256
32+
claims_to_verify:
33+
- exp
34+
uri_param_names:
35+
- jwt
36+
cookie_names: []
37+
scope:
38+
roles:
39+
realm_roles:
40+
client_roles:
41+
anonymous:
42+
consumer_match: true
43+
consumer_match_claim: azp
44+
consumer_match_claim_custom_id: true
45+
consumer_match_ignore_not_found: false
46+
- name: request-transformer
47+
tags: [ns.strdata]
48+
enabled: true
49+
config:
50+
http_method:
51+
- name: kong-upstream-jwt
52+
enabled: true
53+
tags: [ns.strdata]
54+
config:
55+
header: GW-JWT
56+
include_credential_type: false

server/StrDss.Api/Controllers/UsersController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,19 @@ public async Task<ActionResult> GetBceidUserInfo()
150150
var userinfo = await _userService.GetBceidUserInfo();
151151
return Ok(userinfo);
152152
}
153+
154+
[ApiAuthorize(Permissions.UserWrite)]
155+
[HttpPost("aps", Name = "CreateApsUser")]
156+
public async Task<ActionResult> CreateApsUser(ApsUserCreateDto dto)
157+
{
158+
var errors = await _userService.CreateApsUserAsync(dto);
159+
160+
if (errors.Count > 0)
161+
{
162+
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
163+
}
164+
165+
return Ok();
166+
}
153167
}
154168
}

server/StrDss.Data/Mappings/ModelToEntityProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class ModelToEntityProfile : Profile
1111
public ModelToEntityProfile()
1212
{
1313
CreateMap<UserCreateDto, DssUserIdentity>();
14+
CreateMap<ApsUserCreateDto, DssUserIdentity>();
1415
CreateMap<UserDto, DssUserIdentity>();
1516
CreateMap<UserUpdateDto, DssUserIdentity>();
1617
CreateMap<AccessRequestDenyDto, DssUserIdentity>();

server/StrDss.Data/Repositories/UserRepository.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public interface IUserRepository
2424
Task<List<DropdownStrDto>> GetAccessRequestStatuses();
2525
Task AcceptTermsConditions();
2626
Task UpdateUserNamesAsync(long userId, string firstName, string lastName);
27+
Task CreateApsUserAsync(ApsUserCreateDto dto);
2728
}
2829
public class UserRepository : RepositoryBase<DssUserIdentity>, IUserRepository
2930
{
@@ -207,5 +208,20 @@ public async Task UpdateUserNamesAsync(long userId, string firstName, string las
207208
entity.FamilyNm = lastName;
208209
entity.GivenNm = firstName;
209210
}
211+
212+
public async Task CreateApsUserAsync(ApsUserCreateDto dto)
213+
{
214+
var userEntity = _mapper.Map<DssUserIdentity>(dto);
215+
216+
var roleCds = dto.RoleCds.Distinct();
217+
218+
foreach (var roleCd in roleCds)
219+
{
220+
userEntity.DssUserRoleAssignments
221+
.Add(new DssUserRoleAssignment { UserRoleCd = roleCd });
222+
}
223+
224+
await _dbContext.AddAsync(userEntity);
225+
}
210226
}
211227
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace StrDss.Model.UserDtos
4+
{
5+
public class ApsUserCreateDto : IOrgRoles
6+
{
7+
[JsonIgnore]
8+
public Guid UserGuid { get; set; }
9+
10+
public string DisplayNm { get; set; } = "";
11+
12+
[JsonIgnore]
13+
public string IdentityProviderNm { get; set; } = "aps";
14+
15+
public bool IsEnabled { get; set; } = true;
16+
17+
[JsonIgnore]
18+
public string AccessRequestStatusCd { get; set; } = "Approved";
19+
20+
[JsonIgnore]
21+
public DateTime? AccessRequestDtm { get; set; } = DateTime.UtcNow;
22+
23+
[JsonIgnore]
24+
public string? AccessRequestJustificationTxt { get; set; } = "";
25+
26+
[JsonIgnore]
27+
public string? GivenNm { get; set; } = "";
28+
29+
[JsonIgnore]
30+
public string? FamilyNm { get; set; } = "";
31+
32+
[JsonIgnore]
33+
public string? EmailAddressDsc { get; set; } = "";
34+
35+
[JsonIgnore]
36+
public string? BusinessNm { get; set; } = "";
37+
38+
[JsonIgnore]
39+
public DateTime? TermsAcceptanceDtm { get; set; } = DateTime.UtcNow;
40+
41+
public long RepresentedByOrganizationId { get; set; }
42+
43+
public List<string> RoleCds { get; set; } = new List<string>();
44+
}
45+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace StrDss.Model.UserDtos
2+
{
3+
public interface IOrgRoles
4+
{
5+
public long RepresentedByOrganizationId { get; set; }
6+
public List<string> RoleCds { get; set; }
7+
}
8+
}

server/StrDss.Model/UserDtos/UserUpdateDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace StrDss.Model.UserDtos
22
{
3-
public class UserUpdateDto
3+
public class UserUpdateDto : IOrgRoles
44
{
55
public long UserIdentityId { get; set; }
66
public long RepresentedByOrganizationId { get; set; }

0 commit comments

Comments
 (0)