Skip to content

Commit

Permalink
Fix credentials for CRA api call (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Sep 20, 2023
1 parent 9dc3355 commit 74ab30f
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 286 deletions.
20 changes: 0 additions & 20 deletions src/config/customer-risk-assessment.config.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/config/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Body, Controller, Get, Post} from "@nestjs/common";
import {ApiPropertyOptional, ApiTags} from "@nestjs/swagger";

import {
Cp4adminCustomerRiskAssessmentCustomerRiskAssessmentApiFactory,
customerRiskAssessmentConfig,
CustomerRiskAssessmentRisk0020AssessmentInput
} from "../../services/customer-risk-assessment";
import {customerRiskAssessmentConfig} from "../../config";
import {ApiPropertyOptional, ApiTags} from "@nestjs/swagger";
import {MenuOptionsApi} from "../../services";

class CustomerRiskAssessmentInput implements CustomerRiskAssessmentRisk0020AssessmentInput {
Expand Down
8 changes: 3 additions & 5 deletions src/controllers/kyc-summary/kyc-summary.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {AxiosResponse} from "axios";
import {Body, Controller, Post, UploadedFile, UseInterceptors} from "@nestjs/common";
import {ApiConsumes, ApiHeader, ApiParam, ApiProperty, ApiTags} from "@nestjs/swagger";

import {kycCaseSummaryConfig} from "../../config";
import {DefaultApiFactory, Entity, IDefaultApi} from "../../services";
import {FileInterceptor} from "@nestjs/platform-express";
import {SwaggerEnumType} from "@nestjs/swagger/dist/types/swagger-enum.type";
import {ApiConsumes, ApiProperty, ApiTags} from "@nestjs/swagger";

import {DefaultApiFactory, Entity, IDefaultApi, kycCaseSummaryConfig} from "../../services";

class EntityData implements Entity {
@ApiProperty()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as https from "https";
import {Configuration} from "./configuration";

let _instance: Configuration;
export const customerRiskAssessmentConfig = (): Configuration => {
if (_instance) {
return _instance;
}

const username = process.env.CRA_USERNAME;
const password = process.env.CRA_PASSWORD;
const apiKey = process.env.CRA_API_KEY;

const buildAuthorization = () => {
if (username && apiKey) {
const token = Buffer.from(`${username}:${apiKey}`).toString('base64')

return `ZenApiKey ${token}`
}

const token = Buffer.from(`${username}:${password}`).toString('base64')

return `Basic ${token}`
}

_instance = new Configuration({
username,
password,
apiKey,
basePath: process.env.CRA_BASE_PATH,
baseOptions: {
httpsAgent: new https.Agent({
rejectUnauthorized: false
}),
headers: {
'Authorization': buildAuthorization()
}
}
});

if (!(_instance.username && _instance.password) && !_instance.apiKey) {
throw new Error('CRA_USERNAME, CRA_PASSWORD, and/or CRA_API_KEY not set');
}

return _instance;
}
1 change: 1 addition & 0 deletions src/services/customer-risk-assessment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
export * from "./api";
export * from "./configuration";
export * from "./models";
export * from './customer-risk-assessment.config';

2 changes: 1 addition & 1 deletion src/services/kyc-case-summary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
export * from "./api";
export * from "./configuration";
export * from "./models";

export * from './kyc-summary.config';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Configuration} from "../services/kyc-case-summary";
import {Configuration} from "./configuration";

let _instance: Configuration;
export const kycCaseSummaryConfig = (): Configuration => {
Expand Down
18 changes: 10 additions & 8 deletions src/services/kyc-case/kyc-case-management.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ import {
ReviewCaseModel
} from "../../models";
import {delay, first, streamToBuffer, urlToStream} from "../../utils";
import {Cp4adminCustomerRiskAssessmentCustomerRiskAssessmentApiFactory} from "../customer-risk-assessment";
import {customerRiskAssessmentConfig, kycCaseSummaryConfig} from "../../config";
import {
Cp4adminCustomerRiskAssessmentCustomerRiskAssessmentApiFactory,
customerRiskAssessmentConfig
} from "../customer-risk-assessment";
import {NegativeNewsApi} from "../negative-news";
import {DefaultApiFactory} from "../kyc-case-summary";
import {DefaultApiFactory, kycCaseSummaryConfig} from "../kyc-case-summary";
import {NegativeNewsImpl} from "../negative-news/negative-news.impl";

const initialValue: KycCaseModel[] = [
{
id: '1',
customer: {
name: 'John Doe',
countryOfResidence: 'US',
countryOfResidence: 'United States',
personalIdentificationNumber: '123458690',
entityType: '02',
industryType: '92.00',
entityType: 'Private Limited Company',
industryType: 'Growing of rice',
},
status: 'New',
documents: [],
Expand All @@ -47,8 +49,8 @@ const initialValue: KycCaseModel[] = [
name: 'Jane Doe',
countryOfResidence: 'CA',
personalIdentificationNumber: 'AB1458690',
entityType: '03',
industryType: '10.82/2',
entityType: 'Sole Trader',
industryType: 'Extraction of crude petroleum',
},
status: 'New',
documents: [],
Expand Down
Loading

0 comments on commit 74ab30f

Please sign in to comment.