From 867325501ecfa3eab9960d86a9ab97997df4329c Mon Sep 17 00:00:00 2001 From: Valur Einarsson Date: Wed, 11 Dec 2024 13:37:26 +0000 Subject: [PATCH] Enable getting fake users in v3 client. Configure for ids-api envs. --- apps/services/auth/ids-api/infra/ids-api.ts | 5 +++ .../auth/ids-api/src/app/app.module.ts | 6 +++- .../app/user-profile/user-profile.service.ts | 14 ++++++-- charts/identity-server/values.dev.yaml | 1 + charts/identity-server/values.prod.yaml | 1 + charts/identity-server/values.staging.yaml | 1 + .../services-auth-ids-api/values.dev.yaml | 1 + .../services-auth-ids-api/values.prod.yaml | 1 + .../services-auth-ids-api/values.staging.yaml | 1 + .../lib/delegations/alive-status.service.ts | 20 +++++++++-- .../v3/src/lib/nationalRegistryV3.service.ts | 35 +++++++++++++------ 11 files changed, 70 insertions(+), 16 deletions(-) diff --git a/apps/services/auth/ids-api/infra/ids-api.ts b/apps/services/auth/ids-api/infra/ids-api.ts index 1afda547b717..b4f06d72ee64 100644 --- a/apps/services/auth/ids-api/infra/ids-api.ts +++ b/apps/services/auth/ids-api/infra/ids-api.ts @@ -100,6 +100,11 @@ export const serviceSetup = (): ServiceBuilder<'services-auth-ids-api'> => { staging: 'digitaliceland', dev: 'digitaliceland', }, + ALSO_USE_FAKE_USER_API: { + dev: 'true', + staging: 'false', + prod: 'false', + }, }) .secrets({ ZENDESK_CONTACT_FORM_EMAIL: '/k8s/api/ZENDESK_CONTACT_FORM_EMAIL', diff --git a/apps/services/auth/ids-api/src/app/app.module.ts b/apps/services/auth/ids-api/src/app/app.module.ts index b1cfb1b1506c..60b34ac48694 100644 --- a/apps/services/auth/ids-api/src/app/app.module.ts +++ b/apps/services/auth/ids-api/src/app/app.module.ts @@ -1,4 +1,5 @@ import { Module } from '@nestjs/common' +import { ConfigModule as NestConfigModule } from '@nestjs/config' import { SequelizeModule } from '@nestjs/sequelize' import { @@ -13,6 +14,7 @@ import { NationalRegistryV3ClientConfig } from '@island.is/clients/national-regi import { CompanyRegistryConfig } from '@island.is/clients/rsk/company-registry' import { SyslumennClientConfig } from '@island.is/clients/syslumenn' import { UserProfileClientConfig } from '@island.is/clients/user-profile' +import { ZendeskServiceConfig } from '@island.is/clients/zendesk' import { AuditModule } from '@island.is/nest/audit' import { ConfigModule, @@ -35,7 +37,6 @@ import { ResourcesModule } from './resources/resources.module' import { TranslationModule } from './translation/translation.module' import { UserProfileModule } from './user-profile/user-profile.module' import { UsersModule } from './users/users.module' -import { ZendeskServiceConfig } from '@island.is/clients/zendesk' @Module({ imports: [ @@ -56,6 +57,9 @@ import { ZendeskServiceConfig } from '@island.is/clients/zendesk' NotificationsModule, LoginRestrictionsModule, PasskeysModule, + NestConfigModule.forRoot({ + ignoreEnvFile: true, + }), ConfigModule.forRoot({ isGlobal: true, load: [ diff --git a/apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts b/apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts index 626b782bb437..67da94832ea2 100644 --- a/apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts +++ b/apps/services/auth/ids-api/src/app/user-profile/user-profile.service.ts @@ -1,4 +1,5 @@ -import { Inject, Injectable } from '@nestjs/common' +import { Inject, Injectable, Optional } from '@nestjs/common' +import { ConfigService } from '@nestjs/config' import { AuthMiddleware } from '@island.is/auth-nest-tools' import { FetchError } from '@island.is/clients/middlewares' @@ -30,6 +31,7 @@ type CountryFormatter = { of: (countryCode: string) => string } @Injectable() export class UserProfileService { + alsoUseFakeApi = false // REMOVE these ignores after upgrading to TypeScript 4.5 // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore @@ -45,7 +47,14 @@ export class UserProfileService { private companyRegistryApi: CompanyRegistryClientService, @Inject(LOGGER_PROVIDER) private logger: Logger, - ) {} + @Optional() + readonly configService?: ConfigService, + ) { + if (configService) { + this.alsoUseFakeApi = + configService.get('ALSO_USE_FAKE_USER_API') ?? false + } + } userProfileApiWithAuth(auth: Auth) { return this.userProfileApi.withMiddleware(new AuthMiddleware(auth)) @@ -123,6 +132,7 @@ export class UserProfileService { const individual = await this.nationalRegistryV3.getAllDataIndividual( auth.nationalId, false, + this.alsoUseFakeApi, ) if (!individual) { diff --git a/charts/identity-server/values.dev.yaml b/charts/identity-server/values.dev.yaml index a5d5ce51e239..47834b587715 100644 --- a/charts/identity-server/values.dev.yaml +++ b/charts/identity-server/values.dev.yaml @@ -414,6 +414,7 @@ services-auth-delegation-api: services-auth-ids-api: enabled: true env: + ALSO_USE_FAKE_USER_API: 'true' CODE_OWNER: 'aranja' COMPANY_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379"]' COMPANY_REGISTRY_XROAD_PROVIDER_ID: 'IS-DEV/GOV/10006/Skatturinn/ft-v1' diff --git a/charts/identity-server/values.prod.yaml b/charts/identity-server/values.prod.yaml index 2f51a29e6326..a350ead4e04b 100644 --- a/charts/identity-server/values.prod.yaml +++ b/charts/identity-server/values.prod.yaml @@ -411,6 +411,7 @@ services-auth-delegation-api: services-auth-ids-api: enabled: true env: + ALSO_USE_FAKE_USER_API: 'false' CODE_OWNER: 'aranja' COMPANY_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379"]' COMPANY_REGISTRY_XROAD_PROVIDER_ID: 'IS/GOV/5402696029/Skatturinn/ft-v1' diff --git a/charts/identity-server/values.staging.yaml b/charts/identity-server/values.staging.yaml index 00cbc00e4a90..b02c94cd26d5 100644 --- a/charts/identity-server/values.staging.yaml +++ b/charts/identity-server/values.staging.yaml @@ -414,6 +414,7 @@ services-auth-delegation-api: services-auth-ids-api: enabled: true env: + ALSO_USE_FAKE_USER_API: 'false' CODE_OWNER: 'aranja' COMPANY_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379"]' COMPANY_REGISTRY_XROAD_PROVIDER_ID: 'IS-TEST/GOV/5402696029/Skatturinn/ft-v1' diff --git a/charts/services/services-auth-ids-api/values.dev.yaml b/charts/services/services-auth-ids-api/values.dev.yaml index e1461ecdd4a9..12367bce8312 100644 --- a/charts/services/services-auth-ids-api/values.dev.yaml +++ b/charts/services/services-auth-ids-api/values.dev.yaml @@ -19,6 +19,7 @@ global: name: 'services-auth-ids-api' enabled: true env: + ALSO_USE_FAKE_USER_API: 'true' CODE_OWNER: 'aranja' COMPANY_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379"]' COMPANY_REGISTRY_XROAD_PROVIDER_ID: 'IS-DEV/GOV/10006/Skatturinn/ft-v1' diff --git a/charts/services/services-auth-ids-api/values.prod.yaml b/charts/services/services-auth-ids-api/values.prod.yaml index 48b414b22bb9..8f72bda2431f 100644 --- a/charts/services/services-auth-ids-api/values.prod.yaml +++ b/charts/services/services-auth-ids-api/values.prod.yaml @@ -19,6 +19,7 @@ global: name: 'services-auth-ids-api' enabled: true env: + ALSO_USE_FAKE_USER_API: 'false' CODE_OWNER: 'aranja' COMPANY_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379"]' COMPANY_REGISTRY_XROAD_PROVIDER_ID: 'IS/GOV/5402696029/Skatturinn/ft-v1' diff --git a/charts/services/services-auth-ids-api/values.staging.yaml b/charts/services/services-auth-ids-api/values.staging.yaml index 5b620fa22960..1e1e45950161 100644 --- a/charts/services/services-auth-ids-api/values.staging.yaml +++ b/charts/services/services-auth-ids-api/values.staging.yaml @@ -19,6 +19,7 @@ global: name: 'services-auth-ids-api' enabled: true env: + ALSO_USE_FAKE_USER_API: 'false' CODE_OWNER: 'aranja' COMPANY_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379"]' COMPANY_REGISTRY_XROAD_PROVIDER_ID: 'IS-TEST/GOV/5402696029/Skatturinn/ft-v1' diff --git a/libs/auth-api-lib/src/lib/delegations/alive-status.service.ts b/libs/auth-api-lib/src/lib/delegations/alive-status.service.ts index e1e4aeceb170..57139bda3fc2 100644 --- a/libs/auth-api-lib/src/lib/delegations/alive-status.service.ts +++ b/libs/auth-api-lib/src/lib/delegations/alive-status.service.ts @@ -1,4 +1,5 @@ -import { Inject, Injectable, Logger } from '@nestjs/common' +import { Inject, Injectable, Logger, Optional } from '@nestjs/common' +import { ConfigService } from '@nestjs/config' import * as kennitala from 'kennitala' import { NationalRegistryClientService } from '@island.is/clients/national-registry-v2' @@ -20,13 +21,22 @@ const decesead = 'LÉST' @Injectable() export class AliveStatusService { + alsoUseFakeApi = false + constructor( private readonly nationalRegistryClient: NationalRegistryClientService, private readonly nationalRegistryV3Client: NationalRegistryV3ClientService, private readonly companyRegistryClient: CompanyRegistryClientService, @Inject(LOGGER_PROVIDER) private logger: Logger, - ) {} + @Optional() + readonly configService?: ConfigService, + ) { + if (configService) { + this.alsoUseFakeApi = + configService.get('ALSO_USE_FAKE_USER_API') ?? false + } + } /** * Divides nationalIds into alive and deceased @@ -134,7 +144,11 @@ export class AliveStatusService { ): Promise { if (useNationalRegistryV3) { return await this.nationalRegistryV3Client - .getAllDataIndividual(individualInfo.nationalId) + .getAllDataIndividual( + individualInfo.nationalId, + false, + this.alsoUseFakeApi, + ) .then((individual) => { if ( individual && diff --git a/libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts b/libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts index 1f8e09ec369e..fec86cce0731 100644 --- a/libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts +++ b/libs/clients/national-registry/v3/src/lib/nationalRegistryV3.service.ts @@ -34,19 +34,34 @@ export class NationalRegistryV3ClientService { ) } - getAllDataIndividual( + async getAllDataIndividual( nationalId: string, - useFakeApi?: boolean, + useFakeApiOnly?: boolean, + alsoTryFakeApiWhenNotFound?: boolean, ): Promise { - return useFakeApi - ? this.fakeApi.midlunV1GerviEinstaklingarNationalIdGet({ + if (useFakeApiOnly) { + return handle204( + this.fakeApi.midlunV1GerviEinstaklingarNationalIdGetRaw({ nationalId, - }) - : handle204( - this.individualApi.midlunV1EinstaklingarNationalIdGetRaw({ - nationalId, - }), - ) + }), + ) + } + + const result = await handle204( + this.individualApi.midlunV1EinstaklingarNationalIdGetRaw({ + nationalId, + }), + ) + + if (!result && alsoTryFakeApiWhenNotFound) { + return handle204( + this.fakeApi.midlunV1GerviEinstaklingarNationalIdGetRaw({ + nationalId, + }), + ) + } + + return result } getBiologicalFamily(