Skip to content

Commit

Permalink
Merge pull request #29 from bcgov/MAKE-ENV-VARS-ALLCAPS
Browse files Browse the repository at this point in the history
Update admin service so that env vars are in all caps
  • Loading branch information
mgtennant authored Aug 16, 2024
2 parents 1f86f58 + 4389e54 commit dd82147
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions backend/src/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class AdminService {
constructor(private readonly httpService: HttpService) {}

async getToken() {
const url = process.env.users_api_token_url;
const token = `${process.env.users_api_client_id}:${process.env.users_api_client_secret}`;
const url = process.env.USERS_API_TOKEN_URL;
const token = `${process.env.USERS_API_CLIENT_ID}:${process.env.USERS_API_CLIENT_SECRET}`;
const encodedToken = Buffer.from(token).toString("base64");
const config = {
headers: {
Expand All @@ -23,7 +23,7 @@ export class AdminService {
grantTypeParam.append("grant_type", "client_credentials");
try {
const response = await firstValueFrom(
this.httpService.post(url, grantTypeParam.toString(), config)
this.httpService.post(url, grantTypeParam.toString(), config),
);
return response.data.access_token;
} catch (error) {
Expand All @@ -39,14 +39,14 @@ export class AdminService {
*/
async findAll(): Promise<any[]> {
const bearerToken = await this.getToken();
const adminUrl = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/roles/${Role.ENMODS_ADMIN}/users`;
const userUrl = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/roles/${Role.ENMODS_USER}/users`;
const adminUrl = `${process.env.USERS_API_BASE_URL}/integrations/${process.env.INTEGRATION_ID}/${process.env.CSS_ENVIRONMENT}/roles/${Role.ENMODS_ADMIN}/users`;
const userUrl = `${process.env.USERS_API_BASE_URL}/integrations/${process.env.INTEGRATION_ID}/${process.env.CSS_ENVIRONMENT}/roles/${Role.ENMODS_USER}/users`;
const config = {
headers: { Authorization: "Bearer " + bearerToken },
};
try {
const adminResponse = await firstValueFrom(
this.httpService.get(adminUrl, config)
this.httpService.get(adminUrl, config),
);

const returnData: UserInfo[] = [];
Expand All @@ -64,12 +64,12 @@ export class AdminService {
});
});
const userResponse = await firstValueFrom(
this.httpService.get(userUrl, config)
this.httpService.get(userUrl, config),
);
const userData = userResponse.data.data;
userData.map((user: IdirUserInfo) => {
const existingUser = returnData.find(
(u) => u.username === user.attributes.idir_username[0]
(u) => u.username === user.attributes.idir_username[0],
);
if (existingUser) {
existingUser.role.push(Role.ENMODS_USER);
Expand Down Expand Up @@ -101,15 +101,15 @@ export class AdminService {
* @returns
*/
async userEmailSearch(email: string): Promise<any> {
const url = `${process.env.users_api_base_url}/${process.env.css_environment}/idir/users?&email=${email}`;
const url = `${process.env.USERS_API_BASE_URL}/${process.env.CSS_ENVIRONMENT}/idir/users?&email=${email}`;
const bearerToken = await this.getToken();

const config = {
headers: { Authorization: "Bearer " + bearerToken },
};

const searchData: IdirUserInfo[] = await firstValueFrom(
this.httpService.get(url, config)
this.httpService.get(url, config),
)
.then((res) => {
return res.data.data;
Expand All @@ -128,7 +128,7 @@ export class AdminService {
* @returns
*/
async addRoles(userRolesDto: UserRolesDto): Promise<any> {
const addRolesUrl = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/user-role-mappings`;
const addRolesUrl = `${process.env.USERS_API_BASE_URL}/integrations/${process.env.INTEGRATION_ID}/${process.env.CSS_ENVIRONMENT}/user-role-mappings`;
const bearerToken = await this.getToken();

const config = {
Expand All @@ -145,8 +145,8 @@ export class AdminService {
username: userRolesDto.idirUsername,
operation: "add",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand All @@ -166,8 +166,8 @@ export class AdminService {
username: userRolesDto.idirUsername,
operation: "add",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand All @@ -193,7 +193,7 @@ export class AdminService {
};
for (const role of userRolesDto.roles) {
if (role === Role.ENMODS_USER) {
const url = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/user-role-mappings`;
const url = `${process.env.USERS_API_BASE_URL}/integrations/${process.env.INTEGRATION_ID}/${process.env.CSS_ENVIRONMENT}/user-role-mappings`;
await firstValueFrom(
this.httpService.post(
url,
Expand All @@ -202,8 +202,8 @@ export class AdminService {
username: userRolesDto.idirUsername,
operation: "del",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand All @@ -214,7 +214,7 @@ export class AdminService {
});
}
if (role === Role.ENMODS_ADMIN) {
const url = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/user-role-mappings`;
const url = `${process.env.USERS_API_BASE_URL}/integrations/${process.env.INTEGRATION_ID}/${process.env.CSS_ENVIRONMENT}/user-role-mappings`;
await firstValueFrom(
this.httpService.post(
url,
Expand All @@ -223,8 +223,8 @@ export class AdminService {
username: userRolesDto.idirUsername,
operation: "del",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand All @@ -247,9 +247,9 @@ export class AdminService {
async updateRoles(
idirUsername: string,
existingRoles: string[],
roles: string[]
roles: string[],
): Promise<any> {
const url = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/user-role-mappings`;
const url = `${process.env.USERS_API_BASE_URL}/integrations/${process.env.INTEGRATION_ID}/${process.env.CSS_ENVIRONMENT}/user-role-mappings`;
const bearerToken = await this.getToken();

const config = {
Expand All @@ -269,8 +269,8 @@ export class AdminService {
username: idirUsername,
operation: "del",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand All @@ -288,8 +288,8 @@ export class AdminService {
username: idirUsername,
operation: "del",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand All @@ -311,8 +311,8 @@ export class AdminService {
username: idirUsername,
operation: "add",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand All @@ -330,8 +330,8 @@ export class AdminService {
username: idirUsername,
operation: "add",
},
config
)
config,
),
)
.then((res) => {
return res.data;
Expand Down

0 comments on commit dd82147

Please sign in to comment.