FIX: +200 Meltano - Productboard API

This commit is contained in:
Victor Radael
2022-10-05 16:42:41 -03:00
parent 97d6f914cc
commit 9d732d4a48
7 changed files with 110 additions and 1 deletions
+2
View File
@@ -23,6 +23,7 @@ import { HealthModule } from './modules/health/health.module';
import { CatalogModule } from './modules/catalog/catalog.module';
import { ConfigModule } from '@nestjs/config';
import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
import { ProductboardModule } from './productboard/productboard.module';
@Module({
controllers: [],
@@ -54,6 +55,7 @@ import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
OauthModule,
PipelinesV2Module,
CatalogModule,
ProductboardModule,
],
})
export class AppModule {}
+12
View File
@@ -0,0 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';
export class INote {
@ApiProperty()
title: string;
@ApiProperty()
content: string;
@ApiProperty()
tags: string[];
}
@@ -0,0 +1,19 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ProductboardController } from './productboard.controller';
describe('ProductboardController', () => {
let controller: ProductboardController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ProductboardController],
providers: [],
}).compile();
controller = module.get<ProductboardController>(ProductboardController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
@@ -0,0 +1,51 @@
import { Body, Controller, HttpException, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import axios from 'axios';
import { User, RequestUser } from 'src/authentication/user.decorator';
import { getSecreteFromSecreteManager } from 'src/utils/SecretManager';
import { INote } from './dtos';
@ApiTags('Productboard')
@Controller('productboard')
export class ProductboardController {
@Post('notes')
async sendNote(@Body() note: INote, @User() user: RequestUser) {
const { title, content, tags } = note;
const { username, customer_name } = user;
const email = username.includes('@')
? username
: username + `@${customer_name}.default`;
const path = process.env.PB_TOKEN_PATH;
const token = await getSecreteFromSecreteManager(path);
const response = await axios
.post(
`https://api.productboard.com/notes`,
{
title,
content,
tags,
user: {
email,
},
},
{
headers: {
Authorization: 'Bearer ' + token,
},
},
)
.catch(() => null);
if (!response) {
throw new HttpException(
'Your request could not be submitted, please try again in a few moments or contact support.',
502,
);
}
return response.data;
}
}
+8
View File
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { ProductboardController } from './productboard.controller';
@Module({
controllers: [ProductboardController],
providers: [],
})
export class ProductboardModule {}
+17
View File
@@ -0,0 +1,17 @@
import {
SecretsManagerClient,
GetSecretValueCommand,
} from '@aws-sdk/client-secrets-manager';
export async function getSecreteFromSecreteManager(path: string) {
const secretsManagerClient = new SecretsManagerClient({});
const getSecretComand = new GetSecretValueCommand({
SecretId: `${path}`,
});
const res = await secretsManagerClient
.send(getSecretComand)
.catch(() => null);
return res?.SecretString;
}
+1 -1
View File
File diff suppressed because one or more lines are too long