Skip to content

Commit

Permalink
[PPANTT-223] feat: Add FdR QI KPI sub key (#533)
Browse files Browse the repository at this point in the history
Co-authored-by: pagopa-github-bot <github-bot@pagopa.it>
Co-authored-by: Samuele Varianti <128470180+svariant@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent dacc91d commit 9f3045a
Show file tree
Hide file tree
Showing 32 changed files with 329 additions and 200 deletions.
43 changes: 1 addition & 42 deletions .github/workflows/deploy_with_github_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,8 @@ permissions:
contents: read

jobs:
create_runner:
name: Create Runner
runs-on: ubuntu-22.04
environment:
name: ${{ inputs.environment }}
outputs:
runner_name: ${{ steps.create_github_runner.outputs.runner_name }}
steps:
- name: Create GitHub Runner
id: create_github_runner
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-create-action
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-create-action@main
with:
client_id: ${{ secrets.CD_CLIENT_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
container_app_environment_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_NAME }}
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }} # RG of the runner
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }}
self_hosted_runner_image_tag: "latest"

deploy:
needs: [ create_runner ]
runs-on: [ self-hosted, "${{ needs.create_runner.outputs.runner_name }}" ]
runs-on: [ self-hosted-job, "${{ inputs.environment }}" ]
name: Deploy on AKS
environment: ${{ inputs.environment }}
steps:
Expand All @@ -93,25 +71,6 @@ jobs:
run: |
helm uninstall ${{ env.APP_NAME }}${{inputs.suffix_name}} -n ${{ vars.NAMESPACE }}
cleanup_runner:
name: Cleanup Runner
needs: [ create_runner, deploy ]
if: ${{ success() || failure() }}
runs-on: ubuntu-22.04
environment: ${{ inputs.environment }}
steps:
- name: Cleanup GitHub Runner
id: cleanup_github_runner
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-cleanup-action
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-cleanup-action@main
with:
client_id: ${{ secrets.CD_CLIENT_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }}
runner_name: ${{ needs.create_runner.outputs.runner_name }}
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }}

update_openapi:
needs: [ deploy ]
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopa-selfcare-ms-backoffice
description: Microservice that manage api keys for pagopa product from selfcare
type: application
version: 0.435.0
appVersion: "2.32.2-1-next"
version: 0.442.0
appVersion: "2.34.1"
dependencies:
- name: microservice-chart
version: 2.4.0
Expand Down
3 changes: 2 additions & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend
tag: "2.32.2-1-next"
tag: "2.34.1"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -82,6 +82,7 @@ microservice-chart:
GEC_SERVICE_URL: https://api.dev.platform.pagopa.it
FORWARDER_SERVICE_URL: https://api.dev.platform.pagopa.it
TAXONOMY_SERVICE_URL: https://api.platform.pagopa.it
ENABLE_SEND_EMAIL: 'false'
AZURE_RESOURCE_GROUP: pagopa-d-api-rg
AZURE_SERVICE_NAME: pagopa-d-apim
APPCONFIGURATION_ENDPOINT: 'https://pagopa-d-selfcare-appconfiguration.azconfig.io'
Expand Down
3 changes: 2 additions & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend
tag: "2.32.2-1-next" #improve
tag: "2.34.1" #improve
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -85,6 +85,7 @@ microservice-chart:
GEC_SERVICE_URL: https://api.platform.pagopa.it
FORWARDER_SERVICE_URL: https://api.platform.pagopa.it
TAXONOMY_SERVICE_URL: https://api.platform.pagopa.it
ENABLE_SEND_EMAIL: 'true'
AZURE_RESOURCE_GROUP: pagopa-p-api-rg
AZURE_SERVICE_NAME: pagopa-p-apim
APPCONFIGURATION_ENDPOINT: 'https://pagopa-p-selfcare-appconfiguration.azconfig.io'
Expand Down
3 changes: 2 additions & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend
tag: "2.32.2-1-next" #improve
tag: "2.34.1" #improve
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -83,6 +83,7 @@ microservice-chart:
GEC_SERVICE_URL: https://api.uat.platform.pagopa.it
FORWARDER_SERVICE_URL: https://api.uat.platform.pagopa.it
TAXONOMY_SERVICE_URL: https://api.platform.pagopa.it
ENABLE_SEND_EMAIL: 'true'
AZURE_RESOURCE_GROUP: pagopa-u-api-rg
AZURE_SERVICE_NAME: pagopa-u-apim
APPCONFIGURATION_ENDPOINT: 'https://pagopa-u-selfcare-appconfiguration.azconfig.io'
Expand Down
5 changes: 3 additions & 2 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Microservice to manage PagoPA Backoffice",
"termsOfService": "https://www.pagopa.gov.it/",
"title": "SelfCare Backoffice",
"version": "2.32.2-1-next"
"version": "2.34.1"
},
"servers": [
{
Expand Down Expand Up @@ -8965,6 +8965,7 @@
"BIZ",
"FDR_ORG",
"FDR_PSP",
"QI_FDR_KPI",
"BO_EXT_EC",
"BO_EXT_PSP",
"PRINT_NOTICE",
Expand Down Expand Up @@ -17049,4 +17050,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<version>2.5.14</version>
</parent>
<artifactId>pagopa-selfcare-ms-backoffice</artifactId>
<version>2.32.2-1-next</version>
<version>2.34.1</version>
<name>SelfCare Backoffice</name>
<description>Microservice to manage PagoPA Backoffice</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class AwsSesClient {

private final String environment;

private final Boolean enableSendEmail;

private final String testEmailAddress;

private final String pagopaOperatorEmailAddress;
Expand All @@ -46,15 +48,16 @@ public AwsSesClient(
ExternalApiClient externalApiClient,
@Value("${info.properties.environment}") String environment,
@Value("${institution.subscription.test-email}") String testEmailAddress,
@Value("${institution.subscription.pagopa-operator-email}") String pagopaOperatorEmailAddress
) {
@Value("${institution.subscription.pagopa-operator-email}") String pagopaOperatorEmailAddress,
@Value("${institution.subscription.enable-send-email}") Boolean enableSendEmail) {
this.sesClient = sesClient;
this.from = from;
this.templateEngine = templateEngine;
this.externalApiClient = externalApiClient;
this.environment = environment;
this.testEmailAddress = testEmailAddress;
this.pagopaOperatorEmailAddress = pagopaOperatorEmailAddress;
this.enableSendEmail = enableSendEmail;
}

/**
Expand All @@ -72,7 +75,7 @@ public AwsSesClient(
*/
public void sendEmail(EmailMessageDetail email, boolean sendEmailToPagopaOperator) {
String taxCode = email.getInstitutionTaxCode();
if (isNotProdWithoutTestEmail() || isProdWithNullDestinationInstitutionTaxCode(taxCode)) {
if (hasNotRequiredData(taxCode)) {
log.warn("Skip send email process");
return;
}
Expand Down Expand Up @@ -111,6 +114,7 @@ public void sendEmail(EmailMessageDetail email) {

private SendEmailRequest buildEmailRequest(EmailMessageDetail email, String[] toAddressList, boolean sendEmailToPagopaOperator) {
String html = this.templateEngine.process(email.getHtmlBodyFileName(), email.getHtmlBodyContext());
String subject = isNotProd() ? String.format("[%s] %s", this.environment, email.getSubject()) : email.getSubject();

return SendEmailRequest.builder()
.source(this.from)
Expand All @@ -122,7 +126,7 @@ private SendEmailRequest buildEmailRequest(EmailMessageDetail email, String[] to
}
})
.message(m -> m
.subject(c -> c.data(email.getSubject()))
.subject(c -> c.data(subject))
.body(b -> b
.html(c -> c.data(html).charset(StandardCharsets.UTF_8.name()))
.text(c -> c.data(email.getTextBody()))
Expand All @@ -132,7 +136,7 @@ private SendEmailRequest buildEmailRequest(EmailMessageDetail email, String[] to
}

private String[] getToAddressList(String taxCode, SelfcareProductUser destinationUserType) {
if (!this.environment.equals("PROD")) {
if (Boolean.FALSE.equals(this.enableSendEmail)) {
return new String[]{testEmailAddress};
}
Optional<Institution> optionalInstitution = this.externalApiClient.getInstitutionsFiltered(taxCode)
Expand All @@ -158,11 +162,11 @@ private String[] getToAddressList(String taxCode, SelfcareProductUser destinatio
.toArray(new String[0]);
}

private boolean isProdWithNullDestinationInstitutionTaxCode(String taxCode) {
return this.environment.equals("PROD") && taxCode == null;
private boolean isNotProd() {
return !this.environment.equals("PROD");
}

private boolean isNotProdWithoutTestEmail() {
return !this.environment.equals("PROD") && StringUtils.isBlank(testEmailAddress);
private boolean hasNotRequiredData(String taxCode) {
return Boolean.FALSE.equals(this.enableSendEmail) ? StringUtils.isBlank(testEmailAddress) : taxCode == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public enum Subscription {
BIZ("/products/bizevents", "BIZ - Recupero ricevute Ente Creditore", "biz-", CI, null, false),
FDR_ORG("/products/fdr-org", "FdR - Flussi di Rendicontazione (EC)", "fdrorg-", CI, "fdr", true),
FDR_PSP("/products/fdr-psp", "FdR - Flussi di Rendicontazione (PSP)", "fdrpsp-", PSP, "fdr", true),
QI_FDR_KPI("/products/qi-fdr-kpi", "FdR - Quality Improvement KPI API", "qifdrkpiservice-", PSP, "qi", true),
BO_EXT_EC("/apis/%s-backoffice-external-ec-api-v1", "Backoffice External (EC)", "selfcareboexternalec-", CI, "backoffice_external", false),
BO_EXT_PSP("/apis/%s-backoffice-external-psp-api-v1", "Backoffice External (PSP)", "selfcareboexternalpsp-", PSP, "backoffice_external", false),
PRINT_NOTICE("/products/pagopa_notices_service_external", "Stampa Avvisi", "printnotice-", CI, null, false),
ACA("/products/aca", "ACA - paCreatePosition", "aca-", CI, "aca", true);
ACA("/products/aca", "ACA - Conferimento delle posizioni debitorie", "aca-", CI, "aca", true);

private final String scope;
private final String displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ private Set<String> getAllBrokersOrThrowException() {
updateMDCError(e, "Export CI Broker");
String errMsg = "[Export-CI] - An error occurred while extracting broker list, export aborted";
log.error(errMsg, e);
throw new AppException(AppError.BROKER_CI_EXPORT_SCHEDULER_SETUP_ERROR, e, errMsg);
} finally {
MDC.clear();
throw new AppException(AppError.BROKER_CI_EXPORT_SCHEDULER_SETUP_ERROR, e, errMsg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
Expand All @@ -35,6 +36,8 @@
@Slf4j
public class CommissionBundleMailNotificationScheduler {

private final String environment;

private static final String VALID_FROM_DATE_FORMAT = "yyyy-MM-dd";

private final BundleAllPages bundleAllPages;
Expand All @@ -44,10 +47,12 @@ public class CommissionBundleMailNotificationScheduler {
private final AwsSesClient awsSesClient;

public CommissionBundleMailNotificationScheduler(
@Value("${info.properties.environment}") String environment,
BundleAllPages bundleAllPages,
ApiConfigClient apiConfigClient,
AwsSesClient awsSesClient
) {
this.environment = environment;
this.bundleAllPages = bundleAllPages;
this.apiConfigClient = apiConfigClient;
this.awsSesClient = awsSesClient;
Expand Down Expand Up @@ -111,7 +116,7 @@ private void sendMail(String expireAt, Bundle bundle, String notifyTaxCode, Stri
EmailMessageDetail messageDetail = EmailMessageDetail.builder()
.institutionTaxCode(notifyTaxCode)
.subject(BUNDLE_EXPIRE_SUBJECT)
.textBody(String.format(BUNDLE_EXPIRE_BODY, bundle.getName(), bundle.getPspBusinessName(), pspTaxCode, expireAt))
.textBody(String.format(BUNDLE_EXPIRE_BODY, bundle.getName(), bundle.getPspBusinessName(), pspTaxCode, expireAt, getEnvParam()))
.htmlBodyFileName("expiringBundleEmail.html")
.htmlBodyContext(buildEmailHtmlBodyContext(bundle.getName(), bundle.getPspBusinessName(), pspTaxCode, expireAt))
.destinationUserType(SelfcareProductUser.ADMIN)
Expand Down Expand Up @@ -144,8 +149,16 @@ private Context buildEmailHtmlBodyContext(
properties.put("pspName", pspBusinessName);
properties.put("pspTaxCode", pspTaxCode);
properties.put("expireAt", expireAt);
properties.put("environment", getEnvParam());

context.setVariables(properties);
return context;
}

private String getEnvParam() {
if (this.environment.equals("PROD")) {
return "";
}
return String.format(".%s", this.environment.toLowerCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ private Set<String> getAllBrokersOrThrowException() {
updateMDCError(e, "Export Broker IBAN");
String errMsg = "[Export IBANs] - An error occurred while extracting broker list, export aborted";
log.error(errMsg, e);
throw new AppException(AppError.BROKER_IBAN_EXPORT_SCHEDULER_SETUP_ERROR, e, errMsg);
} finally {
MDC.clear();
throw new AppException(AppError.BROKER_IBAN_EXPORT_SCHEDULER_SETUP_ERROR, e, errMsg);
}
}

Expand Down
Loading

0 comments on commit 9f3045a

Please sign in to comment.