mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
ACA-4171 to ACA-4174 Display the number of activated and deactivated users (#6400)
* ACA-4171 to ACA-4174 Display the number of activated and deactivated users * ACA-4171 to ACA-4174 Added scan-env command to README Co-authored-by: Thomas Hunter <thomas.hunter@alfresco.com>
This commit is contained in:
@@ -56,6 +56,7 @@ In develop mode, the CLI takes the prebuilt scripts from the dist folder.
|
|||||||
|update-version |This command allows you to update the adf dependencies and js-api with different versions Update adf libs and js-api with latest alpha|
|
|update-version |This command allows you to update the adf dependencies and js-api with different versions Update adf libs and js-api with latest alpha|
|
||||||
|licenses |Create a 3th party license file |
|
|licenses |Create a 3th party license file |
|
||||||
|audit |Check the security risk dependency in your package.json |
|
|audit |Check the security risk dependency in your package.json |
|
||||||
|
|scan-env |Scan the environment to show its status |
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
76
lib/cli/scripts/scan-env.ts
Normal file
76
lib/cli/scripts/scan-env.ts
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
const { AlfrescoApiCompatibility, PeopleApi } = require('@alfresco/js-api');
|
||||||
|
const program = require('commander');
|
||||||
|
|
||||||
|
const MAX_ATTEMPTS = 10;
|
||||||
|
const TIMEOUT = 60000;
|
||||||
|
const MAX_PEOPLE_PER_PAGE = 100;
|
||||||
|
|
||||||
|
let jsApiConnection;
|
||||||
|
let loginAttempts: number = 0;
|
||||||
|
|
||||||
|
export default async function main(_args: string[]) {
|
||||||
|
|
||||||
|
program
|
||||||
|
.version('0.1.0')
|
||||||
|
.option('--host <type>', 'Remote environment host')
|
||||||
|
.option('-p, --password <type>', 'password ')
|
||||||
|
.option('-u, --username <type>', 'username ')
|
||||||
|
.parse(process.argv);
|
||||||
|
|
||||||
|
await attemptLogin();
|
||||||
|
|
||||||
|
const peopleCount = await getPeopleCount();
|
||||||
|
console.log('Active Users :', peopleCount.enabled);
|
||||||
|
console.log('Deactivated Users :', peopleCount.disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function attemptLogin() {
|
||||||
|
try {
|
||||||
|
jsApiConnection = new AlfrescoApiCompatibility({
|
||||||
|
provider: 'ECM',
|
||||||
|
hostEcm: program.host
|
||||||
|
});
|
||||||
|
await jsApiConnection.login(program.username, program.password);
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Login error environment down or inaccessible');
|
||||||
|
loginAttempts++;
|
||||||
|
if (MAX_ATTEMPTS === loginAttempts) {
|
||||||
|
console.log('Give up');
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
console.log(`Retry in 1 minute attempt N ${loginAttempts}`);
|
||||||
|
await wait(TIMEOUT);
|
||||||
|
await attemptLogin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PeopleTally { enabled: number, disabled: number }
|
||||||
|
async function getPeopleCount(skipCount: number = 0): Promise<PeopleTally> {
|
||||||
|
try {
|
||||||
|
const peopleApi = new PeopleApi(jsApiConnection);
|
||||||
|
const apiResult = await peopleApi.listPeople({
|
||||||
|
fields: ['enabled'],
|
||||||
|
maxItems: MAX_PEOPLE_PER_PAGE,
|
||||||
|
skipCount: skipCount
|
||||||
|
});
|
||||||
|
const result: PeopleTally = apiResult.list.entries.reduce((peopleTally: PeopleTally, currentPerson) => {
|
||||||
|
if (currentPerson.entry.enabled) { peopleTally.enabled++; } else { peopleTally.disabled++; }
|
||||||
|
return peopleTally;
|
||||||
|
}, { enabled: 0, disabled: 0 });
|
||||||
|
if (apiResult.list.pagination.hasMoreItems) {
|
||||||
|
const more = await getPeopleCount(apiResult.list.pagination.skipCount + MAX_PEOPLE_PER_PAGE);
|
||||||
|
result.enabled += more.enabled;
|
||||||
|
result.disabled += more.disabled;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function wait(ms: number) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user