Skip to content

Commit 465fb64

Browse files
Vitolo-AndreastedeliaDanieleRanaldo
authored
fix: Added TPP secret (#14)
Co-authored-by: stefanodel <[email protected]> Co-authored-by: DanieleRanaldo <[email protected]>
1 parent 47ad221 commit 465fb64

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

.github/workflows/code-review.yml

+19-11
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ jobs:
1414

1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
17+
uses: actions/[email protected]
18+
with:
19+
fetch-depth: 0 # Fetch all history for all branches and tags
1820

1921
- name: Set up JDK 17
20-
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 #v4.2.1
22+
uses: actions/[email protected]
2123
with:
2224
distribution: 'adopt'
2325
java-version: '17'
@@ -33,17 +35,23 @@ jobs:
3335
- name: Build and test with Maven
3436
run: mvn clean org.jacoco:jacoco-maven-plugin:0.8.8:prepare-agent verify org.jacoco:jacoco-maven-plugin:0.8.8:report org.jacoco:jacoco-maven-plugin:0.8.8:report-aggregate -B
3537

38+
- name: Generate JaCoCo XML Report
39+
run: mvn org.jacoco:jacoco-maven-plugin:0.8.8:report -Djacoco.reportFormat=xml -B
40+
3641
- name: SonarCloud Scan
3742
env:
3843
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3944
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4045
run: |
41-
mvn sonar:sonar \
42-
-Dsonar.projectKey=${{ vars.SONARCLOUD_PROJECT_KEY }} \
43-
-Dsonar.organization=${{ vars.SONARCLOUD_ORG }} \
44-
-Dsonar.host.url=https://sonarcloud.io \
45-
-Dsonar.login=${{ secrets.SONAR_TOKEN }} \
46-
-Dsonar.java.binaries=target/classes \
47-
-Dsonar.junit.reportPaths=target/surefire-reports \
48-
-Dsonar.jacoco.reportPaths=target/jacoco.exec \
49-
-Dsonar.exclusions=**/enums/**,**/model/**,**/stub/**,**/dto/**,**/*Constant*,**/*Config.java,**/*Scheduler.java,**/*Application.java,**/src/test/**,**/Dummy*.java
46+
mvn sonar:sonar \
47+
-Dsonar.projectKey=${{ vars.SONARCLOUD_PROJECT_KEY }} \
48+
-Dsonar.organization=${{ vars.SONARCLOUD_ORG }} \
49+
-Dsonar.host.url=https://sonarcloud.io \
50+
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
51+
-Dsonar.java.binaries=target/classes \
52+
-Dsonar.junit.reportPaths=target/surefire-reports \
53+
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml \
54+
-Dsonar.exclusions=**/enums/**,**/model/**,**/stub/**,**/dto/**,**/*Constant*,**/*Config.java,**/*Scheduler.java,**/*Application.java,**/src/test/**,**/Dummy*.java
55+
56+
- name: Fetch all branches
57+
run: git fetch --all

src/main/java/it/gov/pagopa/message/core/service/SendMessageServiceImpl.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import it.gov.pagopa.message.core.dto.MessageDTO;
44
import it.gov.pagopa.message.core.dto.TokenDTO;
55
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.http.HttpEntity;
78
import org.springframework.http.HttpHeaders;
89
import org.springframework.http.HttpMethod;
@@ -17,16 +18,30 @@ public class SendMessageServiceImpl implements SendMessageService {
1718

1819
private final RestTemplate restTemplate;
1920
private final MessageErrorProducerService errorProducerService;
21+
22+
private final String client;
23+
private final String clientId;
24+
private final String grantType;
25+
26+
private final String tenantId;
2027
public SendMessageServiceImpl(MessageErrorProducerService errorProducerService,
21-
RestTemplate restTemplate) {
28+
RestTemplate restTemplate,
29+
@Value("${app.token.client}")String client,
30+
@Value("${app.token.clientId}") String clientId,
31+
@Value("${app.token.grantType}") String grantType,
32+
@Value("${app.token.tenantId}") String tenantId) {
2233
this.restTemplate = restTemplate;
2334
this.errorProducerService = errorProducerService;
35+
this.client = client;
36+
this.clientId = clientId;
37+
this.grantType = grantType;
38+
this.tenantId = tenantId;
2439
}
2540

2641
@Override
2742
public void sendMessage(MessageDTO messageDTO, String messageUrl, String authenticationUrl) {
2843
try {
29-
toUrl(messageDTO, messageUrl, getToken(authenticationUrl, messageDTO.getRecipientId()));
44+
toUrl(messageDTO, messageUrl, getToken(authenticationUrl));
3045
}
3146
catch (Exception e) {
3247
log.info("[EMD][SEND-MESSAGE] Error while sending message");
@@ -37,32 +52,28 @@ public void sendMessage(MessageDTO messageDTO, String messageUrl, String authent
3752
@Override
3853
public void sendMessage(MessageDTO messageDTO, String messageUrl, String authenticationUrl, long retry) {
3954
try {
40-
toUrl(messageDTO, messageUrl, getToken(authenticationUrl, messageDTO.getRecipientId()));
55+
toUrl(messageDTO, messageUrl, getToken(authenticationUrl));
4156
}
4257
catch (Exception e) {
4358
log.info("[EMD][SEND-MESSAGE] Error while sending message");
4459
errorProducerService.sendError(messageDTO,messageUrl,authenticationUrl,retry);
4560
}
4661
}
4762

48-
private TokenDTO getToken(String authenticationUrl, String recipientId) throws Exception{
63+
private TokenDTO getToken(String authenticationUrl) throws Exception{
4964

5065
HttpHeaders headers = new HttpHeaders();
51-
headers.set("RequestId", "00000000-0000-0000-0000-000000000006");
5266
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
5367

54-
String client = "64b5f14d-56ef-4d14-8b65-ff7bc5d4661e";
55-
String clientId = "6010064c-ec73-4fa5-9ed5-5446af8920cf";
56-
String grantType = "client_credentials";
5768
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
5869
map.add("client_secret", client);
5970
map.add("client_id", clientId);
6071
map.add("grant_type", grantType);
61-
map.add("fiscal_code", recipientId);
6272

63-
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(map, headers);
73+
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(map,headers);
6474
TokenDTO token;
6575

76+
authenticationUrl = authenticationUrl.replace("tenantId",tenantId);
6677
log.info("[EMD][SEND-MESSAGE] Getting Token");
6778
token = restTemplate.exchange(
6879
authenticationUrl,

src/main/resources/application.yml

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ spring:
8585

8686
app:
8787
retry.max-retry: ${ERROR_MESSAGE_MAX_RETRY:5}
88+
token:
89+
client: ${HYPE_KEY:}
90+
clientId: ${HYPE_CLIENT:}
91+
grantType: ${GRANT_TYPE:client_credentials}
92+
tenantId: ${HYPE_TENANT:}
8893

8994
management:
9095
health:

src/test/java/it/gov/pagopa/message/core/controller/CitizenControllerTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,18 @@ void updateCitizenConsent_Ok() throws Exception {
8585

8686
@Test
8787
void deleteCitizenConsent_Ok() throws Exception {
88+
String userId = "testUserId";
89+
String channelId = "testChannelId";
8890
CitizenConsentDTO citizenConsentDTO = CitizenConsentDTOFaker.mockInstance(false);
89-
9091
Mockito.when(
91-
citizenService.deleteCitizenConsent(citizenConsentDTO.getHashedFiscalCode(),citizenConsentDTO.getChannelId()))
92+
citizenService.deleteCitizenConsent(userId,channelId))
9293
.thenReturn(citizenConsentDTO);
9394

9495
MvcResult result = mockMvc.perform(
9596
delete("/emd/onboarding-citizen/citizenConsents")
96-
.contentType(MediaType.APPLICATION_JSON)
97+
.param("userId", userId)
98+
.param("channelId", channelId)
9799
.accept(MediaType.APPLICATION_JSON)
98-
.content(objectMapper.writeValueAsString(citizenConsentDTO))
99100
).andExpect(status().isOk()).andReturn();
100101

101102
CitizenConsentDTO resultResponse = objectMapper.readValue(

0 commit comments

Comments
 (0)