mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-18 23:49:09 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8623b88df | ||
|
|
92aab57d37 | ||
|
|
e5d9ac2fbf | ||
|
|
9cc538cdcd |
+3
-1
@@ -28,6 +28,7 @@ import { MixpanelModule } from './modules/mixpanel/mixpanel.module';
|
|||||||
import { CustomersModule } from './modules/customers/customers.module';
|
import { CustomersModule } from './modules/customers/customers.module';
|
||||||
import { OpenDataModule } from './modules/open-data/open-data.module';
|
import { OpenDataModule } from './modules/open-data/open-data.module';
|
||||||
import { ThemeModule } from './modules/theme/theme.module';
|
import { ThemeModule } from './modules/theme/theme.module';
|
||||||
|
import { NetworkPolicyModule } from './modules/network-policy/network-policy.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
@@ -62,7 +63,8 @@ import { ThemeModule } from './modules/theme/theme.module';
|
|||||||
OpenDataModule,
|
OpenDataModule,
|
||||||
ThemeModule,
|
ThemeModule,
|
||||||
//Always leave HealthModule last, so it is on the bottom of swagger
|
//Always leave HealthModule last, so it is on the bottom of swagger
|
||||||
HealthModule
|
HealthModule,
|
||||||
|
NetworkPolicyModule
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -88,9 +88,10 @@ export class AuthController {
|
|||||||
async signIn(
|
async signIn(
|
||||||
@Body() { username, password, totp }: AuthSignInReq,
|
@Body() { username, password, totp }: AuthSignInReq,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
|
@Headers('host') host: string
|
||||||
): Promise<AuthSignInRes> {
|
): Promise<AuthSignInRes> {
|
||||||
this.logger.info('/auth - SignIn');
|
this.logger.info('/auth - SignIn');
|
||||||
const metadata = PackTheMetadata({ language });
|
const metadata = PackTheMetadata({ language, host });
|
||||||
return this.authClient.signIn({ username, password, totp }, metadata);
|
return this.authClient.signIn({ username, password, totp }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +101,7 @@ export class AuthController {
|
|||||||
async refreshAccessToken(
|
async refreshAccessToken(
|
||||||
@Body() body: AuthRefreshAccessTokenReq,
|
@Body() body: AuthRefreshAccessTokenReq,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
|
@Headers('host') host: string
|
||||||
) {
|
) {
|
||||||
this.logger.info('/auth - RefreshAccessToken');
|
this.logger.info('/auth - RefreshAccessToken');
|
||||||
const { refreshToken, customerName: customer_name } = body;
|
const { refreshToken, customerName: customer_name } = body;
|
||||||
@@ -107,6 +109,7 @@ export class AuthController {
|
|||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
customer_name,
|
customer_name,
|
||||||
language,
|
language,
|
||||||
|
host
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.authClient.refreshAccessToken({ refreshToken }, metadata);
|
return this.authClient.refreshAccessToken({ refreshToken }, metadata);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
|
||||||
|
export class NetworkPoliciesDTO {
|
||||||
|
@ApiProperty()
|
||||||
|
policies: string []
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { Body, Controller, Delete, HttpCode, HttpStatus, Post } from '@nestjs/common';
|
||||||
|
import { ApiOkResponse } from '@nestjs/swagger';
|
||||||
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/decorators/authentication.decorator';
|
||||||
|
import { NetworkPoliciesDTO } from './dto/network-policy.dto';
|
||||||
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
|
import { NetworkPolicyService } from './network-policy.service';
|
||||||
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
|
||||||
|
@Controller('network-policy')
|
||||||
|
export class NetworkPolicyController {
|
||||||
|
constructor(private networkPolicyService: NetworkPolicyService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
@Authenticated()
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
|
@ApiOkResponse()
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async applyNetworkPolicies(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body() data: NetworkPoliciesDTO,
|
||||||
|
) {
|
||||||
|
const metadata = PackTheMetadata(user);
|
||||||
|
|
||||||
|
return await this.networkPolicyService.apply(
|
||||||
|
data.policies,
|
||||||
|
user.customer_id,
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete()
|
||||||
|
@Authenticated()
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
|
@ApiOkResponse()
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async removeNetworkPolicies(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body() data: NetworkPoliciesDTO,
|
||||||
|
) {
|
||||||
|
const metadata = PackTheMetadata(user);
|
||||||
|
|
||||||
|
return await this.networkPolicyService.delete(
|
||||||
|
data.policies,
|
||||||
|
user.customer_id,
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { NetworkPolicyController } from './network-policy.controller';
|
||||||
|
import { NetworkPolicyService } from './network-policy.service';
|
||||||
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
|
const ducClient = new DucClient();
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ClientsModule.register([
|
||||||
|
ducClient.providerOptions
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
controllers: [NetworkPolicyController],
|
||||||
|
providers: [NetworkPolicyService, DadosferaLogger]
|
||||||
|
})
|
||||||
|
export class NetworkPolicyModule {}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
@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 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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ interface IMetadata {
|
|||||||
roles?: string[];
|
roles?: string[];
|
||||||
is_data_manager?: boolean;
|
is_data_manager?: boolean;
|
||||||
access_token?: string;
|
access_token?: string;
|
||||||
|
host?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PackTheMetadata(info: IMetadata): Metadata {
|
export function PackTheMetadata(info: IMetadata): Metadata {
|
||||||
|
|||||||
Reference in New Issue
Block a user