Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ids-api): Enable getting fake users in v3 client. Configure for ids-api envs. #17201

Merged
merged 8 commits into from
Dec 13, 2024
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',
valurefugl marked this conversation as resolved.
Show resolved Hide resolved
},
})
.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 @@ -45,7 +46,13 @@ export class UserProfileService {
private companyRegistryApi: CompanyRegistryClientService,
@Inject(LOGGER_PROVIDER)
private logger: Logger,
) {}
@Optional()
private alsoUseFakeApi: boolean,
readonly configService?: ConfigService,
valurefugl marked this conversation as resolved.
Show resolved Hide resolved
) {
this.alsoUseFakeApi =
configService?.get<boolean>('ALSO_USE_FAKE_USER_API') ?? false
}

valurefugl marked this conversation as resolved.
Show resolved Hide resolved
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
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
17 changes: 14 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 Down Expand Up @@ -26,7 +27,13 @@ export class AliveStatusService {
private readonly companyRegistryClient: CompanyRegistryClientService,
@Inject(LOGGER_PROVIDER)
private logger: Logger,
) {}
private alsoUseFakeApi: boolean,
@Optional()
valurefugl marked this conversation as resolved.
Show resolved Hide resolved
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 +141,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
Loading