Skip to content

Commit

Permalink
feat: P4ADEV-1781 add API to get decrypted api-key of broker (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: antonioT90 <[email protected]>
  • Loading branch information
serdimic and antonioT90 authored Dec 23, 2024
1 parent e96d51f commit 4a929c5
Show file tree
Hide file tree
Showing 17 changed files with 855 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ HELP.md
!**/src/test/**/target/

#**/src/main/resources/application-local*.properties
/src/main/resources/local-*.env

### STS ###
.apt_generated
Expand Down
31 changes: 31 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ openApi {
outputFileName.set("generated.openapi.json")
}

configure<SourceSetContainer> {
named("main") {
java.srcDir("$projectDir/build/generated/src/main/java")
}
}

tasks.compileJava {
dependsOn("openApiGenerateOrganization")
}

springBoot {
mainClass.value("it.gov.pagopa.pu.organization.OrganizationApplication")
}

tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerateOrganization") {
group = "openapi"
description = "description"

generatorName.set("spring")
inputSpec.set("$rootDir/openapi/p4pa-organization.openapi.json")
outputDir.set("$projectDir/build/generated")
apiPackage.set("it.gov.pagopa.pu.organization.controller.generated")
modelPackage.set("it.gov.pagopa.pu.organization.dto.generated")
configOptions.set(mapOf(
"dateLibrary" to "java8",
"requestMappingMode" to "api_interface",
"useSpringBoot3" to "true",
"interfaceOnly" to "true",
"useTags" to "true",
"generateConstructorWithAllArgs" to "false",
"generatedConstructorWithRequiredArgs" to "false",
"additionalModelTypeAnnotations" to "@lombok.Data @lombok.Builder @lombok.AllArgsConstructor"
))
}
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ microservice-chart:
ORGANIZATION_DB_HOST: db-host
ORGANIZATION_DB_USER: db-mypay-login-username
ORGANIZATION_DB_PASSWORD: db-mypay-login-password
BROKER_ENCRYPT_PASSWORD: broker-encrypt-password

# nodeSelector: {}

Expand Down
131 changes: 109 additions & 22 deletions openapi/generated.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"description": "Generated server url"
}
],
"tags": [
{
"name": "Broker",
"description": "the Broker API"
}
],
"paths": {
"/brokers": {
"get": {
Expand Down Expand Up @@ -653,6 +659,73 @@
}
}
}
},
"/brokers/apiKey/{brokerId}": {
"get": {
"tags": [
"Broker"
],
"summary": "Retrieve decrypted API keys for a broker",
"operationId": "getBrokerApiKeys",
"parameters": [
{
"name": "brokerId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
},
"application/hal+json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
},
"application/hal+json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
},
"application/hal+json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -946,6 +1019,28 @@
}
}
},
"PagedModelEntityModelBroker": {
"type": "object",
"properties": {
"_embedded": {
"type": "object",
"properties": {
"broker": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EntityModelBroker"
}
}
}
},
"_links": {
"$ref": "#/components/schemas/Links"
},
"page": {
"$ref": "#/components/schemas/PageMetadata"
}
}
},
"PersonalisationFe": {
"type": "object",
"properties": {
Expand All @@ -972,28 +1067,6 @@
}
}
},
"PagedModelEntityModelBroker": {
"type": "object",
"properties": {
"_embedded": {
"type": "object",
"properties": {
"broker": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EntityModelBroker"
}
}
}
},
"_links": {
"$ref": "#/components/schemas/Links"
},
"page": {
"$ref": "#/components/schemas/PageMetadata"
}
}
},
"BrokerRequestBody": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1154,6 +1227,20 @@
}
}
},
"BrokerApiKeys": {
"type": "object",
"properties": {
"syncKey": {
"type": "string"
},
"acaKey": {
"type": "string"
},
"gpdKey": {
"type": "string"
}
}
},
"Link": {
"type": "object",
"properties": {
Expand Down
86 changes: 86 additions & 0 deletions openapi/p4pa-organization.openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"openapi": "3.0.1",
"info": {
"title": "p4pa-organization",
"description": "Api and Models",
"version": "0.0.1"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"paths": {
"/brokers/apiKey/{brokerId}": {
"get": {
"tags": [
"Broker"
],
"summary": "Retrieve decrypted API keys for a broker",
"operationId": "getBrokerApiKeys",
"parameters": [
{
"name": "brokerId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/hal+json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/hal+json": {
"schema": {
"$ref": "#/components/schemas/BrokerApiKeys"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"BrokerApiKeys": {
"type": "object",
"properties": {
"syncKey": {
"type": "string"
},
"acaKey": {
"type": "string"
},
"gpdKey": {
"type": "string"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.gov.pagopa.pu.organization.controller;

import it.gov.pagopa.pu.organization.controller.generated.BrokerApi;
import it.gov.pagopa.pu.organization.dto.generated.BrokerApiKeys;
import it.gov.pagopa.pu.organization.service.broker.BrokerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class BrokerController implements BrokerApi {

private final BrokerService brokerService;

public BrokerController(BrokerService brokerService){
this.brokerService = brokerService;
}

@Override
public ResponseEntity<BrokerApiKeys> getBrokerApiKeys(Long brokerId) {
log.info("invoking getBrokerApiKeys, brokerId[{}]", brokerId);
return ResponseEntity.ofNullable(brokerService.getBrokerApiKeys(brokerId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package it.gov.pagopa.pu.organization.exception;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.event.Level;
import org.springdoc.api.ErrorMessage;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ControllerExceptionHandler {

@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<ErrorMessage> resourceNotFoundException(ResourceNotFoundException ex, HttpServletRequest request) {
HttpStatus returnStatus = HttpStatus.NOT_FOUND;
logException(ex, request, returnStatus, Level.INFO, false);
return ResponseEntity.status(returnStatus)
.body(new ErrorMessage("resource not found: %s".formatted(ex.getMessage())));
}

private void logException(Exception ex, HttpServletRequest request, HttpStatus httpStatus, Level level, boolean printStackTrace) {
printStackTrace = printStackTrace || log.isTraceEnabled();
log.atLevel(level)
.setCause(printStackTrace ? ex : null)
.log("A {} occurred handling request {} {} - HttpStatus {} - {}",
ex.getClass().getSimpleName(),
request.getMethod(),
request.getRequestURI(),
httpStatus.value(),
ex.getMessage()
);
}

}
2 changes: 2 additions & 0 deletions src/main/java/it/gov/pagopa/pu/organization/model/Broker.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.persistence.SequenceGenerator;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.JdbcTypeCode;
Expand All @@ -19,6 +20,7 @@
@Entity(name = "broker")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class Broker implements Serializable {
@Id
Expand Down
Loading

0 comments on commit 4a929c5

Please sign in to comment.