-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Monitor user Groups and Templates scripts #52
Conversation
…nd minor fixes to user group monitoring files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[code only review] Very close, cool to have tests. Mostly minor issues:
src/data/user-monitoring/user-groups-monitoring/UserGroupD2Repository.ts
Outdated
Show resolved
Hide resolved
src/data/user-monitoring/user-groups-monitoring/UserGroupD2Repository.ts
Outdated
Show resolved
Hide resolved
src/data/user-monitoring/user-groups-monitoring/UserGroupD2Repository.ts
Outdated
Show resolved
Hide resolved
...ain/usecases/user-monitoring/user-groups-monitoring/SaveUserGroupsMonitoringConfigUseCase.ts
Outdated
Show resolved
Hide resolved
src/domain/usecases/user-monitoring/user-templates-monitoring/MonitorUserTemplatesUseCase.ts
Outdated
Show resolved
Hide resolved
...ecases/user-monitoring/user-templates-monitoring/SaveUserTemplatesMonitoringConfigUseCase.ts
Outdated
Show resolved
Hide resolved
typos and repeated lines in README usermonitoring.ts => userMonitoring.ts userMonitoring: config_file => configFile UserGroup/TemplateDiff replace _Lost/Added to camel case CompareUserTemplatesUseCase.specs move noChangesDiff to data folder CompareUserGroupsUseCase.data add usersChanges to the user difference test
Rework User and UserGroup entities and D2Repositories. Fix and improve some tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some very minor details and we are ready to go
@@ -75,7 +73,7 @@ export class MonitorUserGroupsUseCase { | |||
log.info(`Get user groups with ids: ${options.groupsToMonitor.join(", ")}`); | |||
|
|||
const getGroupsUseCase = new GetUserGroupsUseCase(this.userGroupRepository); | |||
const compareUserGroupsUseCase = new CompareUserGroupsUseCase(); | |||
const compareUserGroupsUseCase = new CompareUserGroups(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can now remove UseCase
from the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry about that...
|
||
export class SaveUserGroupsMonitoringConfigUseCase { | ||
constructor(private configRepository: UserGroupsMonitoringConfigRepository) {} | ||
|
||
async execute(options: UserGroupsMonitoringOptions, monitoredUserGroups: UserGroup[]): Async<void> { | ||
options.lastExecution = new GetLogFormatDateUseCase().execute(new Date()); | ||
options.monitoredUserGroups = monitoredUserGroups; | ||
const new_options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
casing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, there were some other snake case names that are changed too.
@@ -12,7 +12,7 @@ import { | |||
|
|||
describe("CompareUserGroupsUseCase", () => { | |||
it("Should return empty array when comparing the same objects", () => { | |||
const useCase = new CompareUserGroupsUseCase(); | |||
const useCase = new CompareUserGroups(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
@@ -97,7 +97,7 @@ export class MonitorUserTemplatesUseCase { | |||
log.info(`Get user groups with usernames: ${options.templatesToMonitor.join(", ")}`); | |||
|
|||
const getTemplatesUseCase = new GetUserTemplatesUseCase(this.usersRepository); | |||
const compareUserTemplatesUseCase = new CompareUserTemplatesUseCase(); | |||
const compareUserTemplatesUseCase = new CompareUserTemplates(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
|
||
export class SaveUserTemplatesMonitoringConfigUseCase { | ||
constructor(private configRepository: UserTemplatesMonitoringConfigRepository) {} | ||
|
||
async execute(options: UserTemplatesMonitoringOptions, monitoredUserTemplates: User[]): Async<void> { | ||
options.lastExecution = new GetLogFormatDateUseCase().execute(new Date()); | ||
options.monitoredUserTemplates = monitoredUserTemplates; | ||
const new_options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
casing
|
||
beforeEach(() => { | ||
useCase = new CompareUserTemplatesUseCase(); | ||
useCase = new CompareUserTemplates(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
Simplify getLogFormatDate, naming and casing. Fix userRoles repeating in userCredentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good! 👍
📌 References
Issue: Implementation of the highest risk (the ones in green) events logging into MSTeams
📝 Implementation
This script will compare the metadata of the monitored userGroups or user templates with the version stored in the datastore and generate a report of the changes. This report will be sent to the MS Teams channel set in the webhook config section. Then the new version of the metadata will be stored in the datastore.
Execution:
Parameters:
--config-file
: Connection and webhook config file.-s
|--set-datastore
: Write monitored data to datastore, use in script setup. It assumes there is a monitoring config in d2-tools/[user-groups-monitoring | user-templates-monitoring]Requirements:
A config file with the access info of the server and the message webhook details:
Sample user-groups-monitoring datastore:
Sample user-templates-monitoring datastore:
This reports stores data into the
d2-tools.[user-groups-monitoring | user-templates-monitoring]
datastore. This key needs to be setup before the first run to get a correct report.Its possible to leave
monitoredUserGroups | monitoredUserTemplates
empty and use the-s
flag to populate it.The report, potentially, has tree sections for each user group:
If a section is empty it will be omited.