generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Release/lewis moon snail (#648)
Co-authored-by: dmitri-korin-bcps <[email protected]> Co-authored-by: Barrett Falk <[email protected]> Co-authored-by: gregorylavery <[email protected]> Co-authored-by: Scarlett <[email protected]> Co-authored-by: Mike <[email protected]> Co-authored-by: Mike Sears <[email protected]> Co-authored-by: jeznorth <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Scarlett <[email protected]>
- Loading branch information
1 parent
33f7f58
commit a2671b4
Showing
202 changed files
with
11,457 additions
and
2,518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const hasRole = (req, role: string) => { | ||
const userroles = req.user.client_roles; | ||
const hasRole = userroles?.includes(role); | ||
return hasRole; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export enum Role { | ||
COS_OFFICER = "COS Officer", | ||
COS_ADMIN = "COS Admin", | ||
COS_ADMINISTRATOR = "COS Administrator", | ||
CEEB = "CEEB", | ||
CEEB_COMPLIANCE_COORDINATOR = "CEEB Compliance Coordinator", | ||
CEEB_SECTION_HEAD = "CEEB Section Head", | ||
TEMPORARY_TEST_ADMIN = "TEMPORARY_TEST_ADMIN", | ||
READ_ONLY = "READ ONLY", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { CssService } from "./css.service"; | ||
import { ConfigurationModule } from "../../v1/configuration/configuration.module"; | ||
|
||
@Module({ | ||
imports: [ConfigurationModule], | ||
providers: [CssService], | ||
exports: [CssService], | ||
}) | ||
export class CssModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { getRepositoryToken } from "@nestjs/typeorm"; | ||
import { ConfigurationService } from "../../v1/configuration/configuration.service"; | ||
import { Configuration } from "../../v1/configuration/entities/configuration.entity"; | ||
import { CssService } from "./css.service"; | ||
|
||
describe("CssService", () => { | ||
let service: CssService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
CssService, | ||
ConfigurationService, | ||
{ | ||
provide: getRepositoryToken(Configuration), | ||
useValue: {}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<CssService>(CssService); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import { Inject, Injectable, Logger } from "@nestjs/common"; | ||
import { ExternalApiService } from "../external-api-service"; | ||
import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; | ||
import { get } from "../../helpers/axios-api"; | ||
import { ConfigurationService } from "../../v1/configuration/configuration.service"; | ||
|
||
@Injectable() | ||
export class CssService implements ExternalApiService { | ||
private readonly logger = new Logger(CssService.name); | ||
|
||
readonly authApi: string; | ||
readonly baseUri: string; | ||
readonly clientId: string; | ||
readonly clientSecret: string; | ||
readonly grantType: string; | ||
readonly env: string; | ||
|
||
@Inject(ConfigurationService) | ||
readonly configService: ConfigurationService; | ||
|
||
constructor() { | ||
this.authApi = process.env.CSS_TOKEN_URL; | ||
this.baseUri = process.env.CSS_URL; | ||
this.clientId = process.env.CSS_CLIENT_ID; | ||
this.clientSecret = process.env.CSS_CLIENT_SECRET; | ||
this.grantType = "client_credentials"; | ||
this.env = process.env.ENVIRONMENT; | ||
} | ||
|
||
authenticate = async (): Promise<string> => { | ||
const response: AxiosResponse = await axios.post( | ||
this.authApi, | ||
{ | ||
client_id: this.clientId, | ||
client_secret: this.clientSecret, | ||
grant_type: this.grantType, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
}, | ||
); | ||
return response?.data?.access_token; | ||
}; | ||
|
||
getUserIdirByName = async (firstName, lastName): Promise<AxiosResponse> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/${this.env}/idir/users?firstName=${firstName}&lastName=${lastName}`; | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiToken}`, | ||
}, | ||
}; | ||
const response = await get(apiToken, url, config); | ||
return response?.data.data; | ||
} catch (error) { | ||
this.logger.error(`exception: unable to get user: ${firstName} ${lastName} - error: ${error}`); | ||
throw new Error(`exception: unable to get user: ${firstName} ${lastName} - error: ${error}`); | ||
} | ||
}; | ||
|
||
getUserRoles = async (userIdir): Promise<{ name: string; composite: string }[]> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/integrations/4794/${this.env}/users/${userIdir}/roles`; | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiToken}`, | ||
}, | ||
}; | ||
const response = await get(apiToken, url, config); | ||
return response?.data.data; | ||
} catch (error) { | ||
this.logger.error(`exception: unable to get user's roles ${userIdir} - error: ${error}`); | ||
throw new Error(`exception: unable to get user's roles ${userIdir} - error: ${error}`); | ||
} | ||
}; | ||
|
||
updateUserRole = async (userIdir, userRoles): Promise<{ name: string; composite: string }[]> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/integrations/4794/${this.env}/users/${userIdir}/roles`; | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiToken}`, | ||
}, | ||
}; | ||
const response = await axios.post(url, userRoles, config); | ||
return response?.data.data; | ||
} catch (error) { | ||
this.logger.error(`exception: unable to update user's roles ${userIdir} - error: ${error}`); | ||
throw new Error(`exception: unable to update user's roles ${userIdir} - error: ${error}`); | ||
} | ||
}; | ||
|
||
deleteUserRole = async (userIdir, roleName): Promise<AxiosResponse> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/integrations/4794/${this.env}/users/${userIdir}/roles/${roleName}`; | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiToken}`, | ||
}, | ||
}; | ||
const response = await axios.delete(url, config); | ||
return response?.data.data; | ||
} catch (error) { | ||
this.logger.error(`exception: unable to delete user's role ${userIdir} - error: ${error}`); | ||
throw new Error(`exception: unable to delete user's role ${userIdir} - error: ${error}`); | ||
} | ||
}; | ||
|
||
getUserRoleMapping = async (): Promise<AxiosResponse> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
//Get all roles from NatCom CSS integation | ||
const rolesUrl = `${this.baseUri}/api/v1/integrations/4794/${this.env}/roles`; | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiToken}`, | ||
}, | ||
}; | ||
const roleRes = await get(apiToken, rolesUrl, config); | ||
if (roleRes?.data.data.length > 0) { | ||
const { | ||
data: { data: roleList }, | ||
} = roleRes; | ||
|
||
//Get all users for each role | ||
let usersUrl: string = ""; | ||
const usersRoles = await Promise.all( | ||
roleList.map(async (role) => { | ||
usersUrl = `${this.baseUri}/api/v1/integrations/4794/${this.env}/roles/${role.name}/users`; | ||
const userRes = await get(apiToken, encodeURI(usersUrl), config); | ||
if (userRes?.data.data.length > 0) { | ||
const { | ||
data: { data: users }, | ||
} = userRes; | ||
let usersRolesTemp = await Promise.all( | ||
users.map((user) => { | ||
return { | ||
userId: user.username | ||
.replace(/@idir$/i, "") | ||
.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5"), | ||
role: role.name, | ||
}; | ||
}), | ||
); | ||
return usersRolesTemp; | ||
} | ||
}), | ||
); | ||
|
||
//exclude empty roles and concatenate all sub-array elements | ||
const usersRolesFlat = usersRoles.filter((item) => item !== undefined).flat(); | ||
|
||
//group the array elements by a user id | ||
const usersRolesGroupped = usersRolesFlat.reduce((grouping, item) => { | ||
grouping[item.userId] = [...(grouping[item.userId] || []), item.role]; | ||
return grouping; | ||
}, {}); | ||
|
||
return usersRolesGroupped; | ||
} | ||
} catch (error) { | ||
this.logger.error(`exception: error: ${error}`); | ||
return; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.