Skip to content

Commit

Permalink
Merge branch 'develop' into feature/3929-indexer-enhancements
Browse files Browse the repository at this point in the history
Signed-off-by: Dariy Miseldzhani <[email protected]>
  • Loading branch information
Dariy Miseldzhani committed Jan 31, 2025
2 parents b1f03ca + 2d91f34 commit 5c4bebf
Show file tree
Hide file tree
Showing 228 changed files with 20,508 additions and 3,766 deletions.
505 changes: 505 additions & 0 deletions api-gateway/src/api/service/formulas.ts

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions api-gateway/src/api/service/schema-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IAuthUser, PinoLogger } from '@guardian/common';
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Post, Put, Query, Response } from '@nestjs/common';
import { Permissions, UserPermissions } from '@guardian/interfaces';
import { ApiBody, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiTags, ApiQuery, ApiExtraModels, ApiParam } from '@nestjs/swagger';
import { Examples, InternalServerErrorDTO, SchemaRuleDTO, SchemaRuleDataDTO, SchemaRuleRelationshipsDTO, pageHeader } from '#middlewares';
import { Examples, InternalServerErrorDTO, SchemaRuleDTO, SchemaRuleDataDTO, SchemaRuleOptionsDTO, SchemaRuleRelationshipsDTO, pageHeader } from '#middlewares';
import { Guardians, InternalException, EntityOwner } from '#helpers';
import { AuthUser, Auth } from '#auth';

Expand Down Expand Up @@ -390,24 +390,25 @@ export class SchemaRulesApi {
description: '',
})
@ApiBody({
description: 'Configuration.',
type: SchemaRuleDataDTO,
description: 'Options.',
type: SchemaRuleOptionsDTO,
required: true
})
@ApiOkResponse({
description: 'Successful operation.',
type: SchemaRuleDataDTO,
isArray: true
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO,
})
@ApiExtraModels(SchemaRuleDataDTO, InternalServerErrorDTO)
@ApiExtraModels(SchemaRuleOptionsDTO, SchemaRuleDataDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.CREATED)
async getSchemaRuleData(
@AuthUser() user: IAuthUser,
@Body() options: any
): Promise<SchemaRuleDataDTO> {
@Body() options: SchemaRuleOptionsDTO
): Promise<SchemaRuleDataDTO[]> {
try {
if (!options) {
throw new HttpException('Invalid config.', HttpStatus.UNPROCESSABLE_ENTITY);
Expand Down
2 changes: 2 additions & 0 deletions api-gateway/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { PolicyStatisticsApi } from './api/service/policy-statistics.js';
import { SchemaRulesApi } from './api/service/schema-rules.js';
import { loggerMongoProvider, pinoLoggerProvider } from './helpers/providers/index.js';
import { PolicyLabelsApi } from './api/service/policy-labels.js';
import { FormulasApi } from './api/service/formulas.js';

// const JSON_REQUEST_LIMIT = process.env.JSON_REQUEST_LIMIT || '1mb';
// const RAW_REQUEST_LIMIT = process.env.RAW_REQUEST_LIMIT || '1gb';
Expand Down Expand Up @@ -97,6 +98,7 @@ import { PolicyLabelsApi } from './api/service/policy-labels.js';
PermissionsApi,
PolicyStatisticsApi,
SchemaRulesApi,
FormulasApi,
PolicyLabelsApi,
WorkerTasksController
],
Expand Down
167 changes: 149 additions & 18 deletions api-gateway/src/helpers/guardians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
IToken,
ITokenInfo,
IUser,
IVC,
IVCDocument,
IVPDocument,
MessageAPI,
Expand Down Expand Up @@ -49,7 +48,12 @@ import {
PolicyLabelRelationshipsDTO,
PolicyLabelDocumentRelationshipsDTO,
PolicyLabelComponentsDTO,
PolicyLabelFiltersDTO
PolicyLabelFiltersDTO,
FormulaDTO,
SchemaRuleOptionsDTO,
FormulasOptionsDTO,
FormulasDataDTO,
FormulaRelationshipsDTO
} from '#middlewares';

/**
Expand Down Expand Up @@ -2953,7 +2957,7 @@ export class Guardians extends NatsService {
* @param definition
* @param owner
*
* @returns theme
* @returns statistic
*/
public async updateStatisticDefinition(
definitionId: string,
Expand Down Expand Up @@ -2981,7 +2985,7 @@ export class Guardians extends NatsService {
* @param definitionId
* @param owner
*
* @returns Operation Success
* @returns statistic
*/
public async publishStatisticDefinition(definitionId: string, owner: IOwner): Promise<StatisticDefinitionDTO> {
return await this.sendMessage(MessageAPI.PUBLISH_STATISTIC_DEFINITION, { definitionId, owner });
Expand Down Expand Up @@ -3028,7 +3032,7 @@ export class Guardians extends NatsService {
* @param assessmentId
* @param owner
*
* @returns Operation Success
* @returns assessment
*/
public async getStatisticAssessment(
definitionId: string,
Expand All @@ -3045,7 +3049,7 @@ export class Guardians extends NatsService {
* @param assessmentId
* @param owner
*
* @returns Operation Success
* @returns relationships
*/
public async getStatisticAssessmentRelationships(
definitionId: string,
Expand Down Expand Up @@ -3111,7 +3115,7 @@ export class Guardians extends NatsService {
*
* @param ruleId
* @param owner
* @returns Operation Success
* @returns schema rule
*/
public async getSchemaRuleById(ruleId: string, owner: IOwner): Promise<SchemaRuleDTO> {
return await this.sendMessage(MessageAPI.GET_SCHEMA_RULE, { ruleId, owner });
Expand All @@ -3136,7 +3140,7 @@ export class Guardians extends NatsService {
* @param definition
* @param owner
*
* @returns theme
* @returns schema rule
*/
public async updateSchemaRule(
ruleId: string,
Expand Down Expand Up @@ -3164,7 +3168,7 @@ export class Guardians extends NatsService {
* @param ruleId
* @param owner
*
* @returns Operation Success
* @returns schema rule
*/
public async activateSchemaRule(ruleId: string, owner: IOwner): Promise<SchemaRuleDTO> {
return await this.sendMessage(MessageAPI.ACTIVATE_SCHEMA_RULE, { ruleId, owner });
Expand All @@ -3176,7 +3180,7 @@ export class Guardians extends NatsService {
* @param ruleId
* @param owner
*
* @returns Operation Success
* @returns schema rule
*/
public async inactivateSchemaRule(ruleId: string, owner: IOwner): Promise<SchemaRuleDTO> {
return await this.sendMessage(MessageAPI.INACTIVATE_SCHEMA_RULE, { ruleId, owner });
Expand All @@ -3188,9 +3192,9 @@ export class Guardians extends NatsService {
* @param options
* @param owner
*
* @returns Operation Success
* @returns Schema Rule Data
*/
public async getSchemaRuleData(options: any, owner: IOwner): Promise<SchemaRuleDataDTO> {
public async getSchemaRuleData(options: SchemaRuleOptionsDTO, owner: IOwner): Promise<SchemaRuleDataDTO[]> {
return await this.sendMessage(MessageAPI.GET_SCHEMA_RULE_DATA, { options, owner });
}

Expand Down Expand Up @@ -3222,7 +3226,6 @@ export class Guardians extends NatsService {
return await this.sendMessage(MessageAPI.PREVIEW_SCHEMA_RULE_FILE, { zip, owner });
}


/**
* Get Indexer availability
*/
Expand Down Expand Up @@ -3258,7 +3261,7 @@ export class Guardians extends NatsService {
*
* @param definitionId
* @param owner
* @returns Operation Success
* @returns policy label
*/
public async getPolicyLabelById(definitionId: string, owner: IOwner): Promise<PolicyLabelDTO> {
return await this.sendMessage(MessageAPI.GET_POLICY_LABEL, { definitionId, owner });
Expand All @@ -3283,7 +3286,7 @@ export class Guardians extends NatsService {
* @param label
* @param owner
*
* @returns theme
* @returns policy label
*/
public async updatePolicyLabel(
definitionId: string,
Expand Down Expand Up @@ -3311,7 +3314,7 @@ export class Guardians extends NatsService {
* @param definitionId
* @param owner
*
* @returns Operation Success
* @returns policy label
*/
public async publishPolicyLabel(definitionId: string, owner: IOwner): Promise<PolicyLabelDTO> {
return await this.sendMessage(MessageAPI.PUBLISH_POLICY_LABEL, { definitionId, owner });
Expand Down Expand Up @@ -3450,7 +3453,7 @@ export class Guardians extends NatsService {
* @param documentId
* @param owner
*
* @returns Operation Success
* @returns policy label document
*/
public async getLabelDocument(
definitionId: string,
Expand All @@ -3469,7 +3472,7 @@ export class Guardians extends NatsService {
* @param documentId
* @param owner
*
* @returns Operation Success
* @returns relationships
*/
public async getLabelDocumentRelationships(
definitionId: string,
Expand All @@ -3480,4 +3483,132 @@ export class Guardians extends NatsService {
{ definitionId, documentId, owner }
);
}

/**
* Create formula
*
* @param formula
* @param owner
*
* @returns formula
*/
public async createFormula(formula: FormulaDTO, owner: IOwner): Promise<FormulaDTO> {
return await this.sendMessage(MessageAPI.CREATE_FORMULA, { formula, owner });
}

/**
* Return formulas
*
* @param filters
* @param owner
*
* @returns {ResponseAndCount<FormulaDTO>}
*/
public async getFormulas(filters: IFilter, owner: IOwner): Promise<ResponseAndCount<FormulaDTO>> {
return await this.sendMessage(MessageAPI.GET_FORMULAS, { filters, owner });
}

/**
* Get formula
*
* @param formulaId
* @param owner
* @returns formula
*/
public async getFormulaById(formulaId: string, owner: IOwner): Promise<FormulaDTO> {
return await this.sendMessage(MessageAPI.GET_FORMULA, { formulaId, owner });
}

/**
* Update formula
*
* @param formulaId
* @param definition
* @param owner
*
* @returns formula
*/
public async updateFormula(
formulaId: string,
formula: FormulaDTO,
owner: IOwner
): Promise<FormulaDTO> {
return await this.sendMessage(MessageAPI.UPDATE_FORMULA, { formulaId, formula, owner });
}

/**
* Delete formula
*
* @param formulaId
* @param owner
*
* @returns Operation Success
*/
public async deleteFormula(formulaId: string, owner: IOwner): Promise<boolean> {
return await this.sendMessage(MessageAPI.DELETE_FORMULA, { formulaId, owner });
}

/**
* Load formula file for import
* @param zip
* @param owner
*/
public async importFormula(zip: any, policyId: string, owner: IOwner): Promise<any> {
return await this.sendMessage(MessageAPI.IMPORT_FORMULA_FILE, { zip, policyId, owner });
}

/**
* Get formula export file
* @param formulaId
* @param owner
*/
public async exportFormula(formulaId: string, owner: IOwner) {
const file = await this.sendMessage(MessageAPI.EXPORT_FORMULA_FILE, { formulaId, owner }) as any;
return Buffer.from(file, 'base64');
}

/**
* Get formula info from file
* @param zip
* @param owner
*/
public async previewFormula(zip: any, owner: IOwner) {
return await this.sendMessage(MessageAPI.PREVIEW_FORMULA_FILE, { zip, owner });
}

/**
* Get formula relationships
*
* @param formulaId
* @param owner
*
* @returns Operation Success
*/
public async getFormulaRelationships(formulaId: string, owner: IOwner): Promise<FormulaRelationshipsDTO> {
return await this.sendMessage(MessageAPI.GET_FORMULA_RELATIONSHIPS, { formulaId, owner });
}

/**
* Get Formulas Data
*
* @param options
* @param owner
*
* @returns Formulas Data
*/
public async getFormulasData(options: FormulasOptionsDTO, owner: IOwner): Promise<FormulasDataDTO> {
return await this.sendMessage(MessageAPI.GET_FORMULAS_DATA, { options, owner });
}

/**
* Publish Formula
*
* @param formulaId
* @param owner
*
* @returns statistic
*/
public async publishFormula(formulaId: string, owner: IOwner): Promise<FormulaDTO> {
return await this.sendMessage(MessageAPI.PUBLISH_FORMULA, { formulaId, owner });
}
}
Loading

0 comments on commit 5c4bebf

Please sign in to comment.