generated from pagopa/template-payments-java-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: P4ADEV-1781 add API to get decrypted api-key of broker (#8)
Co-authored-by: antonioT90 <[email protected]>
- Loading branch information
1 parent
e96d51f
commit 4a929c5
Showing
17 changed files
with
855 additions
and
42 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 |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/it/gov/pagopa/pu/organization/controller/BrokerController.java
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,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)); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/it/gov/pagopa/pu/organization/exception/ControllerExceptionHandler.java
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,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() | ||
); | ||
} | ||
|
||
} |
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
Oops, something went wrong.