mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-28 05:54:48 +00:00
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { DucClient } from '../duc/client.config';
|
|
import { ClientGrpc } from '@nestjs/microservices';
|
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
import { CustomersProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
|
import { Metadata } from '@grpc/grpc-js';
|
|
import { lastValueFrom } from 'rxjs';
|
|
import { NetworkPoliciesDTO } from './dto/network-policy.dto';
|
|
|
|
|
|
@Injectable()
|
|
export class NetworkPolicyService {
|
|
private customerService: CustomersProtoService;
|
|
private logger: DadosferaLogger;
|
|
|
|
constructor(
|
|
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
onModuleInit() {
|
|
this.customerService = this.grpcClient.getService<CustomersProtoService>(
|
|
ProtoServices.CustomersProtoService,
|
|
);
|
|
}
|
|
|
|
async getByCustomer(id: string): Promise<NetworkPoliciesDTO> {
|
|
const {
|
|
customer
|
|
} = await lastValueFrom(this.customerService.CustomerFindOneById({
|
|
id
|
|
}));
|
|
|
|
return {
|
|
policies: customer.networkPolicies
|
|
}
|
|
}
|
|
|
|
async apply(
|
|
networkPolicies: string[],
|
|
customerId: string,
|
|
metadata: Metadata,
|
|
) {
|
|
return await lastValueFrom(
|
|
this.customerService.CustomerCreateNetworkPolicy(
|
|
{
|
|
customerId,
|
|
networkPolicies,
|
|
},
|
|
metadata,
|
|
),
|
|
);
|
|
}
|
|
|
|
async delete(
|
|
networkPolicies: string[],
|
|
customerId: string,
|
|
metadata: Metadata,
|
|
) {
|
|
return await lastValueFrom(
|
|
this.customerService.CustomerRemoveNetworkPolicy(
|
|
{
|
|
customerId,
|
|
networkPolicies,
|
|
},
|
|
metadata,
|
|
),
|
|
);
|
|
}
|
|
}
|