Skip to content

Commit

Permalink
feat(ids-api): Enable getting fake users in v3 client. Configure for …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
valurefugl and kodiakhq[bot] authored Dec 13, 2024
1 parent c4977d1 commit 3719969
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 16 deletions.
5 changes: 5 additions & 0 deletions apps/services/auth/ids-api/infra/ids-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion apps/services/auth/ids-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -45,7 +47,12 @@ export class UserProfileService {
private companyRegistryApi: CompanyRegistryClientService,
@Inject(LOGGER_PROVIDER)
private logger: Logger,
) {}
@Optional()
readonly configService?: ConfigService,
) {
this.alsoUseFakeApi =
configService?.get<boolean>('ALSO_USE_FAKE_USER_API') ?? false
}

userProfileApiWithAuth(auth: Auth) {
return this.userProfileApi.withMiddleware(new AuthMiddleware(auth))
Expand Down Expand Up @@ -123,6 +130,7 @@ export class UserProfileService {
const individual = await this.nationalRegistryV3.getAllDataIndividual(
auth.nationalId,
false,
this.alsoUseFakeApi,
)

if (!individual) {
Expand Down
1 change: 1 addition & 0 deletions charts/identity-server/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions charts/identity-server/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions charts/identity-server/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions charts/services/services-auth-ids-api/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions charts/services/services-auth-ids-api/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions charts/services/services-auth-ids-api/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 15 additions & 3 deletions libs/auth-api-lib/src/lib/delegations/alive-status.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<boolean>('ALSO_USE_FAKE_USER_API') ?? false
}

/**
* Divides nationalIds into alive and deceased
Expand Down Expand Up @@ -134,7 +142,11 @@ export class AliveStatusService {
): Promise<IdentityInfo> {
if (useNationalRegistryV3) {
return await this.nationalRegistryV3Client
.getAllDataIndividual(individualInfo.nationalId)
.getAllDataIndividual(
individualInfo.nationalId,
false,
this.alsoUseFakeApi,
)
.then((individual) => {
if (
individual &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,34 @@ export class NationalRegistryV3ClientService {
)
}

getAllDataIndividual(
async getAllDataIndividual(
nationalId: string,
useFakeApi?: boolean,
useFakeApiOnly?: boolean,
alsoTryFakeApiWhenNotFound?: boolean,
): Promise<EinstaklingurDTOAllt | null> {
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(
Expand Down

0 comments on commit 3719969

Please sign in to comment.