Skip to content

Commit

Permalink
chore(application-system): Refactor env config (#15096)
Browse files Browse the repository at this point in the history
* Data Protection config refactor

* remove unused variable

* Criminal Record client config refactor

* HealthInsurance client config refactor

* remove logging

* Vmst client config refactor

* Data Protection config refactor

* remove unused variable

* Criminal Record client config refactor

* Vmst refactor

* clean up

* Health insurance client config refactor

* client path fix

* Revert "Vmst client config refactor"

This reverts commit d2855b7.

* basePath update

* vmst client refactor round 2

* Data Protection config refactor

* remove unused variable

* Criminal Record client config refactor

* Vmst refactor

* clean up

* Health insurance client config refactor

* client path fix

* Data Protection config refactor

* remove unused variable

* Criminal Record client config refactor

* HealthInsurance client config refactor

* Vmst client config refactor

* Revert "Vmst client config refactor"

This reverts commit d2855b7.

* vmst client refactor round 2

* Doublicate key clean up

* fallback value for env

* Fallback for env variables

* chore: nx format:write update dirty files

* Update tests to use new module config

* Propper mock values

* Force feature deploy

* clean up

* typo fix and other minor clean up

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and sigruntg committed Jun 14, 2024
1 parent 5560aa2 commit 217cb64
Show file tree
Hide file tree
Showing 37 changed files with 405 additions and 504 deletions.
26 changes: 9 additions & 17 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ import {
import { HousingBenefitsConfig } from '@island.is/clients/hms-housing-benefits'
import { UserProfileClientConfig } from '@island.is/clients/user-profile'
import { UltravioletRadiationClientConfig } from '@island.is/clients/ultraviolet-radiation'
import { CriminalRecordClientConfig } from '@island.is/clients/criminal-record'
import { HealthInsuranceV2ClientConfig } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { VmstClientConfig } from '@island.is/clients/vmst'

const environment = getConfig

Expand Down Expand Up @@ -223,7 +226,7 @@ const environment = getConfig
baseApiUrl: environment.applicationSystem.baseApiUrl!,
}),
LicenseServiceModule,
DirectorateOfLabourModule.register(),
DirectorateOfLabourModule,
FileUploadModule,
DocumentModule,
DocumentProviderModule.register({
Expand All @@ -246,15 +249,7 @@ const environment = getConfig
}),
CmsTranslationsModule,
TerminusModule,
HealthInsuranceModule.register({
clientV2Config: {
xRoadBaseUrl: environment.healthInsuranceV2.xRoadBaseUrl!,
xRoadProviderId: environment.healthInsuranceV2.xRoadProviderId!,
xRoadClientId: environment.healthInsuranceV2.xRoadClientId!,
username: environment.healthInsuranceV2.username!,
password: environment.healthInsuranceV2.password!,
},
}),
HealthInsuranceModule,
UserProfileModule.register({
islykill: {
cert: environment.islykill.cert!,
Expand Down Expand Up @@ -309,13 +304,7 @@ const environment = getConfig
ApiDomainsPaymentModule,
PaymentScheduleModule,
ProblemModule,
CriminalRecordModule.register({
clientConfig: {
xroadBaseUrl: environment.xroad.baseUrl!,
xroadClientId: environment.xroad.clientId!,
xroadPath: environment.criminalRecord.xroadPath!,
},
}),
CriminalRecordModule,
MunicipalitiesFinancialAidModule,
FishingLicenseModule,
MortgageCertificateModule,
Expand Down Expand Up @@ -414,6 +403,9 @@ const environment = getConfig
LicenseConfig,
UserProfileClientConfig,
UltravioletRadiationClientConfig,
VmstClientConfig,
HealthInsuranceV2ClientConfig,
CriminalRecordClientConfig,
],
}),
],
Expand Down
25 changes: 0 additions & 25 deletions apps/api/src/app/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const prodConfig = () => ({
: process.env.XROAD_DRIVING_LICENSE_V2_PATH,
},
},
criminalRecord: {
xroadPath: process.env.XROAD_CRIMINAL_RECORD_PATH,
},
education: {
xroadLicenseServiceId: process.env.XROAD_MMS_LICENSE_SERVICE_ID,
xroadGradeServiceId: process.env.XROAD_MMS_GRADE_SERVICE_ID,
Expand All @@ -42,13 +39,6 @@ const prodConfig = () => ({
clientID: process.env.XROAD_CLIENT_ID,
xroadID: process.env.XROAD_HEALTH_INSURANCE_ID,
},
healthInsuranceV2: {
xRoadBaseUrl: process.env.XROAD_BASE_PATH,
xRoadClientId: process.env.XROAD_CLIENT_ID,
xRoadProviderId: process.env.XROAD_HEALTH_INSURANCE_ID,
username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME,
password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD,
},
auth: {
issuer: process.env.IDENTITY_SERVER_ISSUER_URL,
audience: ['@island.is', '@admin.island.is'],
Expand Down Expand Up @@ -129,11 +119,6 @@ const devConfig = () => ({
'r1/IS-DEV/GOV/10005/Logreglan-Protected/RafraentOkuskirteini-v2',
},
},
criminalRecord: {
xroadPath:
process.env.XROAD_CRIMINAL_RECORD_PATH ??
'r1/IS-DEV/GOV/10005/Logreglan-Protected/Sakavottord-PDF-v2',
},
education: {
xroadLicenseServiceId: 'IS-DEV/GOV/10066/MMS-Protected/license-api-v1',
xroadGradeServiceId: 'IS-DEV/GOV/10066/MMS-Protected/grade-api-v1',
Expand All @@ -152,16 +137,6 @@ const devConfig = () => ({
clientID: process.env.XROAD_CLIENT_ID ?? '',
xroadID: process.env.XROAD_HEALTH_INSURANCE_ID ?? '',
},
healthInsuranceV2: {
xRoadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8080',
xRoadClientId:
process.env.XROAD_CLIENT_ID ?? 'IS-DEV/GOV/10000/island-is-client',
xRoadProviderId:
process.env.XROAD_HEALTH_INSURANCE_ID ??
'IS-DEV/GOV/10007/SJUKRA-Protected',
username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME ?? '',
password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD ?? '',
},
auth: {
issuer: 'https://identity-server.dev01.devland.is',
audience: ['@island.is', '@admin.island.is'],
Expand Down
8 changes: 8 additions & 0 deletions apps/application-system/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import { SignatureCollectionClientConfig } from '@island.is/clients/signature-co
import { InnaClientConfig } from '@island.is/clients/inna'
import { OfficialJournalOfIcelandClientConfig } from '@island.is/clients/official-journal-of-iceland'
import { OfficialJournalOfIcelandApplicationClientConfig } from '@island.is/clients/official-journal-of-iceland/application'
import { DataProtectionComplaintClientConfig } from '@island.is/clients/data-protection-complaint'
import { CriminalRecordClientConfig } from '@island.is/clients/criminal-record'
import { HealthInsuranceV2ClientConfig } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { VmstClientConfig } from '@island.is/clients/vmst'

@Module({
imports: [
Expand Down Expand Up @@ -79,6 +83,10 @@ import { OfficialJournalOfIcelandApplicationClientConfig } from '@island.is/clie
InnaClientConfig,
OfficialJournalOfIcelandClientConfig,
OfficialJournalOfIcelandApplicationClientConfig,
DataProtectionComplaintClientConfig,
CriminalRecordClientConfig,
HealthInsuranceV2ClientConfig,
VmstClientConfig,
],
}),
],
Expand Down
48 changes: 0 additions & 48 deletions apps/application-system/api/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,11 @@ const devConfig = {
password: process.env.NOVA_PASSWORD,
acceptUnauthorized: true,
},
criminalRecord: {
clientConfig: {
xroadClientId:
process.env.XROAD_CLIENT_ID ?? 'IS-DEV/GOV/10000/island-is-client',
xroadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8081',
xroadPath:
process.env.XROAD_CRIMINAL_RECORD_PATH ??
'r1/IS-DEV/GOV/10005/Logreglan-Protected/Sakavottord-PDF-v2',
},
},
presignBucket: process.env.FILE_SERVICE_PRESIGN_BUCKET,
attachmentBucket: process.env.APPLICATION_ATTACHMENT_BUCKET,
generalPetition: {
endorsementsApiBasePath: 'http://localhost:4246',
},
healthInsuranceV2: {
xRoadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8080',
xRoadProviderId:
process.env.XROAD_HEALTH_INSURANCE_ID ??
'IS-DEV/GOV/10007/SJUKRA-Protected',
xRoadClientId:
process.env.XROAD_CLIENT_ID ?? 'IS-DEV/GOV/10000/island-is-client',
username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME ?? '',
password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD ?? '',
},
dataProtectionComplaint: {
password: process.env.DATA_PROTECTION_COMPLAINT_API_PASSWORD,
username: process.env.DATA_PROTECTION_COMPLAINT_API_USERNAME,
XRoadProviderId: process.env.DATA_PROTECTION_COMPLAINT_XROAD_PROVIDER_ID,
xRoadClientId: process.env.XROAD_CLIENT_ID,
xRoadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8080',
},
userProfile: {
serviceBasePath: 'http://localhost:3366',
},
Expand Down Expand Up @@ -123,30 +96,9 @@ const prodConfig = {
},
presignBucket: process.env.FILE_SERVICE_PRESIGN_BUCKET,
attachmentBucket: process.env.APPLICATION_ATTACHMENT_BUCKET,
criminalRecord: {
clientConfig: {
xroadClientId: process.env.XROAD_CLIENT_ID,
xroadBaseUrl: process.env.XROAD_BASE_PATH,
xroadPath: process.env.XROAD_CRIMINAL_RECORD_PATH,
},
},
generalPetition: {
endorsementsApiBasePath: process.env.ENDORSEMENTS_API_BASE_PATH,
},
healthInsuranceV2: {
xRoadBaseUrl: process.env.XROAD_BASE_PATH,
xRoadProviderId: process.env.XROAD_HEALTH_INSURANCE_ID,
xRoadClientId: process.env.XROAD_CLIENT_ID,
username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME,
password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD,
},
dataProtectionComplaint: {
password: process.env.DATA_PROTECTION_COMPLAINT_API_PASSWORD,
username: process.env.DATA_PROTECTION_COMPLAINT_API_USERNAME,
XRoadProviderId: process.env.DATA_PROTECTION_COMPLAINT_XROAD_PROVIDER_ID,
xRoadClientId: process.env.XROAD_CLIENT_ID,
xRoadBaseUrl: process.env.XROAD_BASE_PATH,
},
userProfile: {
serviceBasePath: process.env.SERVICE_USER_PROFILE_URL,
},
Expand Down
28 changes: 8 additions & 20 deletions libs/api/domains/criminal-record/src/lib/criminalRecord.module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import { Module, DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'

import { CriminalRecordService } from './criminalRecord.service'
import {
CriminalRecordApiModule,
CriminalRecordApiConfig,
} from '@island.is/clients/criminal-record'
import { CriminalRecordApiModule } from '@island.is/clients/criminal-record'

export interface Config {
clientConfig: CriminalRecordApiConfig
}

@Module({})
export class CriminalRecordModule {
static register(config: Config): DynamicModule {
return {
module: CriminalRecordModule,
providers: [CriminalRecordService],
imports: [CriminalRecordApiModule.register(config.clientConfig)],
exports: [CriminalRecordService],
}
}
}
@Module({
providers: [CriminalRecordService],
exports: [CriminalRecordService],
imports: [CriminalRecordApiModule],
})
export class CriminalRecordModule {}
28 changes: 19 additions & 9 deletions libs/api/domains/criminal-record/src/lib/criminalRecord.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
requestHandlers,
} from './__mock-data__/requestHandlers'
import { startMocking } from '@island.is/shared/mocking'
import { createLogger } from 'winston'
import { ConfigModule } from '@nestjs/config'
import { defineConfig } from '@island.is/nest/config'

startMocking(requestHandlers)

Expand All @@ -17,15 +18,24 @@ describe('CriminalRecordService', () => {
beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [
CriminalRecordApiModule.register({
xroadBaseUrl: 'http://localhost',
xroadClientId: '',
xroadPath: 'v2',
fetchOptions: {
logger: createLogger({
silent: true,
CriminalRecordApiModule,
ConfigModule.forRoot({
isGlobal: true,
load: [
defineConfig({
name: 'CriminalRecordClient',
load: () => ({
xRoadServicePath: 'v2',
}),
}),
},
defineConfig({
name: 'XRoadConfig',
load: () => ({
xRoadBasePath: 'http://localhost',
xRoadClient: '',
}),
}),
],
}),
],
providers: [CriminalRecordService, { provide: 'CONFIG', useValue: {} }],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
import { DynamicModule, Module } from '@nestjs/common'

import { Module } from '@nestjs/common'
import { VMSTModule } from '@island.is/clients/vmst'
import {
createXRoadAPIPath,
XRoadMemberClass,
} from '@island.is/shared/utils/server'

import { DirectorateOfLabourRepository } from './directorate-of-labour.repository'
import { DirectorateOfLabourResolver } from './directorate-of-labour.resolver'
import { DirectorateOfLabourService } from './directorate-of-labour.service'

const XROAD_BASE_PATH_WITH_ENV = process.env.XROAD_BASE_PATH_WITH_ENV ?? ''
const XROAD_VMST_MEMBER_CODE = process.env.XROAD_VMST_MEMBER_CODE ?? ''
const XROAD_VMST_API_PATH = process.env.XROAD_VMST_API_PATH ?? ''
const XROAD_VMST_API_KEY = process.env.XROAD_VMST_API_KEY ?? ''
const XROAD_CLIENT_ID = process.env.XROAD_CLIENT_ID ?? ''
const XROAD_VMST_MEMBER_CLASS = XRoadMemberClass.GovernmentInstitution

@Module({})
export class DirectorateOfLabourModule {
static register(): DynamicModule {
return {
module: DirectorateOfLabourModule,
providers: [
DirectorateOfLabourResolver,
DirectorateOfLabourService,
DirectorateOfLabourRepository,
],
imports: [
VMSTModule.register({
xRoadPath: createXRoadAPIPath(
XROAD_BASE_PATH_WITH_ENV,
XROAD_VMST_MEMBER_CLASS,
XROAD_VMST_MEMBER_CODE,
XROAD_VMST_API_PATH,
),
xRoadClient: XROAD_CLIENT_ID,
apiKey: XROAD_VMST_API_KEY,
}),
],
exports: [],
}
}
}
@Module({
providers: [
DirectorateOfLabourResolver,
DirectorateOfLabourService,
DirectorateOfLabourRepository,
],
imports: [VMSTModule],
})
export class DirectorateOfLabourModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { apiDomainsHealthInsurance } from './api-domains-health-insurance'
import { Test } from '@nestjs/testing'
import { HealthInsuranceService } from './healthInsurance.service'
import {
HealthInsuranceV2Client,
HealthInsuranceV2Options,
HealthInsuranceV2ClientConfig,
HealthInsuranceV2ClientModule,
} from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { logger, LOGGER_PROVIDER } from '@island.is/logging'
import { ConfigModule } from '@nestjs/config'
import { XRoadConfig } from '@island.is/nest/config'

describe('apiDomainsHealthInsurance', () => {
it('should work', () => {
Expand All @@ -14,22 +16,16 @@ describe('apiDomainsHealthInsurance', () => {
})

describe('healthInsuranceTest', () => {
interface HealthInsuranceOptions {
clientV2Config: HealthInsuranceV2Options
}
const options: HealthInsuranceOptions = {
clientV2Config: {
xRoadBaseUrl: 'http://localhost:8080',
password: '',
username: '',
xRoadClientId: '',
xRoadProviderId: '',
},
}
let service: HealthInsuranceService
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
imports: [HealthInsuranceV2Client.register(options.clientV2Config)],
imports: [
HealthInsuranceV2ClientModule,
ConfigModule.forRoot({
isGlobal: true,
load: [HealthInsuranceV2ClientConfig, XRoadConfig],
}),
],
providers: [
{
provide: LOGGER_PROVIDER,
Expand Down
Loading

0 comments on commit 217cb64

Please sign in to comment.