Skip to content

Commit

Permalink
Add new config to determine deployed environment
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1morel committed Jul 11, 2024
1 parent 022358e commit a2b15d9
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/environments/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config:
SERVER_CHES_APIPATH: https://ches-dev.api.gov.bc.ca/api/v1
SERVER_CHES_TOKENURL: https://dev.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token
SERVER_DB_PORT: "5432"
SERVER_ENV: dev
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: http
SERVER_OIDC_AUTHORITY: https://dev.loginproxy.gov.bc.ca/auth/realms/standard
Expand Down
1 change: 1 addition & 0 deletions .github/environments/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config:
SERVER_CHES_APIPATH: https://ches.api.gov.bc.ca/api/v1
SERVER_CHES_TOKENURL: https://loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token
SERVER_DB_PORT: "5432"
SERVER_ENV: prod
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: http
SERVER_OIDC_AUTHORITY: https://loginproxy.gov.bc.ca/auth/realms/standard
Expand Down
1 change: 1 addition & 0 deletions .github/environments/values.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config:
SERVER_CHES_APIPATH: https://ches-test.api.gov.bc.ca/api/v1
SERVER_CHES_TOKENURL: https://test.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token
SERVER_DB_PORT: "5432"
SERVER_ENV: test
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: http
SERVER_OIDC_AUTHORITY: https://test.loginproxy.gov.bc.ca/auth/realms/standard
Expand Down
1 change: 1 addition & 0 deletions app/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"port": "SERVER_DB_PORT",
"username": "SERVER_DB_USERNAME"
},
"env": "SERVER_ENV",
"logFile": "SERVER_LOGFILE",
"logLevel": "SERVER_LOGLEVEL",
"oidc": {
Expand Down
18 changes: 18 additions & 0 deletions app/src/controllers/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ const controller = {
}
},

searchIdirUsers: async (req: Request, res: Response, next: NextFunction) => {
try {
const response = await ssoService.searchIdirUsers(req.query);
res.status(response.status).json(response.data);
} catch (e: unknown) {
next(e);
}
},

searchBasicBceidUsers: async (req: Request, res: Response, next: NextFunction) => {
try {
const response = await ssoService.searchBasicBceidUsers(req.query);
res.status(response.status).json(response.data);
} catch (e: unknown) {
next(e);
}
},

getRoles: async (req: Request, res: Response, next: NextFunction) => {
try {
const response = await ssoService.getRoles();
Expand Down
8 changes: 8 additions & 0 deletions app/src/routes/v1/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ router.post('/requestBasicAccess', (req: Request, res: Response, next: NextFunct
ssoController.requestBasicAccess(req, res, next);
});

router.get('/idir/users', (req: Request, res: Response, next: NextFunction): void => {
ssoController.searchIdirUsers(req, res, next);
});

router.get('/basic-bceid/users', (req: Request, res: Response, next: NextFunction): void => {
ssoController.searchBasicBceidUsers(req, res, next);
});

router.get('/roles', (req: Request, res: Response, next: NextFunction): void => {
ssoController.getRoles(req, res, next);
});
Expand Down
58 changes: 56 additions & 2 deletions app/src/services/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import { AccessRole } from '../utils/enums/application';

import type { AxiosInstance } from 'axios';

// Types

type IdirSearchParams = {
firstName: string;
lastName: string;
email: string;
};

type BCeIdSearchParams = {
guid: string;
};

/**
* @function getToken
* Gets Auth token using SSO credentials
Expand Down Expand Up @@ -52,8 +64,9 @@ function ssoAxios(): AxiosInstance {
const service = {
requestBasicAccess: async (username: string) => {
try {
const env = config.get('server.env');
const integration = config.get('server.sso.integration');
const { data, status } = await ssoAxios().post(`/integrations/${integration}/dev/users/${username}/roles`, [
const { data, status } = await ssoAxios().post(`/integrations/${integration}/${env}/users/${username}/roles`, [
{
name: AccessRole.PCNS_PROPONENT
}
Expand All @@ -74,10 +87,51 @@ const service = {
}
},

searchIdirUsers: async (params?: IdirSearchParams) => {
try {
const env = config.get('server.env');
const { data, status } = await ssoAxios().get(`/${env}/idir/users`, { params: params });
return { data: data.data, status };
} catch (e: unknown) {
if (axios.isAxiosError(e)) {
return {
data: e.response?.data.message,
status: e.response ? e.response.status : 500
};
} else {
return {
data: 'Error',
status: 500
};
}
}
},

searchBasicBceidUsers: async (params?: BCeIdSearchParams) => {
try {
const env = config.get('server.env');
const { data, status } = await ssoAxios().get(`/${env}/basic-bceid/users`, { params: params });
return { data: data.data, status };
} catch (e: unknown) {
if (axios.isAxiosError(e)) {
return {
data: e.response?.data.message,
status: e.response ? e.response.status : 500
};
} else {
return {
data: 'Error',
status: 500
};
}
}
},

getRoles: async () => {
try {
const env = config.get('server.env');
const integration = config.get('server.sso.integration');
const { data, status } = await ssoAxios().get(`/integrations/${integration}/dev/roles`);
const { data, status } = await ssoAxios().get(`/integrations/${integration}/${env}/roles`);
return { data: data.data, status };
} catch (e: unknown) {
if (axios.isAxiosError(e)) {
Expand Down
2 changes: 1 addition & 1 deletion charts/pcns/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: nr-permitconnect-navigator-service
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.9
version: 0.0.10
kubeVersion: ">= 1.13.0"
description: PermitConnect Navigator Service
# A chart can be either an 'application' or a 'library' chart.
Expand Down
4 changes: 2 additions & 2 deletions charts/pcns/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nr-permitconnect-navigator-service

![Version: 0.0.9](https://img.shields.io/badge/Version-0.0.9-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.3.0](https://img.shields.io/badge/AppVersion-0.3.0-informational?style=flat-square)
![Version: 0.0.10](https://img.shields.io/badge/Version-0.0.10-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.3.0](https://img.shields.io/badge/AppVersion-0.3.0-informational?style=flat-square)

PermitConnect Navigator Service

Expand Down Expand Up @@ -35,7 +35,7 @@ Kubernetes: `>= 1.13.0`
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
| chesSecretOverride.password | string | `nil` | |
| chesSecretOverride.username | string | `nil` | |
| config.configMap | object | `{"FRONTEND_APIPATH":"api/v1","FRONTEND_CHES_ROADMAP_BCC":null,"FRONTEND_CHES_SUBMISSION_CC":null,"FRONTEND_COMS_APIPATH":null,"FRONTEND_COMS_BUCKETID":null,"FRONTEND_GEOCODER_APIPATH":null,"FRONTEND_OIDC_AUTHORITY":null,"FRONTEND_OIDC_CLIENTID":null,"FRONTEND_OPENSTREETMAP_APIPATH":null,"FRONTEND_ORGBOOK_APIPATH":null,"SERVER_APIPATH":"/api/v1","SERVER_BODYLIMIT":"30mb","SERVER_CHEFS_APIPATH":null,"SERVER_CHES_APIPATH":null,"SERVER_CHES_TOKENURL":null,"SERVER_DB_HOST":null,"SERVER_DB_POOL_MAX":"10","SERVER_DB_POOL_MIN":"2","SERVER_DB_PORT":"5432","SERVER_LOGLEVEL":"http","SERVER_OIDC_AUTHORITY":null,"SERVER_OIDC_IDENTITYKEY":null,"SERVER_OIDC_PUBLICKEY":null,"SERVER_PORT":"8080"}` | These values will be wholesale added to the configmap as is; refer to the pcns documentation for what each of these values mean and whether you need them defined. Ensure that all values are represented explicitly as strings, as non-string values will not translate over as expected into container environment variables. For configuration keys named `*_ENABLED`, either leave them commented/undefined, or set them to string value "true". |
| config.configMap | object | `{"FRONTEND_APIPATH":"api/v1","FRONTEND_CHES_ROADMAP_BCC":null,"FRONTEND_CHES_SUBMISSION_CC":null,"FRONTEND_COMS_APIPATH":null,"FRONTEND_COMS_BUCKETID":null,"FRONTEND_GEOCODER_APIPATH":null,"FRONTEND_OIDC_AUTHORITY":null,"FRONTEND_OIDC_CLIENTID":null,"FRONTEND_OPENSTREETMAP_APIPATH":null,"FRONTEND_ORGBOOK_APIPATH":null,"SERVER_APIPATH":"/api/v1","SERVER_BODYLIMIT":"30mb","SERVER_CHEFS_APIPATH":null,"SERVER_CHES_APIPATH":null,"SERVER_CHES_TOKENURL":null,"SERVER_DB_HOST":null,"SERVER_DB_POOL_MAX":"10","SERVER_DB_POOL_MIN":"2","SERVER_DB_PORT":"5432","SERVER_ENV":null,"SERVER_LOGLEVEL":"http","SERVER_OIDC_AUTHORITY":null,"SERVER_OIDC_IDENTITYKEY":null,"SERVER_OIDC_PUBLICKEY":null,"SERVER_PORT":"8080"}` | These values will be wholesale added to the configmap as is; refer to the pcns documentation for what each of these values mean and whether you need them defined. Ensure that all values are represented explicitly as strings, as non-string values will not translate over as expected into container environment variables. For configuration keys named `*_ENABLED`, either leave them commented/undefined, or set them to string value "true". |
| config.enabled | bool | `false` | Set to true if you want to let Helm manage and overwrite your configmaps. |
| config.releaseScoped | bool | `false` | This should be set to true if and only if you require configmaps and secrets to be release scoped. In the event you want all instances in the same namespace to share a similar configuration, this should be set to false |
| dbSecretOverride.password | string | `nil` | |
Expand Down
2 changes: 2 additions & 0 deletions charts/pcns/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ config:
SERVER_DB_POOL_MIN: "2"
SERVER_DB_POOL_MAX: "10"

SERVER_ENV: ~

# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: http
SERVER_PORT: "8080"
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/services/permissionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ export default class PermissionService {
return appAxios().post('sso/requestBasicAccess');
}

public async searchIdirUsers(params?: any) {
return appAxios().get('sso/idir/users', { params: params });
}

public async searchBasicBceidUsers(params?: any) {
return appAxios().get('sso/basic-bceid/users', { params: params });
}

public async getRoles() {
return appAxios().get('sso/roles');
}
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/views/DeveloperView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ async function ssoRequestBasicAccess() {
await permissionService.requestBasicAccess();
}
async function ssGetRoles() {
async function searchIdirUsers() {
await permissionService.searchIdirUsers({ firstName: 'Kyle' });
}
async function searchBasicBceidUsers() {
await permissionService.searchBasicBceidUsers({ guid: 'tb914nlltlo4mz05viha1b4hdyi4xnad' });
}
async function ssoGetRoles() {
await permissionService.getRoles();
}
</script>
Expand Down Expand Up @@ -84,10 +92,13 @@ async function ssGetRoles() {
<div class="flex align-items-center mt-3">
<h3 class="mr-2">SSO Test</h3>
<div>
<Button @click="ssoRequestBasicAccess">SSO Test</Button>
<Button @click="searchIdirUsers">SSO search idir</Button>
</div>
<div>
<Button @click="searchBasicBceidUsers">SSO search basic bceid</Button>
</div>
<div>
<Button @click="ssGetRoles">SSO Test 2</Button>
<Button @click="ssoGetRoles">SSO get roles</Button>
</div>
</div>
</div>
Expand Down

0 comments on commit a2b15d9

Please sign in to comment.