From 3719969ce9ecfd26e746c8602049f5034cf44321 Mon Sep 17 00:00:00 2001 From: valurefugl <65780958+valurefugl@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:23:18 +0000 Subject: [PATCH] feat(ids-api): Enable getting fake users in v3 client. Configure for ids-api envs. (#17201) * Enable getting fake users in v3 client. Configure for ids-api envs. * Remove configmodule import. * Declare property in constructor, use optional chaining. * Fix optional decorator. * Move declaration. --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/services/auth/ids-api/infra/ids-api.ts | 5 +++ .../auth/ids-api/src/app/app.module.ts | 2 +- .../app/user-profile/user-profile.service.ts | 12 +++++-- 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 | 18 ++++++++-- .../v3/src/lib/nationalRegistryV3.service.ts | 35 +++++++++++++------ 11 files changed, 62 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..16198e21f08d 100644 --- a/apps/services/auth/ids-api/src/app/app.module.ts +++ b/apps/services/auth/ids-api/src/app/app.module.ts @@ -13,6 +13,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 +36,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: [ 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..9479bd021332 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: boolean // REMOVE these ignores after upgrading to TypeScript 4.5 // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore @@ -45,7 +47,12 @@ export class UserProfileService { private companyRegistryApi: CompanyRegistryClientService, @Inject(LOGGER_PROVIDER) private logger: Logger, - ) {} + @Optional() + readonly configService?: ConfigService, + ) { + this.alsoUseFakeApi = + configService?.get('ALSO_USE_FAKE_USER_API') ?? false + } userProfileApiWithAuth(auth: Auth) { return this.userProfileApi.withMiddleware(new AuthMiddleware(auth)) @@ -123,6 +130,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..c960148f83a9 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,20 @@ const decesead = 'LÉST' @Injectable() export class AliveStatusService { + alsoUseFakeApi: boolean + constructor( private readonly nationalRegistryClient: NationalRegistryClientService, private readonly nationalRegistryV3Client: NationalRegistryV3ClientService, private readonly companyRegistryClient: CompanyRegistryClientService, @Inject(LOGGER_PROVIDER) private logger: Logger, - ) {} + @Optional() + readonly configService?: ConfigService, + ) { + this.alsoUseFakeApi = + configService?.get('ALSO_USE_FAKE_USER_API') ?? false + } /** * Divides nationalIds into alive and deceased @@ -134,7 +142,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(