Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RiXelanya committed Feb 16, 2024
1 parent edec330 commit 446da40
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 66 deletions.
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import dotenv from 'dotenv';
dotenv.config();

export const config = {
DEBIO_API_KEY: process.env.DEBIO_API_KEY ?? '',
RECAPTCHA_SECRET_KEY : process.env.RECAPTCHA_SECRET_KEY ?? '',
REDIS_HOST : process.env.HOST_REDIS ?? 'localhost',
REDIS_PORT : process.env.PORT_REDIS ?? '6379',
REDIS_PASSWORD : process.env.REDIS_PASSWORD ?? 'root',
Expand All @@ -23,5 +25,10 @@ export const config = {
ADMIN_SUBSTRATE_MNEMONIC : process.env.ADMIN_SUBSTRATE_MNEMONIC ?? '',
BUCKET_NAME : process.env.BUCKET_NAME ?? '',
STORAGE_BASE_URI : process.env.STORAGE_BASE_URI ?? '',
MYRIAD_API_URL : process.env.MYRIAD_API_URL ?? '',
MYRIAD_ADMIN_USERNAME : process.env.MYRIAD_ADMIN_USERNAME ?? '',
MYRIAD_PHYSICAL_HEALTH_TIMELINE_ID : process.env.PHYSICAL_HEALTH_EXPERIENCE_ID ?? '',
MYRIAD_MENTAL_HEALTH_TIMELINE_ID : process.env.MENTAL_HEALTH_EXPERIENCE_ID ?? '',
PINATA_JWT : process.env.PINATA_SECRET_KEY ?? ''

};
12 changes: 5 additions & 7 deletions src/endpoints/conversion/conversion.module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { HttpModule } from '@nestjs/axios';
import { CacheModule, Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-redis-store';
import { DebioConversionModule } from 'src/common';
import { keyList } from '../../common/secrets';
import { CacheController } from './conversion.controller';
import { config } from 'src/config';

@Module({
imports: [
CacheModule.registerAsync({
inject: [GCloudSecretManagerService],
inject: [],
useFactory: async (
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
return {
store: redisStore,
host: gCloudSecretManagerService.getSecret('REDIS_HOST'),
port: gCloudSecretManagerService.getSecret('REDIS_PORT'),
auth_pass: gCloudSecretManagerService.getSecret('REDIS_PASSWORD'),
host: config.REDIS_HOST,
port: config.REDIS_PORT,
auth_pass: config.REDIS_PASSWORD,
ttl: 2 * 60 * 60,
};
},
Expand Down
11 changes: 5 additions & 6 deletions src/endpoints/myriad/myriad.module.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { keyList } from '@common/secrets';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { CacheModule, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MyriadAccount } from './models/myriad-account.entity';
import { MyriadController } from './myriad.controller';
import { MyriadService } from './myriad.service';
import * as redisStore from 'cache-manager-redis-store';
import { config } from 'src/config';

@Module({
imports: [
CacheModule.registerAsync({
inject: [GCloudSecretManagerService],
inject: [],
useFactory: async (
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
return {
store: redisStore,
host: gCloudSecretManagerService.getSecret('REDIS_HOST'),
port: gCloudSecretManagerService.getSecret('REDIS_PORT'),
auth_pass: gCloudSecretManagerService.getSecret('REDIS_PASSWORD'),
host: config.REDIS_HOST,
port: config.REDIS_PORT,
auth_pass: config.REDIS_PASSWORD,
ttl: 2 * 60 * 60,
};
},
Expand Down
23 changes: 6 additions & 17 deletions src/endpoints/myriad/myriad.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { keyList } from '@common/secrets';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import {
CACHE_MANAGER,
Inject,
Expand All @@ -23,6 +22,7 @@ import { UserMyriadInterface } from './interface/user';
import { UsernameCheckInterface } from './interface/username-check';
import { MyriadAccount } from './models/myriad-account.entity';
import { Cache } from 'cache-manager';
import { config } from 'src/config';

@Injectable()
export class MyriadService {
Expand All @@ -32,12 +32,9 @@ export class MyriadService {
constructor(
@InjectRepository(MyriadAccount)
private readonly myriadAccountRepository: Repository<MyriadAccount>,
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
) {
this.myriadEndPoints = this.gCloudSecretManagerService
.getSecret('MYRIAD_API_URL')
.toString();
this.myriadEndPoints = config.MYRIAD_API_URL.toString();
}

public async checkUsernameMyriad(username: string): Promise<boolean> {
Expand Down Expand Up @@ -68,9 +65,7 @@ export class MyriadService {
const user = await this.myriadAccountRepository.findOne({
select: ['username', 'jwt_token'],
where: {
username: this.gCloudSecretManagerService
.getSecret('MYRIAD_ADMIN_USERNAME')
.toString(),
username: config.MYRIAD_ADMIN_USERNAME.toString(),
},
});

Expand Down Expand Up @@ -583,9 +578,7 @@ export class MyriadService {
const user = await this.myriadAccountRepository.findOne({
select: ['username', 'jwt_token'],
where: {
username: this.gCloudSecretManagerService
.getSecret('MYRIAD_ADMIN_USERNAME')
.toString(),
username: config.MYRIAD_ADMIN_USERNAME.toString(),
},
});

Expand Down Expand Up @@ -616,13 +609,9 @@ export class MyriadService {

private getExperienceIdAdmin(type: string): string {
if (type === E_PostType.PHYSICAL_HEALTH) {
return this.gCloudSecretManagerService
.getSecret('MYRIAD_PHYSICAL_HEALTH_TIMELINE_ID')
.toString();
return config.MYRIAD_PHYSICAL_HEALTH_TIMELINE_ID.toString();
} else if (type === E_PostType.MENTAL_HEALTH) {
return this.gCloudSecretManagerService
.getSecret('MYRIAD_MENTAL_HEALTH_TIMELINE_ID')
.toString();
return config.MYRIAD_MENTAL_HEALTH_TIMELINE_ID.toString();
} else {
throw new HttpException(
{
Expand Down
11 changes: 4 additions & 7 deletions src/endpoints/pinata/pinata.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Injectable } from '@nestjs/common';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList } from '../../common/secrets';
import axios from 'axios';
import { AxiosRequestConfig } from 'axios';
import FormData from 'form-data';
import { config } from 'src/config';

@Injectable()
export class PinataService {
constructor(
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) {}
async uploadToPinata(file: Express.Multer.File) {
const options = {
Expand All @@ -30,19 +29,17 @@ export class PinataService {
data.append('pinataMetadata', JSON.stringify(options.pinataMetadata));
data.append('pinataOptions', JSON.stringify(options.pinataOptions));

const config: AxiosRequestConfig = {
const configuration: AxiosRequestConfig = {
method: 'POST',
url: 'https://api.pinata.cloud/pinning/pinFileToIPFS',
headers: {
Authorization: this.gCloudSecretManagerService
.getSecret('PINATA_JWT')
.toString(),
Authorization: config.PINATA_JWT.toString(),
...data.getHeaders(),
},
data: data,
};

const res = await axios(config);
const res = await axios(configuration);

return res;
}
Expand Down
8 changes: 2 additions & 6 deletions src/endpoints/recaptcha/recaptcha.controller.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { Body, Controller, Post, Res, UseInterceptors } from '@nestjs/common';
import axios from 'axios';
import { Response } from 'express';
import { keyList } from '../../common/secrets';
import { SentryInterceptor } from '../../common/interceptors';
import { config } from 'src/config';

@UseInterceptors(SentryInterceptor)
@Controller('recaptcha')
export class RecaptchaController {
constructor(
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) {}

@Post()
async recaptcha(@Body() payload: any, @Res() response: Response) {
const result = await axios.post(
'https://www.google.com/recaptcha/api/siteverify' +
'?secret=' +
this.gCloudSecretManagerService
.getSecret('RECAPTCHA_SECRET_KEY')
.toString() +
config.RECAPTCHA_SECRET_KEY.toString() +
'&response=' +
payload.response,
);
Expand Down
12 changes: 5 additions & 7 deletions src/endpoints/second-opinion/second-opinion.module.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { keyList } from '@common/secrets';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { CacheModule, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { HealthProfessionalRole } from './models/health-professional-role.entity';
import { HealthProfessionalSpecialization } from './models/health-professional-specialization.entity';
import { SecondOpinionController } from './second-opinion.controller';
import { SecondOpinionService } from './second-opinion.service';
import * as redisStore from 'cache-manager-redis-store';
import { config } from 'src/config';

@Module({
imports: [
CacheModule.registerAsync({
inject: [GCloudSecretManagerService],
inject: [],
useFactory: async (
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
return {
store: redisStore,
host: gCloudSecretManagerService.getSecret('REDIS_HOST'),
port: gCloudSecretManagerService.getSecret('REDIS_PORT'),
auth_pass: gCloudSecretManagerService.getSecret('REDIS_PASSWORD'),
host: config.REDIS_HOST,
port: config.REDIS_PORT,
auth_pass: config.REDIS_PASSWORD,
ttl: 2 * 60 * 60,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import {
geneticAnalysisByTrakingIdResponse,
geneticAnalysisOrderByGA,
} from './models/response';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList } from '../../common/secrets';
import { MenstrualSubscriptionService } from './services/menstrual-subscription.service';
import { config } from 'src/config';

@Controller('substrate')
@UseInterceptors(SentryInterceptor)
Expand All @@ -51,7 +51,6 @@ export class SubstrateController {
private readonly labService: LabService,
private readonly serviceService: ServiceService,
private readonly orderService: OrderService,
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
private readonly serviceRequestService: ServiceRequestService,
private readonly geneticAnalysisService: GeneticAnalysisService,
private readonly geneticAnalysisOrderService: GeneticAnalysisOrderService,
Expand Down Expand Up @@ -407,7 +406,7 @@ export class SubstrateController {
) {
if (
debioApiKey !==
this.gCloudSecretManagerService.getSecret('DEBIO_API_KEY').toString()
config.DEBIO_API_KEY.toString()
) {
return response.status(401).send('debio-api-key header is required');
}
Expand Down Expand Up @@ -444,7 +443,7 @@ export class SubstrateController {

if (
debioApiKey !=
this.gCloudSecretManagerService.getSecret('DEBIO_API_KEY').toString()
config.DEBIO_API_KEY.toString()
) {
return response.status(401).send('debio-api-key header is required');
}
Expand Down
9 changes: 4 additions & 5 deletions src/endpoints/verification/verification.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import {
Body,
Controller,
Expand All @@ -16,12 +15,12 @@ import { SentryInterceptor } from '../../common';
import { VerificationService } from './verification.service';
import { VerificationStatus } from '@debionetwork/polkadot-provider/lib/primitives';
import { HealthProfessionalRegisterDTO } from './dto/health-professional.dto';
import { config } from 'src/config';

@UseInterceptors(SentryInterceptor)
@Controller('verification')
export class VerificationController {
constructor(
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
private readonly verificationService: VerificationService,
) {}

Expand All @@ -41,7 +40,7 @@ export class VerificationController {
try {
if (
debioApiKey !=
this.gCloudSecretManagerService.getSecret('DEBIO_API_KEY').toString()
config.DEBIO_API_KEY.toString()
) {
return response.status(401).send('debio-api-key header is required');
}
Expand Down Expand Up @@ -77,7 +76,7 @@ export class VerificationController {
try {
if (
debioApiKey !=
this.gCloudSecretManagerService.getSecret('DEBIO_API_KEY').toString()
config.DEBIO_API_KEY.toString()
) {
return response.status(401).send('debio-api-key header is required');
}
Expand All @@ -104,7 +103,7 @@ export class VerificationController {
) {
if (
debioApiKey !=
this.gCloudSecretManagerService.getSecret('DEBIO_API_KEY').toString()
config.DEBIO_API_KEY.toString()
) {
throw new HttpException(
{
Expand Down
12 changes: 5 additions & 7 deletions src/endpoints/verification/verification.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ import { VerificationService } from './verification.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MyriadAccount } from '@endpoints/myriad/models/myriad-account.entity';
import * as redisStore from 'cache-manager-redis-store';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList } from '@common/secrets';
import { MyriadModule } from '@endpoints/myriad/myriad.module';
import { config } from 'src/config';

@Module({
imports: [
CacheModule.registerAsync({
inject: [GCloudSecretManagerService],
inject: [],
useFactory: async (
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
return {
store: redisStore,
host: gCloudSecretManagerService.getSecret('REDIS_HOST'),
port: gCloudSecretManagerService.getSecret('REDIS_PORT'),
auth_pass: gCloudSecretManagerService.getSecret('REDIS_PASSWORD'),
host: config.REDIS_HOST,
port: config.REDIS_PORT,
auth_pass: config.REDIS_PASSWORD,
ttl: 2 * 60 * 60,
};
},
Expand Down

0 comments on commit 446da40

Please sign in to comment.