-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMN-710 - selfcare-onboarding-consumer (#959)
Co-authored-by: AsterITA <[email protected]>
- Loading branch information
1 parent
6cd859b
commit 611d8ca
Showing
27 changed files
with
975 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./context.js"; | ||
export * from "./interopHeaders.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { z } from "zod"; | ||
|
||
export const InteropHeaders = z.object({ | ||
"X-Correlation-Id": z.string(), | ||
Authorization: z.string(), | ||
}); | ||
|
||
export type InteropHeaders = z.infer<typeof InteropHeaders>; | ||
|
||
export const getInteropHeaders = ({ | ||
token, | ||
correlationId, | ||
}: { | ||
token: string; | ||
correlationId: string; | ||
}): InteropHeaders => ({ | ||
"X-Correlation-Id": correlationId, | ||
Authorization: `Bearer ${token}`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
LOG_LEVEL=info | ||
KAFKA_LOG_LEVEL=INFO | ||
|
||
KAFKA_CLIENT_ID="selfcare-onboarding-consumer-client" | ||
KAFKA_GROUP_ID="selfcare-onboarding-consumer-group-local" | ||
KAFKA_BROKERS="localhost:9092" | ||
KAFKA_BROKER_CONNECTION_STRING="placeholder" | ||
SELFCARE_TOPIC="placeholder.selfcare.topic" | ||
TOPIC_STARTING_OFFSET="earliest" | ||
AWS_REGION="eu-central-1" | ||
|
||
RESET_CONSUMER_OFFSETS="false" | ||
|
||
INTEROP_PRODUCT="interop-product-placeholder" | ||
ALLOWED_ORIGINS="IPA" | ||
|
||
TENANT_PROCESS_URL="http://localhost:3500" | ||
|
||
INTERNAL_JWT_KID=ffcc9b5b-4612-49b1-9374-9d203a3834f2 | ||
INTERNAL_JWT_SUBJECT="dev-refactor.interop-selfcare-onboarding-consumer" | ||
INTERNAL_JWT_ISSUER="dev-refactor.interop.pagopa.it" | ||
INTERNAL_JWT_AUDIENCE="refactor.dev.interop.pagopa.it/internal" | ||
INTERNAL_JWT_SECONDS_DURATION=60 | ||
|
||
AWS_CONFIG_FILE=aws.config.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
FROM node:20.14.0-slim@sha256:5e8ac65a0231d76a388683d07ca36a9769ab019a85d85169fe28e206f7a3208e as build | ||
|
||
RUN corepack enable | ||
|
||
WORKDIR /app | ||
COPY package.json /app/ | ||
COPY pnpm-lock.yaml /app/ | ||
COPY pnpm-workspace.yaml /app/ | ||
|
||
COPY ./packages/selfcare-onboarding-consumer/package.json /app/packages/selfcare-onboarding-consumer/package.json | ||
COPY ./packages/commons/package.json /app/packages/commons/package.json | ||
COPY ./packages/models/package.json /app/packages/models/package.json | ||
COPY ./packages/kafka-iam-auth/package.json /app/packages/kafka-iam-auth/package.json | ||
COPY ./packages/api-clients/package.json /app/packages/api-clients/package.json | ||
|
||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile | ||
|
||
COPY tsconfig.json /app/ | ||
COPY turbo.json /app/ | ||
COPY ./packages/selfcare-onboarding-consumer /app/packages/selfcare-onboarding-consumer | ||
COPY ./packages/commons /app/packages/commons | ||
COPY ./packages/models /app/packages/models | ||
COPY ./packages/kafka-iam-auth /app/packages/kafka-iam-auth | ||
COPY ./packages/api-clients /app/packages/api-clients | ||
|
||
RUN pnpm build && \ | ||
rm -rf /app/node_modules/.modules.yaml && \ | ||
rm -rf /app/node_modules/.cache && \ | ||
mkdir /out && \ | ||
cp -a --parents -t /out \ | ||
node_modules packages/selfcare-onboarding-consumer/node_modules \ | ||
package*.json packages/selfcare-onboarding-consumer/package*.json \ | ||
packages/commons \ | ||
packages/models \ | ||
packages/kafka-iam-auth \ | ||
packages/api-clients \ | ||
packages/selfcare-onboarding-consumer/dist && \ | ||
find /out -exec touch -h --date=@0 {} \; | ||
|
||
FROM node:20.14.0-slim@sha256:5e8ac65a0231d76a388683d07ca36a9769ab019a85d85169fe28e206f7a3208e as final | ||
|
||
COPY --from=build /out /app | ||
|
||
WORKDIR /app/packages/selfcare-onboarding-consumer | ||
EXPOSE 3000 | ||
|
||
CMD ["node", "."] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Selfcare Onboarding Consumer | ||
|
||
This service imports tenants that have joined Interop through Selfcare. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[default] | ||
aws_access_key_id=testawskey | ||
aws_secret_access_key=testawssecret | ||
region=eu-central-1 | ||
services=local | ||
|
||
[services local] | ||
kms= | ||
endpoint_url=http://localhost:4566 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "pagopa-interop-selfcare-onboarding-consumer", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "PagoPA Interoperability Selfcare onboarding consumer: service that imports tenants that have joined Interop through Selfcare", | ||
"main": "dist", | ||
"type": "module", | ||
"scripts": { | ||
"test": "vitest", | ||
"test:it": "vitest integration", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"lint:autofix": "eslint . --ext .ts,.tsx --fix", | ||
"format:check": "prettier --check src", | ||
"format:write": "prettier --write src", | ||
"start": "node --loader ts-node/esm -r 'dotenv-flow/config' --watch ./src/index.ts", | ||
"build": "tsc", | ||
"check": "tsc --project tsconfig.check.json" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@pagopa/eslint-config": "3.0.0", | ||
"@types/node": "20.14.6", | ||
"@types/uuid": "9.0.8", | ||
"prettier": "2.8.8", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.4.5", | ||
"vitest": "1.6.0" | ||
}, | ||
"dependencies": { | ||
"dotenv-flow": "4.1.0", | ||
"kafka-iam-auth": "workspace:*", | ||
"kafkajs": "2.2.4", | ||
"pagopa-interop-commons": "workspace:*", | ||
"pagopa-interop-commons-test": "workspace:*", | ||
"pagopa-interop-models": "workspace:*", | ||
"pagopa-interop-api-clients": "workspace:*", | ||
"ts-pattern": "5.2.0", | ||
"uuid": "10.0.0", | ||
"zod": "3.23.8" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/selfcare-onboarding-consumer/src/clients/tenantProcessClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { tenantApi } from "pagopa-interop-api-clients"; | ||
|
||
export type TenantProcessClient = { | ||
selfcare: ReturnType<typeof tenantApi.createSelfcareApiClient>; | ||
}; | ||
|
||
export const tenantProcessClientBuilder = ( | ||
url: string | ||
): TenantProcessClient => ({ | ||
selfcare: tenantApi.createSelfcareApiClient(url), | ||
}); |
32 changes: 32 additions & 0 deletions
32
packages/selfcare-onboarding-consumer/src/config/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { z } from "zod"; | ||
import { | ||
KafkaConsumerConfig, | ||
TokenGenerationConfig, | ||
} from "pagopa-interop-commons"; | ||
|
||
export const SelfcareOnboardingConsumerConfig = KafkaConsumerConfig.and( | ||
TokenGenerationConfig | ||
).and( | ||
z | ||
.object({ | ||
SELFCARE_TOPIC: z.string(), | ||
|
||
INTEROP_PRODUCT: z.string(), | ||
ALLOWED_ORIGINS: z.string(), | ||
|
||
TENANT_PROCESS_URL: z.string(), | ||
}) | ||
.transform((c) => ({ | ||
selfcareTopic: c.SELFCARE_TOPIC, | ||
interopProduct: c.INTEROP_PRODUCT, | ||
allowedOrigins: c.ALLOWED_ORIGINS.split(","), | ||
tenantProcessUrl: c.TENANT_PROCESS_URL, | ||
})) | ||
); | ||
|
||
export type SelfcareOnboardingConsumerConfig = z.infer< | ||
typeof SelfcareOnboardingConsumerConfig | ||
>; | ||
|
||
export const config: SelfcareOnboardingConsumerConfig = | ||
SelfcareOnboardingConsumerConfig.parse(process.env); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { runConsumer } from "kafka-iam-auth"; | ||
import { | ||
InteropTokenGenerator, | ||
RefreshableInteropToken, | ||
} from "pagopa-interop-commons"; | ||
import { config } from "./config/config.js"; | ||
import { tenantProcessClientBuilder } from "./clients/tenantProcessClient.js"; | ||
import { selfcareOnboardingProcessorBuilder } from "./services/selfcareOnboardingProcessor.js"; | ||
|
||
const tokenGenerator = new InteropTokenGenerator(config); | ||
const refreshableToken = new RefreshableInteropToken(tokenGenerator); | ||
await refreshableToken.init(); | ||
|
||
const tenantProcessClient = tenantProcessClientBuilder(config.tenantProcessUrl); | ||
|
||
const processor = selfcareOnboardingProcessorBuilder( | ||
refreshableToken, | ||
tenantProcessClient, | ||
config.interopProduct, | ||
config.allowedOrigins | ||
); | ||
|
||
await runConsumer(config, [config.selfcareTopic], processor.processMessage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ORIGIN_IPA = "IPA"; |
Oops, something went wrong.