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

fix(auth-api-lib): Use company registry api to get company name on custom delegations. #15199

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions apps/services/auth/delegation-api/infra/delegation-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import {
} from '../../../../../infra/src/dsl/dsl'
import { Base, Client, RskProcuring } from '../../../../../infra/src/dsl/xroad'

const REDIS_NODE_CONFIG = {
dev: json([
'clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379',
]),
staging: json([
'clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379',
]),
prod: json([
'clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379',
]),
}

export const serviceSetup = (services: {
userNotification: ServiceBuilder<'user-notification'>
}): ServiceBuilder<'services-auth-delegation-api'> => {
Expand All @@ -29,33 +41,19 @@ export const serviceSetup = (services: {
staging: 'IS-TEST/GOV/6503760649/SKRA-Protected/Einstaklingar-v1',
prod: 'IS/GOV/6503760649/SKRA-Protected/Einstaklingar-v1',
},
XROAD_NATIONAL_REGISTRY_REDIS_NODES: {
dev: json([
'clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379',
]),
staging: json([
'clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379',
]),
prod: json([
'clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379',
]),
},
XROAD_RSK_PROCURING_REDIS_NODES: {
dev: json([
'clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379',
]),
staging: json([
'clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379',
]),
prod: json([
'clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379',
]),
},
XROAD_NATIONAL_REGISTRY_REDIS_NODES: REDIS_NODE_CONFIG,
XROAD_RSK_PROCURING_REDIS_NODES: REDIS_NODE_CONFIG,
USER_NOTIFICATION_API_URL: {
dev: ref((h) => `http://${h.svc(services.userNotification)}`),
staging: ref((h) => `http://${h.svc(services.userNotification)}`),
prod: 'https://user-notification.internal.island.is',
},
COMPANY_REGISTRY_XROAD_PROVIDER_ID: {
dev: 'IS-DEV/GOV/10006/Skatturinn/ft-v1',
staging: 'IS-TEST/GOV/5402696029/Skatturinn/ft-v1',
prod: 'IS/GOV/5402696029/Skatturinn/ft-v1',
},
COMPANY_REGISTRY_REDIS_NODES: REDIS_NODE_CONFIG,
})
.secrets({
IDENTITY_SERVER_CLIENT_SECRET:
Expand Down
2 changes: 2 additions & 0 deletions apps/services/auth/delegation-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@island.is/auth-api-lib'
import { AuthModule } from '@island.is/auth-nest-tools'
import { NationalRegistryClientConfig } from '@island.is/clients/national-registry-v2'
import { CompanyRegistryConfig } from '@island.is/clients/rsk/company-registry'
import { RskRelationshipsClientConfig } from '@island.is/clients-rsk-relationships'
import { AuditModule } from '@island.is/nest/audit'
import {
Expand Down Expand Up @@ -46,6 +47,7 @@ import { ScopesModule } from './scopes/scopes.module'
IdsClientConfig,
NationalRegistryClientConfig,
RskRelationshipsClientConfig,
CompanyRegistryConfig,
XRoadConfig,
DelegationApiUserSystemNotificationConfig,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import { json, service, ServiceBuilder } from '../../../../../infra/src/dsl/dsl'
import { MissingSetting } from '../../../../../infra/src/dsl/types/input-types'
import { Base, Client, RskProcuring } from '../../../../../infra/src/dsl/xroad'

const REDIS_NODE_CONFIG = {
dev: json([
'clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379',
]),
staging: json([
'clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379',
]),
prod: json([
'clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379',
]),
}

export const serviceSetup =
(): ServiceBuilder<'services-auth-personal-representative'> => {
return service('services-auth-personal-representative')
Expand All @@ -22,28 +34,14 @@ export const serviceSetup =
staging: 'IS-TEST/GOV/6503760649/SKRA-Protected/Einstaklingar-v1',
prod: 'IS/GOV/6503760649/SKRA-Protected/Einstaklingar-v1',
},
XROAD_NATIONAL_REGISTRY_REDIS_NODES: {
dev: json([
'clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379',
]),
staging: json([
'clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379',
]),
prod: json([
'clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379',
]),
},
XROAD_RSK_PROCURING_REDIS_NODES: {
dev: json([
'clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379',
]),
staging: json([
'clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379',
]),
prod: json([
'clustercfg.general-redis-cluster-group.dnugi2.euw1.cache.amazonaws.com:6379',
]),
XROAD_NATIONAL_REGISTRY_REDIS_NODES: REDIS_NODE_CONFIG,
XROAD_RSK_PROCURING_REDIS_NODES: REDIS_NODE_CONFIG,
COMPANY_REGISTRY_XROAD_PROVIDER_ID: {
dev: 'IS-DEV/GOV/10006/Skatturinn/ft-v1',
staging: 'IS-TEST/GOV/5402696029/Skatturinn/ft-v1',
prod: 'IS/GOV/5402696029/Skatturinn/ft-v1',
},
COMPANY_REGISTRY_REDIS_NODES: REDIS_NODE_CONFIG,
})
.secrets({
IDENTITY_SERVER_CLIENT_SECRET:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
XRoadConfig,
} from '@island.is/nest/config'
import { NationalRegistryClientConfig } from '@island.is/clients/national-registry-v2'
import { CompanyRegistryConfig } from '@island.is/clients/rsk/company-registry'
import { RskRelationshipsClientConfig } from '@island.is/clients-rsk-relationships'
import { FeatureFlagConfig } from '@island.is/nest/feature-flags'

Expand All @@ -34,6 +35,7 @@ import { FeatureFlagConfig } from '@island.is/nest/feature-flags'
IdsClientConfig,
NationalRegistryClientConfig,
RskRelationshipsClientConfig,
CompanyRegistryConfig,
XRoadConfig,
FeatureFlagConfig,
],
Expand Down
6 changes: 6 additions & 0 deletions apps/services/auth/public-api/infra/auth-public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@
XROAD_NATIONAL_REGISTRY_REDIS_NODES: REDIS_NODE_CONFIG,
XROAD_RSK_PROCURING_REDIS_NODES: REDIS_NODE_CONFIG,
XROAD_TJODSKRA_MEMBER_CODE: {
prod: '6503760649',

Check warning on line 45 in apps/services/auth/public-api/infra/auth-public-api.ts

View workflow job for this annotation

GitHub Actions / linting (services-auth-admin-api,services-auth-delegation-api,services-auth-ids-api,services-auth...

Found valid SSN: 6503760649
dev: '10001',
staging: '6503760649',

Check warning on line 47 in apps/services/auth/public-api/infra/auth-public-api.ts

View workflow job for this annotation

GitHub Actions / linting (services-auth-admin-api,services-auth-delegation-api,services-auth-ids-api,services-auth...

Found valid SSN: 6503760649
},
PASSKEY_CORE_RP_ID: 'island.is',
PASSKEY_CORE_RP_NAME: 'Island.is',
PASSKEY_CORE_CHALLENGE_TTL_MS: '120000',
REDIS_NODES: REDIS_NODE_CONFIG,
COMPANY_REGISTRY_XROAD_PROVIDER_ID: {
dev: 'IS-DEV/GOV/10006/Skatturinn/ft-v1',
staging: 'IS-TEST/GOV/5402696029/Skatturinn/ft-v1',
prod: 'IS/GOV/5402696029/Skatturinn/ft-v1',
},
COMPANY_REGISTRY_REDIS_NODES: REDIS_NODE_CONFIG,
})
.secrets({
IDENTITY_SERVER_CLIENT_SECRET:
Expand Down
2 changes: 2 additions & 0 deletions apps/services/auth/public-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { FeatureFlagConfig } from '@island.is/nest/feature-flags'
import { ProblemModule } from '@island.is/nest/problem'
import { NationalRegistryClientConfig } from '@island.is/clients/national-registry-v2'
import { CompanyRegistryConfig } from '@island.is/clients/rsk/company-registry'
import { RskRelationshipsClientConfig } from '@island.is/clients-rsk-relationships'

import { environment } from '../environments'
Expand All @@ -40,6 +41,7 @@ import { PasskeysModule } from './modules/passkeys/passkeys.module'
IdsClientConfig,
NationalRegistryClientConfig,
RskRelationshipsClientConfig,
CompanyRegistryConfig,
XRoadConfig,
PasskeysCoreConfig,
],
Expand Down
6 changes: 6 additions & 0 deletions charts/identity-server/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ services-auth-admin-api:
services-auth-delegation-api:
enabled: true
env:
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'
DB_HOST: 'postgres-applications.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-applications-reader.internal'
Expand Down Expand Up @@ -544,6 +546,8 @@ services-auth-ids-api-cleanup:
services-auth-personal-representative:
enabled: true
env:
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'
DB_HOST: 'postgres-applications.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-applications-reader.internal'
Expand Down Expand Up @@ -697,6 +701,8 @@ services-auth-personal-representative-public:
services-auth-public-api:
enabled: true
env:
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'
DB_HOST: 'postgres-applications.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-applications-reader.internal'
Expand Down
6 changes: 6 additions & 0 deletions charts/identity-server/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ services-auth-admin-api:
services-auth-delegation-api:
enabled: true
env:
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'
DB_HOST: 'postgres-ids.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-ids.internal'
Expand Down Expand Up @@ -541,6 +543,8 @@ services-auth-ids-api-cleanup:
services-auth-personal-representative:
enabled: true
env:
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'
DB_HOST: 'postgres-ids.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-ids.internal'
Expand Down Expand Up @@ -686,6 +690,8 @@ services-auth-personal-representative-public:
services-auth-public-api:
enabled: true
env:
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'
DB_HOST: 'postgres-ids.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-ids.internal'
Expand Down
6 changes: 6 additions & 0 deletions charts/identity-server/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ services-auth-admin-api:
services-auth-delegation-api:
enabled: true
env:
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'
DB_HOST: 'postgres-applications.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-applications.internal'
Expand Down Expand Up @@ -544,6 +546,8 @@ services-auth-ids-api-cleanup:
services-auth-personal-representative:
enabled: true
env:
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'
DB_HOST: 'postgres-applications.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-applications.internal'
Expand Down Expand Up @@ -689,6 +693,8 @@ services-auth-personal-representative-public:
services-auth-public-api:
enabled: true
env:
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'
DB_HOST: 'postgres-applications.internal'
DB_NAME: 'servicesauth'
DB_REPLICAS_HOST: 'postgres-applications.internal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
IndividualDto,
NationalRegistryClientService,
} from '@island.is/clients/national-registry-v2'
import {
CompanyExtendedInfo,
CompanyRegistryClientService,
} from '@island.is/clients/rsk/company-registry'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { AuditService } from '@island.is/nest/audit'
import { isDefined } from '@island.is/shared/utils'
Expand All @@ -31,6 +35,11 @@ type FindAllValidIncomingOptions = {
domainName?: string
}

type FromNameInfo = {
nationalId: string
name: string
}

/**
* Service class for incoming delegations.
* This class supports domain based delegations.
Expand All @@ -43,6 +52,7 @@ export class DelegationsIncomingCustomService {
@InjectModel(ApiScopeUserAccess)
private apiScopeUserAccessModel: typeof ApiScopeUserAccess,
private nationalRegistryClient: NationalRegistryClientService,
private companyRegistryClient: CompanyRegistryClientService,
@Inject(LOGGER_PROVIDER)
private logger: Logger,
private auditService: AuditService,
Expand Down Expand Up @@ -147,7 +157,7 @@ export class DelegationsIncomingCustomService {
validity: DelegationValidity
},
useMaster = false,
): Promise<{ delegations: Delegation[]; fromNameInfo: IndividualDto[] }> {
): Promise<{ delegations: Delegation[]; fromNameInfo: FromNameInfo[] }> {
let whereOptions = getScopeValidityWhereClause(validity)
if (domainName) whereOptions = { ...whereOptions, domainName: domainName }

Expand Down Expand Up @@ -242,7 +252,7 @@ export class DelegationsIncomingCustomService {
): Promise<{
aliveDelegations: Delegation[]
deceasedDelegations: Delegation[]
fromNameInfo: IndividualDto[]
fromNameInfo: FromNameInfo[]
}> {
if (delegations.length === 0) {
return {
Expand All @@ -254,18 +264,27 @@ export class DelegationsIncomingCustomService {

const delegationsPromises = delegations.map(({ fromNationalId }) =>
kennitala.isCompany(fromNationalId)
? null
? this.companyRegistryClient
.getCompany(fromNationalId)
.catch(this.handlerGetError)
: this.nationalRegistryClient
.getIndividual(fromNationalId)
.catch(this.handlerGetIndividualError),
.catch(this.handlerGetError),
)

try {
// Check if delegations is linked to a person, i.e. not deceased
const persons = await Promise.all(delegationsPromises)
const personsValuesNoError = persons
const identities = await Promise.all(delegationsPromises)
const identitiesValuesNoError = identities
.filter(this.isNotError)
.filter(isDefined)
.map((identity) => ({
nationalId: identity.nationalId,
name:
(kennitala.isCompany(identity.nationalId)
? (identity as CompanyExtendedInfo).name
: (identity as IndividualDto).fullName) ?? UNKNOWN_NAME,
}))

// Divide delegations into alive or deceased delegations.
const [aliveDelegations, deceasedDelegations] = partitionWithIndex(
Expand All @@ -274,15 +293,15 @@ export class DelegationsIncomingCustomService {
// All companies will be divided into aliveDelegations
kennitala.isCompany(fromNationalId) ||
// Pass through altough Þjóðskrá API throws an error since it is not required to view the delegation.
persons[index] instanceof Error ||
identities[index] instanceof Error ||
// Make sure we can match the person to the delegation, i.e. not deceased
(persons[index] as IndividualDto)?.nationalId === fromNationalId,
(identities[index] as IndividualDto)?.nationalId === fromNationalId,
)

return {
aliveDelegations,
deceasedDelegations,
fromNameInfo: personsValuesNoError,
fromNameInfo: identitiesValuesNoError,
}
} catch (error) {
this.logger.error(
Expand All @@ -302,7 +321,7 @@ export class DelegationsIncomingCustomService {
}
}

private handlerGetIndividualError(error: null | Error) {
private handlerGetError(error: null | Error) {
return error
}

Expand All @@ -317,10 +336,10 @@ export class DelegationsIncomingCustomService {
* Finds person by nationalId.
*/
private getPersonByNationalId(
persons: Array<IndividualDto | null>,
identities: Array<FromNameInfo | null>,
nationalId: string,
) {
return persons.find((person) => person?.nationalId === nationalId)
return identities.find((identity) => identity?.nationalId === nationalId)
}

private async findAccessControlList(
Expand Down
2 changes: 2 additions & 0 deletions libs/auth-api-lib/src/lib/delegations/delegations.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SequelizeModule } from '@nestjs/sequelize'

import { NationalRegistryClientModule } from '@island.is/clients/national-registry-v2'
import { RskRelationshipsClientModule } from '@island.is/clients-rsk-relationships'
import { CompanyRegistryClientModule } from '@island.is/clients/rsk/company-registry'
import { FeatureFlagModule } from '@island.is/nest/feature-flags'
import { UserSystemNotificationModule } from '../user-notification'

Expand Down Expand Up @@ -39,6 +40,7 @@ import { ApiScopeDelegationType } from '../resources/models/api-scope-delegation
PersonalRepresentativeModule,
NationalRegistryClientModule,
RskRelationshipsClientModule,
CompanyRegistryClientModule,
UserIdentitiesModule,
FeatureFlagModule,
SequelizeModule.forFeature([
Expand Down
Loading