mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-17 13:29:07 +00:00
Inputs models refactor
This commit is contained in:
@@ -1,29 +1,7 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
|
||||
import { Info } from 'protospack/dist/lib/interfaces';
|
||||
|
||||
export class InputModel {
|
||||
category: string;
|
||||
plugin: string;
|
||||
name: string;
|
||||
cron?: string;
|
||||
credentials?: {
|
||||
connection_type: string;
|
||||
oauth: string;
|
||||
oauth_code: string;
|
||||
start_date: string;
|
||||
};
|
||||
}
|
||||
|
||||
export class FileFormatParams {
|
||||
@ApiProperty()
|
||||
sep: string;
|
||||
@ApiProperty()
|
||||
header: boolean;
|
||||
@ApiProperty()
|
||||
encoding: string;
|
||||
}
|
||||
|
||||
class GoogleAnalyticsClientSecrets {
|
||||
export class GoogleAnalyticsClientSecrets {
|
||||
@ApiProperty()
|
||||
type: string;
|
||||
@ApiProperty()
|
||||
@@ -45,7 +23,7 @@ class GoogleAnalyticsClientSecrets {
|
||||
@ApiProperty()
|
||||
client_x509_cert_url: string;
|
||||
}
|
||||
class OauthObject {
|
||||
export class OauthObject {
|
||||
@ApiPropertyOptional()
|
||||
get_tokens_url: string;
|
||||
@ApiPropertyOptional()
|
||||
@@ -55,7 +33,7 @@ class OauthObject {
|
||||
@ApiPropertyOptional()
|
||||
content_type: string;
|
||||
}
|
||||
class InputOptions {
|
||||
export class InputOptions {
|
||||
@ApiPropertyOptional()
|
||||
oauth: OauthObject;
|
||||
@ApiPropertyOptional()
|
||||
@@ -65,8 +43,22 @@ class InputOptions {
|
||||
@ApiPropertyOptional()
|
||||
skip_transformation: true;
|
||||
}
|
||||
export class FileFormatParams {
|
||||
@ApiProperty()
|
||||
sep: string;
|
||||
@ApiProperty()
|
||||
header: boolean;
|
||||
@ApiProperty()
|
||||
encoding: string;
|
||||
}
|
||||
|
||||
class CredentialsJdbc {
|
||||
export class AuthParameters {
|
||||
@ApiProperty()
|
||||
aws_access_key_id: string;
|
||||
@ApiProperty()
|
||||
aws_secret_access_key: string;
|
||||
}
|
||||
export class CredentialsJdbc {
|
||||
@ApiPropertyOptional()
|
||||
jdbc_user: string;
|
||||
@ApiPropertyOptional()
|
||||
@@ -82,8 +74,7 @@ class CredentialsJdbc {
|
||||
@ApiPropertyOptional()
|
||||
schema: string;
|
||||
}
|
||||
|
||||
class Credentials extends CredentialsJdbc {
|
||||
export class Credentials extends CredentialsJdbc {
|
||||
@ApiProperty()
|
||||
connection_type: string;
|
||||
|
||||
@@ -110,13 +101,13 @@ class Credentials extends CredentialsJdbc {
|
||||
@ApiPropertyOptional()
|
||||
oauth_code: string;
|
||||
}
|
||||
class Column {
|
||||
export class Column {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
type: string;
|
||||
}
|
||||
class TableColumns {
|
||||
export class TableColumns {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
@@ -124,6 +115,45 @@ class TableColumns {
|
||||
@ApiProperty()
|
||||
references: Column[];
|
||||
}
|
||||
|
||||
export class Input {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
@ApiProperty({ type: [TableColumns] })
|
||||
tables: TableColumns[];
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
@ApiPropertyOptional()
|
||||
type?: string;
|
||||
@ApiProperty()
|
||||
created_at: string;
|
||||
@ApiProperty()
|
||||
updated_at: string;
|
||||
|
||||
//deprecated attributes (for retro compatibility)
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
category: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
credentials: Credentials;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
options: InputOptions;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
info: Info;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
cron: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
source_bucket: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
source_prefix: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
auth_parameters: AuthParameters;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
file_format_params: FileFormatParams;
|
||||
}
|
||||
export class GetAvailableEntitiesReq {
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
@@ -167,65 +197,8 @@ export class TestConnectionRes {
|
||||
@ApiProperty()
|
||||
database_tables: string[];
|
||||
}
|
||||
|
||||
export class AuthParameters {
|
||||
@ApiProperty()
|
||||
aws_access_key_id: string;
|
||||
@ApiProperty()
|
||||
aws_secret_access_key: string;
|
||||
}
|
||||
export class CreateInputReq {
|
||||
@ApiProperty({ type: [TableColumns] })
|
||||
tables: TableColumns[];
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
@ApiPropertyOptional()
|
||||
type: string;
|
||||
|
||||
//deprecated attributes (for retro compatibility)
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
category: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
credentials: Credentials;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
options: InputOptions;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
info: Info;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
cron: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
source_bucket: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
source_prefix: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
auth_parameters: AuthParameters;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
file_format_params: FileFormatParams;
|
||||
}
|
||||
|
||||
export class Input {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
@ApiProperty()
|
||||
category: string;
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
cron: string;
|
||||
@ApiProperty()
|
||||
credentials: Credentials;
|
||||
@ApiProperty()
|
||||
client_id: string;
|
||||
@ApiProperty()
|
||||
created_at: string;
|
||||
@ApiProperty()
|
||||
updated_at: string;
|
||||
@ApiPropertyOptional()
|
||||
info: Info;
|
||||
}
|
||||
export class CreateInputReq extends OmitType(Input, [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]) {}
|
||||
|
||||
@@ -149,6 +149,7 @@ export class InputsService {
|
||||
return response;
|
||||
},
|
||||
};
|
||||
|
||||
secondsInADay = 60 * 60 * 24;
|
||||
secondsInAnHour = 60 * 60;
|
||||
|
||||
@@ -163,6 +164,12 @@ export class InputsService {
|
||||
}
|
||||
if (payload.input_s3) return payload.input_s3;
|
||||
if (payload.input_jdbc) return payload.input_jdbc;
|
||||
|
||||
const { credentials } = payload;
|
||||
return {
|
||||
...payload,
|
||||
credentials: credentials && JSON.parse(credentials),
|
||||
};
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
@@ -216,9 +223,11 @@ export class InputsService {
|
||||
const adjustedInput = this.adjustInputPayload(input);
|
||||
return { input: adjustedInput };
|
||||
}
|
||||
|
||||
async getAvailableEntities(data): Promise<{ entities: string[] }> {
|
||||
return await this.OLD_inputClient.getAvailableEntities(data);
|
||||
}
|
||||
|
||||
async findAll(info: Info) {
|
||||
const { inputs } = await lastValueFrom(
|
||||
this.inputReadService.InputFindAll({ info }),
|
||||
@@ -227,31 +236,6 @@ export class InputsService {
|
||||
|
||||
const inputsReturn = inputs.map((i) => this.adjustInputPayload(i));
|
||||
return { inputs: inputsReturn };
|
||||
// findAll: async (data) => {
|
||||
// this.logger.info('InputClientService - FindAll');
|
||||
// const findAllInputResponse = await lastValueFrom(
|
||||
// this.inputReadService.InputFindAll(data),
|
||||
// ).catch((e) => {
|
||||
// this.logger.error(e.details);
|
||||
// throw new HttpException(e.details, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
// });
|
||||
// findAllInputResponse.inputs.forEach((input) => objectCamelToSnake(input));
|
||||
|
||||
// return findAllInputResponse;
|
||||
// },
|
||||
// try {
|
||||
// const findAllInputResponse: any = await this.OLD_inputClient.findAll(
|
||||
// body,
|
||||
// );
|
||||
// if (findAllInputResponse?.inputs?.length) {
|
||||
// findAllInputResponse.inputs = findAllInputResponse.inputs.map((input) =>
|
||||
// this.adjustInputPayload(input),
|
||||
// );
|
||||
// }
|
||||
// return findAllInputResponse;
|
||||
// } catch (err) {
|
||||
// throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
||||
// }
|
||||
}
|
||||
|
||||
async findOne(idRequest: IIdRequest) {
|
||||
|
||||
@@ -10,11 +10,25 @@ export class PipelinesService {
|
||||
constructor(private pipelineClient: PipelinesClientService) {}
|
||||
|
||||
adjustPayload(payload) {
|
||||
if (payload.input?.input_generic) {
|
||||
payload.input = DecodeGrpcStruct(payload.input?.input_generic);
|
||||
} else {
|
||||
payload.input = payload.input?.input_s3 || payload.input?.input_jdbc;
|
||||
const { input } = payload;
|
||||
if (input) {
|
||||
if (input.input_generic) {
|
||||
const { credentials } = input.input_generic;
|
||||
return {
|
||||
...input.input_generic,
|
||||
credentials: credentials && JSON.parse(credentials),
|
||||
};
|
||||
}
|
||||
if (input.input_s3) return input.input_s3;
|
||||
if (input.input_jdbc) return input.input_jdbc;
|
||||
|
||||
const { credentials } = input;
|
||||
return {
|
||||
...input,
|
||||
credentials: credentials && JSON.parse(credentials),
|
||||
};
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
async create(createPipelineDto) {
|
||||
|
||||
@@ -196,6 +196,15 @@ export function EnrichErrorCode(code: string) {
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.CONNECTION_TEST.BAD_REQUEST:
|
||||
return {
|
||||
statusCode: HttpStatus.BAD_REQUEST,
|
||||
error: 'Erro ao testar conexão',
|
||||
message:
|
||||
'Verifique se todas as informações foram preenchidas corretamente',
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.INTERNAL:
|
||||
case ErrorCodes.UNKNOWN:
|
||||
default:
|
||||
|
||||
@@ -42,6 +42,7 @@ const CONNECTION_TEST = {
|
||||
ERROR: 'CONNECTION_TEST.ERROR',
|
||||
EXPIRED: 'CONNECTION_TEST.EXPIRED',
|
||||
TIMEOUT: 'CONNECTION_TEST.TIMEOUT',
|
||||
BAD_REQUEST: 'CONNECTION_TEST.BAD_REQUEST',
|
||||
UNKNOWN: 'CONNECTION_TEST.UNKNOWN',
|
||||
};
|
||||
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user