mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-5845] remove Alfresco Compatibility usage (#8822)
* upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * fix security concerns for execSync * security fix * fixes as per code reviews * code fixes for attach file widget dialog * code fixes * code fixes * disable ACS storage check * add the jira to the commented out block * remove useless logger call * code fixes * code fixes * code fixes * code and typing fixes * fix lint * disable the code * try other fixes, add missing headers * dump error to console * replace test file with in-memory stream * code fixes * simplify checks * disable upload * remove useless test and ng-mocks dependency
This commit is contained in:
@@ -15,65 +15,61 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
import { exit } from 'node:process';
|
||||
import { logger } from './../logger';
|
||||
import alfrescoApi = require('@alfresco/js-api');
|
||||
|
||||
const TIMEOUT = 6000;
|
||||
const MAX_RETRY = 10;
|
||||
export class CheckEnv {
|
||||
_alfrescoJsApi: any;
|
||||
_alfrescoJsApi: AlfrescoApi;
|
||||
counter = 0;
|
||||
|
||||
constructor(
|
||||
private host: string,
|
||||
private username: string,
|
||||
private password: string,
|
||||
private clientId: string = 'alfresco'
|
||||
) {}
|
||||
constructor(private host: string, private username: string, private password: string, private clientId: string = 'alfresco') {}
|
||||
|
||||
async checkEnv() {
|
||||
try {
|
||||
this.alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
|
||||
this.alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ALL',
|
||||
hostBpm: this.host,
|
||||
hostEcm: this.host,
|
||||
authType: 'OAUTH',
|
||||
contextRoot: 'alfresco',
|
||||
oauth2: {
|
||||
host: `${this.host}/auth/realms/alfresco`,
|
||||
clientId: `${this.clientId}`,
|
||||
scope: 'openid'
|
||||
scope: 'openid',
|
||||
redirectUri: '/'
|
||||
}
|
||||
} as any);
|
||||
});
|
||||
await this.alfrescoJsApi.login(this.username, this.password);
|
||||
} catch (e) {
|
||||
if (e.error.code === 'ETIMEDOUT') {
|
||||
logger.error('The env is not reachable. Terminating');
|
||||
process.exit(1);
|
||||
exit(1);
|
||||
}
|
||||
logger.error('Login error environment down or inaccessible');
|
||||
this.counter++;
|
||||
if (MAX_RETRY === this.counter) {
|
||||
logger.error('Give up');
|
||||
process.exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
logger.error(
|
||||
`Retry in 1 minute at main();tempt N ${this.counter}`
|
||||
);
|
||||
logger.error(`Retry in 1 minute at main();tempt N ${this.counter}`);
|
||||
this.sleep(TIMEOUT);
|
||||
this.checkEnv();
|
||||
await this.checkEnv();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get alfrescoJsApi() {
|
||||
public get alfrescoJsApi(): AlfrescoApi {
|
||||
return this._alfrescoJsApi;
|
||||
}
|
||||
|
||||
public set alfrescoJsApi(alfrescoJsApi: any) {
|
||||
public set alfrescoJsApi(alfrescoJsApi: AlfrescoApi) {
|
||||
this._alfrescoJsApi = alfrescoJsApi;
|
||||
}
|
||||
|
||||
sleep(delay) {
|
||||
sleep(delay: number) {
|
||||
const start = new Date().getTime();
|
||||
while (new Date().getTime() < start + delay) {}
|
||||
}
|
||||
|
@@ -17,13 +17,11 @@
|
||||
|
||||
import { PluginInterface } from './plugin-model';
|
||||
import { GovernanceHealth } from './governance-health';
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
|
||||
export class GovernanceCheckPlugin {
|
||||
governanceHealth: GovernanceHealth;
|
||||
constructor(
|
||||
private pluginInfo: PluginInterface,
|
||||
private alfrescoJsApi: any
|
||||
) {
|
||||
constructor(private pluginInfo: PluginInterface, private alfrescoJsApi: AlfrescoApi) {
|
||||
this.governanceHealth = new GovernanceHealth(this.pluginInfo, this.alfrescoJsApi);
|
||||
}
|
||||
|
||||
|
@@ -19,48 +19,38 @@
|
||||
|
||||
import { logger } from '../logger';
|
||||
import { PluginInterface } from './plugin-model';
|
||||
import { AlfrescoApi, GsSitesApi } from '@alfresco/js-api';
|
||||
|
||||
export class GovernanceHealth {
|
||||
constructor(private pluginInfo: PluginInterface, private alfrescoJsApi: any) {}
|
||||
constructor(private pluginInfo: PluginInterface, private alfrescoJsApi: AlfrescoApi) {}
|
||||
|
||||
async isRecordManagementAvailable() {
|
||||
async isRecordManagementAvailable(): Promise<boolean> {
|
||||
try {
|
||||
const site = await this.alfrescoJsApi.gsCore.gsSitesApi.getRMSite();
|
||||
logger.info(
|
||||
`Record Management site is present: ${site.entry.title}`
|
||||
);
|
||||
const gsSitesApi = new GsSitesApi(this.alfrescoJsApi);
|
||||
const site = await gsSitesApi.getRMSite();
|
||||
logger.info(`Record Management site is present: ${site.entry.title}`);
|
||||
console.table([{ PluginName: this.pluginInfo.name, Status: 'Active', RecordManagement: 'Available' }]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Record Management site get failed: ${
|
||||
JSON.parse(error.message).error.errorKey
|
||||
}`
|
||||
);
|
||||
console.table([{ PluginName: this.pluginInfo.name, Status: 'Inactive', RecordManagement: 'Not available'}]);
|
||||
logger.error(`Record Management site get failed: ${JSON.parse(error.message).error.errorKey}`);
|
||||
console.table([{ PluginName: this.pluginInfo.name, Status: 'Inactive', RecordManagement: 'Not available' }]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async createRecordManagementSite() {
|
||||
async createRecordManagementSite(): Promise<void> {
|
||||
const body = { title: 'Records Management' };
|
||||
const opts = { skipAddToFavorites: false }; // | Flag to indicate whether the RM site should not be added to the user's site favorites.
|
||||
|
||||
try {
|
||||
logger.info('Trying to create Record Management site...');
|
||||
const site = await this.alfrescoJsApi.gsCore.gsSitesApi.createRMSite(
|
||||
body,
|
||||
opts
|
||||
);
|
||||
const gsSitesApi = new GsSitesApi(this.alfrescoJsApi);
|
||||
const site = await gsSitesApi.createRMSite(body, opts);
|
||||
logger.info('Record Management site: created' + site);
|
||||
console.table([{ PluginName: this.pluginInfo.name, Status: 'Active', RecordManagement: 'Created'}]);
|
||||
console.table([{ PluginName: this.pluginInfo.name, Status: 'Active', RecordManagement: 'Created' }]);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Record Management site creation failed: ${
|
||||
JSON.parse(error.message).error.errorKey
|
||||
}`
|
||||
);
|
||||
console.table([{ PluginName: this.pluginInfo.name, Status: 'Inactive', RecordManagement: 'Not created'}]);
|
||||
logger.error(`Record Management site creation failed: ${JSON.parse(error.message).error.errorKey}`);
|
||||
console.table([{ PluginName: this.pluginInfo.name, Status: 'Inactive', RecordManagement: 'Not created' }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,12 +17,10 @@
|
||||
|
||||
import { PluginInterface } from './plugin-model';
|
||||
import { logger } from '../logger';
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
|
||||
export class PluginConfiguration {
|
||||
constructor(
|
||||
private plugInInfo: PluginInterface,
|
||||
private alfrescoJsApi: any
|
||||
) {}
|
||||
constructor(private plugInInfo: PluginInterface, private alfrescoJsApi: AlfrescoApi) {}
|
||||
|
||||
async getAppConfig(url: string) {
|
||||
return this.callCustomApi(url);
|
||||
@@ -52,10 +50,7 @@ export class PluginConfiguration {
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`${this.plugInInfo.host} is not reachable error: `,
|
||||
error
|
||||
);
|
||||
logger.error(`${this.plugInInfo.host} is not reachable error: `, error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
@@ -20,55 +20,49 @@
|
||||
import { PluginInterface } from './plugin-model';
|
||||
import { logger } from '../logger';
|
||||
import { ProcessAutomationHealth } from './process-automation-health';
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
import { exit } from 'node:process';
|
||||
|
||||
export class ProcessAutomationCheckPlugin {
|
||||
processAutomationHealth: ProcessAutomationHealth;
|
||||
|
||||
constructor(
|
||||
private plugInInfo: PluginInterface,
|
||||
private alfrescoJsApi: any
|
||||
) {
|
||||
this.processAutomationHealth = new ProcessAutomationHealth(
|
||||
this.plugInInfo,
|
||||
this.alfrescoJsApi
|
||||
);
|
||||
constructor(private plugInInfo: PluginInterface, private alfrescoJsApi: AlfrescoApi) {
|
||||
this.processAutomationHealth = new ProcessAutomationHealth(this.plugInInfo, this.alfrescoJsApi);
|
||||
}
|
||||
|
||||
async checkProcessAutomationPlugin() {
|
||||
async checkProcessAutomationPlugin(): Promise<void> {
|
||||
let pluginStatus;
|
||||
try {
|
||||
const isPluginEnabled = await this.processAutomationHealth.isPluginEnabledFromAppConfiguration();
|
||||
const isBackendActive = await this.processAutomationHealth.checkBackendHealth();
|
||||
|
||||
if (isPluginEnabled && isBackendActive) {
|
||||
logger.info(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has been correctly configured`
|
||||
);
|
||||
logger.info(`The plugin ${this.plugInInfo.name} has been correctly configured`);
|
||||
|
||||
pluginStatus = [{ PluginName: this.plugInInfo.name, Status: 'Active', BE: 'UP', FE: 'Enabled' }];
|
||||
console.table(pluginStatus);
|
||||
} else {
|
||||
this.logConfigurationError();
|
||||
pluginStatus = [{ PluginName: this.plugInInfo.name, Status: 'Inactive', BE: isBackendActive ? 'UP' : 'DOWN', FE: isPluginEnabled ? 'Enabled' : 'Disabled' }];
|
||||
pluginStatus = [
|
||||
{
|
||||
PluginName: this.plugInInfo.name,
|
||||
Status: 'Inactive',
|
||||
BE: isBackendActive ? 'UP' : 'DOWN',
|
||||
FE: isPluginEnabled ? 'Enabled' : 'Disabled'
|
||||
}
|
||||
];
|
||||
console.table(pluginStatus);
|
||||
process.exit(1);
|
||||
exit(1);
|
||||
}
|
||||
} catch (e) {
|
||||
this.logConfigurationError(e);
|
||||
pluginStatus = [{ PluginName: this.plugInInfo.name, Status: 'Inactive', BE: 'DOWN', FE: 'Disabled' }];
|
||||
console.table(pluginStatus);
|
||||
process.exit(1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private logConfigurationError(error?: any) {
|
||||
logger.error(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has not been correctly configured`,
|
||||
error
|
||||
);
|
||||
private logConfigurationError(error?: any): void {
|
||||
logger.error(`The plugin ${this.plugInInfo.name} has not been correctly configured`, error);
|
||||
}
|
||||
}
|
||||
|
@@ -18,31 +18,22 @@
|
||||
import { PluginInterface } from './plugin-model';
|
||||
import { logger } from '../logger';
|
||||
import { PluginConfiguration } from './plugin-config';
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
|
||||
export class ProcessAutomationHealth {
|
||||
config: PluginConfiguration;
|
||||
|
||||
constructor(
|
||||
private plugInInfo: PluginInterface,
|
||||
private alfrescoJsApi: any
|
||||
) {
|
||||
this.config = new PluginConfiguration(
|
||||
this.plugInInfo,
|
||||
this.alfrescoJsApi
|
||||
);
|
||||
constructor(private plugInInfo: PluginInterface, private alfrescoJsApi: AlfrescoApi) {
|
||||
this.config = new PluginConfiguration(this.plugInInfo, this.alfrescoJsApi);
|
||||
}
|
||||
|
||||
async isPluginEnabledFromAppConfiguration() {
|
||||
async isPluginEnabledFromAppConfiguration(): Promise<boolean> {
|
||||
try {
|
||||
const url = `${this.plugInInfo.host}/${this.plugInInfo.appName}/ui/${this.plugInInfo.uiName}/app.config.json`;
|
||||
const appConfig = await this.config.getAppConfig(url);
|
||||
let isEnabled = true;
|
||||
if (appConfig && appConfig.plugins && appConfig.plugins[this.plugInInfo.name]) {
|
||||
logger.info(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has been correctly configured in app.config.json`
|
||||
);
|
||||
logger.info(`The plugin ${this.plugInInfo.name} has been correctly configured in app.config.json`);
|
||||
} else {
|
||||
this.logConfigurationError();
|
||||
isEnabled = false;
|
||||
@@ -55,7 +46,7 @@ export class ProcessAutomationHealth {
|
||||
}
|
||||
}
|
||||
|
||||
async checkBackendHealth() {
|
||||
async checkBackendHealth(): Promise<boolean> {
|
||||
const url = `${this.plugInInfo.host}/${this.plugInInfo.appName}/rb/actuator/health`;
|
||||
let isBackendActive = true;
|
||||
try {
|
||||
@@ -68,20 +59,12 @@ export class ProcessAutomationHealth {
|
||||
}
|
||||
return isBackendActive;
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`${this.plugInInfo.host} is not reachable error: `,
|
||||
error
|
||||
);
|
||||
logger.error(`${this.plugInInfo.host} is not reachable error: `, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private logConfigurationError(error?: any) {
|
||||
logger.error(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has not been correctly configured in app.config.json`,
|
||||
error
|
||||
);
|
||||
private logConfigurationError(error?: any): void {
|
||||
logger.error(`The plugin ${this.plugInInfo.name} has not been correctly configured in app.config.json`, error);
|
||||
}
|
||||
}
|
||||
|
@@ -20,37 +20,35 @@
|
||||
import { PluginInterface } from './plugin-model';
|
||||
import { logger } from '../logger';
|
||||
import { ProcessServiceHealth } from './process-services-health';
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
|
||||
export class ProcessServiceCheckPlugin {
|
||||
processServiceHealth: ProcessServiceHealth;
|
||||
|
||||
constructor(
|
||||
private plugInInfo: PluginInterface,
|
||||
private alfrescoJsApi: any
|
||||
) {
|
||||
this.processServiceHealth = new ProcessServiceHealth(
|
||||
this.plugInInfo,
|
||||
this.alfrescoJsApi
|
||||
);
|
||||
constructor(private plugInInfo: PluginInterface, private alfrescoJsApi: AlfrescoApi) {
|
||||
this.processServiceHealth = new ProcessServiceHealth(this.plugInInfo, this.alfrescoJsApi);
|
||||
}
|
||||
|
||||
async checkProcessServicesPlugin() {
|
||||
async checkProcessServicesPlugin(): Promise<void> {
|
||||
let pluginStatus;
|
||||
try {
|
||||
const isPluginEnabled = await this.processServiceHealth.isPluginEnabledFromAppConfiguration();
|
||||
const isBackendActive = await this.processServiceHealth.checkBackendHealth();
|
||||
|
||||
if (isPluginEnabled && isBackendActive) {
|
||||
logger.info(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has been correctly configured`
|
||||
);
|
||||
logger.info(`The plugin ${this.plugInInfo.name} has been correctly configured`);
|
||||
pluginStatus = [{ PluginName: this.plugInInfo.name, Status: `${'Active'}`, BE: 'UP', FE: 'Enabled' }];
|
||||
console.table(pluginStatus);
|
||||
} else {
|
||||
this.logConfigurationError();
|
||||
pluginStatus = [{ PluginName: this.plugInInfo.name, Status: 'Inactive', BE: isBackendActive ? 'UP' : 'DOWN', FE: isPluginEnabled ? 'Enabled' : 'Disabled' }];
|
||||
pluginStatus = [
|
||||
{
|
||||
PluginName: this.plugInInfo.name,
|
||||
Status: 'Inactive',
|
||||
BE: isBackendActive ? 'UP' : 'DOWN',
|
||||
FE: isPluginEnabled ? 'Enabled' : 'Disabled'
|
||||
}
|
||||
];
|
||||
console.table(pluginStatus);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -62,12 +60,7 @@ export class ProcessServiceCheckPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private logConfigurationError(error?: any) {
|
||||
logger.error(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has not been correctly configured`,
|
||||
error
|
||||
);
|
||||
private logConfigurationError(error?: any): void {
|
||||
logger.error(`The plugin ${this.plugInInfo.name} has not been correctly configured`, error);
|
||||
}
|
||||
}
|
||||
|
@@ -18,26 +18,22 @@
|
||||
import { PluginInterface } from './plugin-model';
|
||||
import { logger } from '../logger';
|
||||
import { PluginConfiguration } from './plugin-config';
|
||||
import { AlfrescoApi, SystemPropertiesApi } from '@alfresco/js-api';
|
||||
|
||||
export class ProcessServiceHealth {
|
||||
|
||||
config: PluginConfiguration;
|
||||
|
||||
constructor(private plugInInfo: PluginInterface, private alfrescoJsApi: any) {
|
||||
constructor(private plugInInfo: PluginInterface, private alfrescoJsApi: AlfrescoApi) {
|
||||
this.config = new PluginConfiguration(this.plugInInfo, this.alfrescoJsApi);
|
||||
}
|
||||
|
||||
async isPluginEnabledFromAppConfiguration() {
|
||||
async isPluginEnabledFromAppConfiguration(): Promise<boolean> {
|
||||
try {
|
||||
const url = `${this.plugInInfo.host}/app.config.json`;
|
||||
const appConfig = await this.config.getAppConfig(url);
|
||||
let isEnabled = true;
|
||||
if (appConfig && appConfig.plugins && appConfig.plugins[this.plugInInfo.name]) {
|
||||
logger.info(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has been correctly configured in app.config.json`
|
||||
);
|
||||
logger.info(`The plugin ${this.plugInInfo.name} has been correctly configured in app.config.json`);
|
||||
} else {
|
||||
this.logConfigurationError();
|
||||
return (isEnabled = false);
|
||||
@@ -50,9 +46,10 @@ export class ProcessServiceHealth {
|
||||
}
|
||||
}
|
||||
|
||||
async checkBackendHealth() {
|
||||
async checkBackendHealth(): Promise<boolean> {
|
||||
try {
|
||||
const systemProperties = await this.alfrescoJsApi.activiti.systemPropertiesApi.getProperties();
|
||||
const systemPropertiesApi = new SystemPropertiesApi(this.alfrescoJsApi);
|
||||
const systemProperties = await systemPropertiesApi.getProperties();
|
||||
let isBackendActive = true;
|
||||
if (systemProperties) {
|
||||
logger.info(`${this.plugInInfo.host} is UP!`);
|
||||
@@ -62,20 +59,12 @@ export class ProcessServiceHealth {
|
||||
}
|
||||
return isBackendActive;
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`${this.plugInInfo.host} is not reachable error: `,
|
||||
error
|
||||
);
|
||||
logger.error(`${this.plugInInfo.host} is not reachable error: `, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private logConfigurationError(error?: any) {
|
||||
logger.error(
|
||||
`The plugin ${
|
||||
this.plugInInfo.name
|
||||
} has not been correctly configured in app.config.json`,
|
||||
error
|
||||
);
|
||||
private logConfigurationError(error?: any): void {
|
||||
logger.error(`The plugin ${this.plugInInfo.name} has not been correctly configured in app.config.json`, error);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user