Skip to content
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

Add Network map module #3

Open
wants to merge 4 commits into
base: moving-config-svc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion packages/config-svc-be/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,35 @@ Open a new terminal and run the following command:
curl -X POST "http://localhost:3202/platformRoles/basic-application/add_privileges" \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <New_BearerTOKEN>' \
--data '["SECURITY_CREATE_RULE", "SECURITY_UPDATE_RULE", "SECURITY_GET_RULES", "SECURITY_GET_RULE", "SECURITY_GET_RULE_RULE_CONFIG", "SECURITY_DELETE_RULE", "SECURITY_DISABLE_RULE", "SECURITY_CREATE_RULE_CONFIG", "SECURITY_UPDATE_RULE_CONFIG", "SECURITY_GET_RULE_CONFIGS", "SECURITY_GET_RULE_CONFIG", "SECURITY_DELETE_RULE_CONFIG", "SECURITY_DISABLE_RULE_CONFIG", "SECURITY_CREATE_TYPOLOGY", "SECURITY_UPDATE_TYPOLOGY", "SECURITY_GET_TYPOLOGIES", "SECURITY_GET_TYPOLOGY", "SECURITY_DELETE_TYPOLOGY", "SECURITY_DISABLE_TYPOLOGY"]'
--data '[
"SECURITY_CREATE_RULE",
"SECURITY_UPDATE_RULE",
"SECURITY_GET_RULES",
"SECURITY_GET_RULE",
"SECURITY_GET_RULE_RULE_CONFIG",
"SECURITY_DELETE_RULE",
"SECURITY_DISABLE_RULE",
"SECURITY_CREATE_RULE_CONFIG",
"SECURITY_UPDATE_RULE_CONFIG",
"SECURITY_GET_RULE_CONFIGS",
"SECURITY_GET_RULE_CONFIG",
"SECURITY_DELETE_RULE_CONFIG",
"SECURITY_DISABLE_RULE_CONFIG",
"SECURITY_CREATE_TYPOLOGY",
"SECURITY_UPDATE_TYPOLOGY",
"SECURITY_GET_TYPOLOGIES",
"SECURITY_GET_TYPOLOGY",
"SECURITY_DELETE_TYPOLOGY",
"SECURITY_DISABLE_TYPOLOGY",
"SECURITY_CREATE_NETWORK_MAP",
"SECURITY_UPDATE_NETWORK_MAP",
"SECURITY_GET_NETWORK_MAP",
"SECURITY_APPROVE_NETWORK_MAP",
"SECURITY_IMPORT_NETWORK_MAP",
"SECURITY_EXPORT_NETWORK_MAP",
"SECURITY_DISABLE_NETWORK_MAP",
"SECURITY_DELETE_NETWORK_MAP"
]'
```

- At this time you can test the config-svc-be on <http://localhost:3007/>.
Expand Down
2 changes: 2 additions & 0 deletions packages/config-svc-be/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ArangoDatabaseService } from './arango-database/arango-database.service
import { PrivilegeService } from './privilege/privilege.service';
import { BandModule } from './band/band.module';
import { CaseModule } from './case/case.module';
import { NetworkMapModule } from './network-map/network-map.module';

@Module({
imports: [
Expand All @@ -24,6 +25,7 @@ import { CaseModule } from './case/case.module';
TypologyConfigModule,
BandModule,
CaseModule,
NetworkMapModule,
],
controllers: [AppController],
providers: [AppService, ArangoDatabaseService, PrivilegeService],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
TYPOLOGY_COLLECTION,
typologySchema,
} from '../typology/schema/typology.schema';
import {
NETWORK_MAP_COLLECTION,
networkMapSchema,
} from '../network-map/schema/network-map.schema';

@Injectable()
export class ArangoDatabaseService {
Expand Down Expand Up @@ -64,6 +68,7 @@ export class ArangoDatabaseService {
{ name: RULE_COLLECTION, options: ruleSchema },
{ name: RULE_CONFIG_COLLECTION, options: ruleConfigSchema },
{ name: TYPOLOGY_COLLECTION, options: typologySchema },
{ name: NETWORK_MAP_COLLECTION, options: networkMapSchema },
];

// Iterate over the collection names and create them if they don't exist
Expand Down
168 changes: 168 additions & 0 deletions packages/config-svc-be/src/network-map/dto/create-network-map.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { ApiProperty } from '@nestjs/swagger';
import {
IsArray,
IsBoolean,
IsOptional,
IsString,
ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';

class RuleConfigSummaryDto {
@ApiProperty({
description: 'Database identifier for the rule configuration.',
example: 'rule_config/sample-uuid-4',
})
@IsString()
readonly _id: string;

@ApiProperty({
description: 'Key within the database for the rule configuration.',
example: 'sample-uuid-4',
})
@IsString()
readonly _key: string;

@ApiProperty({
description: 'Version of the rule configuration.',
example: '1.0.0',
})
@IsString()
readonly cfg: string;
}

class RuleSummaryDto {
@ApiProperty({
description: 'Database identifier for the rule.',
example: 'rule/sample-uuid-3',
})
@IsString()
readonly _id: string;

@ApiProperty({
description: 'Key within the database for the rule.',
example: 'sample-uuid-3',
})
@IsString()
readonly _key: string;

@ApiProperty({ description: 'Name of the rule.', example: 'Rule 3' })
@IsString()
readonly name: string;

@ApiProperty({ description: 'Version of the rule.', example: '1.0.0' })
@IsString()
readonly cfg: string;
}

class RulesWithConfigsDto {
@ApiProperty({
description: 'Details of the rule',
type: RuleSummaryDto,
})
@ValidateNested()
@Type(() => RuleSummaryDto)
readonly rule: RuleSummaryDto;

@ApiProperty({
description: 'Configurations associated with the rule.',
type: [RuleConfigSummaryDto],
})
@IsArray()
@IsOptional()
@ValidateNested({ each: true })
@Type(() => RuleConfigSummaryDto)
readonly ruleConfigs?: RuleConfigSummaryDto[];
}

class TypologyDto {
@ApiProperty({
description: 'Typology Processor ID with version.',
example: 'Typology Processor [email protected]',
})
@IsString()
readonly id: string;

@ApiProperty({
description: 'Name of the typology processor.',
example: 'Typology Processor 1',
})
@IsString()
readonly name: string;

@ApiProperty({
description: 'Version of the configuration.',
example: '1.0.0',
})
@IsString()
readonly cfg: string;

@ApiProperty({
description: 'Indicates if the typology processor is active.',
default: false,
})
@IsBoolean()
readonly active: boolean;

@ApiProperty({
description: 'Array of rules with their respective configurations.',
type: [RulesWithConfigsDto],
})
@IsArray()
@IsOptional()
@ValidateNested({ each: true })
@Type(() => RulesWithConfigsDto)
readonly rulesWithConfigs?: RulesWithConfigsDto[];
}

export class CreateEventDto {
@ApiProperty({
description: 'Event ID from the events collection.',
example: 'event/sample-uuid-22',
})
@IsString()
readonly eventId: string;

@ApiProperty({
description: 'Array of typologies associated with the event.',
type: [TypologyDto],
})
@IsArray()
@IsOptional()
@ValidateNested({ each: true })
@Type(() => TypologyDto)
readonly typologies?: TypologyDto[];
}

export class CreateNetworkMapDto {
@ApiProperty({
description: 'Flag to indicate if the network map is active.',
default: false,
})
@IsBoolean()
readonly active: boolean;

@ApiProperty({
description: 'A x.y.z versioning for the network map',
example: '1.0.0',
})
@IsString()
readonly cfg: string;

@ApiProperty({
description: 'Array of events associated with the network map.',
type: [CreateEventDto],
})
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateEventDto)
readonly events: CreateEventDto[];

@ApiProperty({
description: 'Source of the network map.',
example: 'user_created',
})
@IsString()
@IsOptional()
readonly source?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PartialType } from '@nestjs/swagger';
import { CreateNetworkMapDto } from './create-network-map.dto';
import { IsBoolean, IsOptional } from 'class-validator';

export class UpdateNetworkMapDto extends PartialType(CreateNetworkMapDto) {
@IsBoolean()
@IsOptional()
edited?: boolean;
}
Loading