Skip to content

Commit

Permalink
Updated files with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyMitch committed Apr 19, 2024
1 parent aabc9fe commit 2e8ae48
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 138 deletions.
31 changes: 14 additions & 17 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
import dotenv from "dotenv";
import dotenv from 'dotenv';
dotenv.config();

const {
SSO_ENVIRONMENT = "dev",
CSS_API_CLIENT_ID = "",
CSS_API_CLIENT_SECRET = "",
SSO_INTEGRATION_ID = "",
DEBUG = "false",
VERBOSE_DEBUG = "false",
CSS_API_URL = "https://api.loginproxy.gov.bc.ca/api/v1",
SSO_ENVIRONMENT = 'dev',
CSS_API_CLIENT_ID = '',
CSS_API_CLIENT_SECRET = '',
SSO_INTEGRATION_ID = '',
DEBUG = 'false',
VERBOSE_DEBUG = 'false',
CSS_API_URL = 'https://api.loginproxy.gov.bc.ca/api/v1',
} = process.env;

// Exports.
const config = {
DEBUG: DEBUG === "true",
VERBOSE_DEBUG: VERBOSE_DEBUG === "true",
PACKAGE_NAME: "citz-imb-sso-css-api",
DEBUG: DEBUG === 'true',
VERBOSE_DEBUG: VERBOSE_DEBUG === 'true',
PACKAGE_NAME: 'citz-imb-sso-css-api',
SSO_ENVIRONMENT,
CSS_API_CLIENT_ID,
CSS_API_CLIENT_SECRET,
SSO_INTEGRATION_ID: SSO_INTEGRATION_ID.replace(/^0+/, ""), // Trim leading zeros.
SSO_INTEGRATION_ID: SSO_INTEGRATION_ID.replace(/^0+/, ''), // Trim leading zeros.
CSS_API_URL,
};

// Throw error if required env vars are not set.
if (!CSS_API_CLIENT_ID || !CSS_API_CLIENT_SECRET || !SSO_INTEGRATION_ID)
throw new Error(
`One or more environment variables were undefined for package ${config.PACKAGE_NAME}.
Ensure [CSS_API_CLIENT_ID, CSS_API_CLIENT_SECRET, SSO_INTEGRATION_ID] variables are set.`
Ensure [CSS_API_CLIENT_ID, CSS_API_CLIENT_SECRET, SSO_INTEGRATION_ID] variables are set.`,
);

// Log all variables.
if (config.DEBUG && config.VERBOSE_DEBUG)
console.info(
`DEBUG: Configuration variables for '${config.PACKAGE_NAME}': `,
config
);
console.info(`DEBUG: Configuration variables for '${config.PACKAGE_NAME}': `, config);

export default config;
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Integration
export { getIntegration } from "./integration";
export { getIntegration } from './integration';

// Roles
export {
Expand All @@ -12,15 +12,15 @@ export {
addRoleComposite, // Add a composite to a role.
getRoleComposite, // Get a composite role from a role.
deleteRoleComposite, // Remove a composite role from a role.
} from "./roles";
} from './roles';

// Role-Mapping
export {
getUserRoles, // Get roles associated with a user.
assignUserRoles, // Assign roles to a user.
getUsersWithRole, // Get users associated with a role.
unassignUserRole, // Unassign a role from a user.
} from "./roleMapping";
} from './roleMapping';

// Users
export {
Expand All @@ -31,4 +31,4 @@ export {
getBasicBCeIDUser, // Get Basic BCeID user by guid.
getBusinessBCeIDUser, // Get Business BCeID user by guid.
getBothBCeIDUser, // Get Basic or Business BCeID user by guid.
} from "./users";
} from './users';
8 changes: 4 additions & 4 deletions src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { request } from "./utils/request";
import debug from "./utils/debug";
import { request } from './utils/request';
import debug from './utils/debug';

import config from "./config";
import config from './config';
const { SSO_INTEGRATION_ID } = config;

// getIntegration - Get integration details.
export const getIntegration = async () => {
debug.functionCalled("getIntegration");
debug.functionCalled('getIntegration');
return await request({
environmentEndpoint: false,
endpoint: `integrations/${SSO_INTEGRATION_ID}`,
Expand Down
31 changes: 12 additions & 19 deletions src/roleMapping.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import { RequestBody } from "./types";
import { request } from "./utils/request";
import debug from "./utils/debug";
import { RequestBody } from './types';
import { request } from './utils/request';
import debug from './utils/debug';

// getUserRoles - Get roles associated with a user.
export const getUserRoles = async (username: string) => {
debug.functionCalled("getUserRoles");
debug.functionCalled('getUserRoles');
return await request({
integrationEndpoint: true,
endpoint: `users/${username}/roles`,
});
};

// assignUserRoles - Assign roles to a user.
export const assignUserRoles = async (
username: string,
roleNames: string[]
) => {
debug.functionCalled("assignUserRoles");
export const assignUserRoles = async (username: string, roleNames: string[]) => {
debug.functionCalled('assignUserRoles');
return await request({
integrationEndpoint: true,
endpoint: `users/${username}/roles`,
method: "POST",
method: 'POST',
body:
(roleNames.map((roleName) => ({
name: roleName,
Expand All @@ -29,26 +26,22 @@ export const assignUserRoles = async (
};

// getUsersWithRole - Get users associated with a role.
export const getUsersWithRole = async (
roleName: string,
page?: number,
maxCount?: number
) => {
debug.functionCalled("getUsersWithRole");
export const getUsersWithRole = async (roleName: string, page?: number, maxCount?: number) => {
debug.functionCalled('getUsersWithRole');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}/users${
page ? `?page=${page}${maxCount ? `&max=${maxCount}` : ""}` : ""
page ? `?page=${page}${maxCount ? `&max=${maxCount}` : ''}` : ''
}`,
});
};

// unassignUserRole - Unassign a role from a user.
export const unassignUserRole = async (username: string, roleName: string) => {
debug.functionCalled("unassignUserRole");
debug.functionCalled('unassignUserRole');
return await request({
integrationEndpoint: true,
endpoint: `users/${username}/roles/${roleName}`,
method: "DELETE",
method: 'DELETE',
});
};
51 changes: 21 additions & 30 deletions src/roles.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { request } from "./utils/request";
import debug from "./utils/debug";
import { request } from './utils/request';
import debug from './utils/debug';

// getRoles - Get all roles from integration.
export const getRoles = async () => {
debug.functionCalled("getRoles");
return await request({ integrationEndpoint: true, endpoint: "roles" });
debug.functionCalled('getRoles');
return await request({ integrationEndpoint: true, endpoint: 'roles' });
};

// createRole - Create a new role.
export const createRole = async (roleName: string) => {
debug.functionCalled("createRole");
debug.functionCalled('createRole');
return await request({
integrationEndpoint: true,
endpoint: "roles",
method: "POST",
endpoint: 'roles',
method: 'POST',
body: { name: roleName },
});
};

// getRole - Get role details.
export const getRole = async (roleName: string) => {
debug.functionCalled("getRole");
debug.functionCalled('getRole');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}`,
Expand All @@ -29,69 +29,60 @@ export const getRole = async (roleName: string) => {

// updateRole - Update a role name.
export const updateRole = async (roleName: string, newRoleName: string) => {
debug.functionCalled("updateRole");
debug.functionCalled('updateRole');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}`,
method: "PUT",
method: 'PUT',
body: { name: newRoleName },
});
};

// deleteRole - Remove a role.
export const deleteRole = async (roleName: string) => {
debug.functionCalled("deleteRole");
debug.functionCalled('deleteRole');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}`,
method: "DELETE",
method: 'DELETE',
});
};

// getRoleComposites - Get a role's composites.
export const getRoleComposites = async (roleName: string) => {
debug.functionCalled("getRoleComposites");
debug.functionCalled('getRoleComposites');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}/composite-roles`,
});
};

// addRoleComposite - Add a composite to a role.
export const addRoleComposite = async (
roleName: string,
newCompositeRole: string
) => {
debug.functionCalled("addRoleComposite");
export const addRoleComposite = async (roleName: string, newCompositeRole: string) => {
debug.functionCalled('addRoleComposite');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}/composite-roles`,
method: "POST",
method: 'POST',
body: { name: newCompositeRole },
});
};

// getRoleComposite - Get a composite role from a role.
export const getRoleComposite = async (
roleName: string,
compositeRoleName: string
) => {
debug.functionCalled("getRoleComposite");
export const getRoleComposite = async (roleName: string, compositeRoleName: string) => {
debug.functionCalled('getRoleComposite');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}/composite-roles/${compositeRoleName}`,
});
};

// deleteRoleComposite - Remove a composite role from a role.
export const deleteRoleComposite = async (
roleName: string,
compositeRoleName: string
) => {
debug.functionCalled("deleteRoleComposite");
export const deleteRoleComposite = async (roleName: string, compositeRoleName: string) => {
debug.functionCalled('deleteRoleComposite');
return await request({
integrationEndpoint: true,
endpoint: `roles/${roleName}/composite-roles/${compositeRoleName}`,
method: "DELETE",
method: 'DELETE',
});
};
14 changes: 7 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
type RequestRoleObject = {
name: string;
};

export type RequestBody = RequestRoleObject | RequestRoleObject[] | [];

export type RequestParams = {
integrationEndpoint?: boolean;
environmentEndpoint?: boolean;
endpoint: string;
method?: "GET" | "POST" | "PUT" | "DELETE";
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
body?: RequestBody;
};

type RequestRoleObject = {
name: string;
};

export type RequestBody = RequestRoleObject | RequestRoleObject[] | [];

export type IDIRUserQuery = {
firstName?: string;
lastName?: string;
Expand Down
30 changes: 15 additions & 15 deletions src/users.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import qs from "querystring";
import { GitHubUserQuery, IDIRUserQuery } from "./types";
import { request } from "./utils/request";
import debug from "./utils/debug";
import qs from 'querystring';
import { GitHubUserQuery, IDIRUserQuery } from './types';
import { request } from './utils/request';
import debug from './utils/debug';

// getIDIRUsers - Get list of IDIR users by query.
export const getIDIRUsers = async (query: IDIRUserQuery) => {
debug.functionCalled("getIDIRUsers");
debug.functionCalled('getIDIRUsers');
return await request({
integrationEndpoint: false,
endpoint: `idir/users${query ? `?${qs.stringify(query)}` : ""}`,
endpoint: `idir/users${query ? `?${qs.stringify(query)}` : ''}`,
});
};

// getAzureIDIRUsers - Get list of Azure IDIR users by query.
export const getAzureIDIRUsers = async (query: IDIRUserQuery) => {
debug.functionCalled("getAzureIDIRUsers");
debug.functionCalled('getAzureIDIRUsers');
return await request({
integrationEndpoint: false,
endpoint: `azure-idir/users${query ? `?${qs.stringify(query)}` : ""}`,
endpoint: `azure-idir/users${query ? `?${qs.stringify(query)}` : ''}`,
});
};

// getGitHubBCGovUsers - Get list of GitHub BCGov users by query.
export const getGitHubBCGovUsers = async (query: GitHubUserQuery) => {
debug.functionCalled("getGitHubBCGovUsers");
debug.functionCalled('getGitHubBCGovUsers');
return await request({
integrationEndpoint: false,
endpoint: `github-bcgov/users${query ? `?${qs.stringify(query)}` : ""}`,
endpoint: `github-bcgov/users${query ? `?${qs.stringify(query)}` : ''}`,
});
};

// getGitHubPublicUsers - Get list of GitHub Public users by query.
export const getGitHubPublicUsers = async (query: GitHubUserQuery) => {
debug.functionCalled("getGitHubPublicUsers");
debug.functionCalled('getGitHubPublicUsers');
return await request({
integrationEndpoint: false,
endpoint: `github-public/users${query ? `?${qs.stringify(query)}` : ""}`,
endpoint: `github-public/users${query ? `?${qs.stringify(query)}` : ''}`,
});
};

// getBasicBCeIDUser - Get Basic BCeID user by guid.
export const getBasicBCeIDUser = async (guid: string) => {
debug.functionCalled("getBasicBCeIDUser");
debug.functionCalled('getBasicBCeIDUser');
return await request({
integrationEndpoint: false,
endpoint: `basic-bceid/users?guid=${guid}`,
Expand All @@ -50,7 +50,7 @@ export const getBasicBCeIDUser = async (guid: string) => {

// getBusinessBCeIDUser - Get Business BCeID user by guid.
export const getBusinessBCeIDUser = async (guid: string) => {
debug.functionCalled("getBusinessBCeIDUser");
debug.functionCalled('getBusinessBCeIDUser');
return await request({
integrationEndpoint: false,
endpoint: `business-bceid/users?guid=${guid}`,
Expand All @@ -59,7 +59,7 @@ export const getBusinessBCeIDUser = async (guid: string) => {

// getBothBCeIDUser - Get Basic or Business BCeID user by guid.
export const getBothBCeIDUser = async (guid: string) => {
debug.functionCalled("getBothBCeIDUser");
debug.functionCalled('getBothBCeIDUser');
return await request({
integrationEndpoint: false,
endpoint: `basic-business-bceid/users?guid=${guid}`,
Expand Down
Loading

0 comments on commit 2e8ae48

Please sign in to comment.